diff --git a/.editorconfig b/.editorconfig index d3ff85a66..cf96b88c1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,16 +3,13 @@ root = true [*] charset = utf-8 end_of_line = lf +indent_size = 4 indent_style = space insert_final_newline = true trim_trailing_whitespace = true -[*.php] -indent_size = 4 - [*.json] indent_size = 2 [*.{yml,yaml}] indent_size = 2 - diff --git a/.gitattributes b/.gitattributes index a66f62b68..0fd4e90d0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,3 +6,4 @@ /CODE_OF_CONDUCT.md export-ignore /CONTRIBUTING.md export-ignore /phpunit.xml.dist export-ignore +/tests export-ignore diff --git a/.github/workflows/coding-standard.yml b/.github/workflows/coding-standard.yml index 4d2f0d8fd..48ad3efde 100644 --- a/.github/workflows/coding-standard.yml +++ b/.github/workflows/coding-standard.yml @@ -11,8 +11,8 @@ jobs: strategy: fail-fast: false matrix: - operating-system: [ ubuntu-latest, windows-latest, macOS-latest ] - php-versions: [ '7.4', '8.0', '8.1', '8.2'] + operating-system: [ubuntu-latest, windows-latest] + php-versions: ["8.0", "8.1", "8.2", "8.3"] steps: - name: Set git to use LF @@ -21,9 +21,7 @@ jobs: git config --global core.eol lf - name: Checkout - uses: actions/checkout@v3.2.0 - with: - fetch-depth: 1 + uses: actions/checkout@v3 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -35,12 +33,13 @@ jobs: - name: Get Composer Cache Directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v3 + + - name: Cache Composer dependencies + uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- - name: Check Composer configuration run: composer validate --strict @@ -52,4 +51,3 @@ jobs: run: vendor/bin/php-cs-fixer --diff --dry-run -v fix env: PHP_CS_FIXER_IGNORE_ENV: 1 - diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 435ab1ab5..96b1f49e8 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -11,8 +11,8 @@ jobs: strategy: fail-fast: false matrix: - operating-system: [ ubuntu-latest, windows-latest, macOS-latest ] - php-versions: [ '7.4', '8.0', '8.1', '8.2' ] + operating-system: [ubuntu-latest, windows-latest] + php-versions: ["8.0", "8.1", "8.2", "8.3"] steps: - name: Set git to use LF @@ -21,9 +21,7 @@ jobs: git config --global core.eol lf - name: Checkout - uses: actions/checkout@v3.2.0 - with: - fetch-depth: 1 + uses: actions/checkout@v3 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -35,12 +33,13 @@ jobs: - name: Get Composer Cache Directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v3 + + - name: Cache Composer dependencies + uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- - name: Check Composer configuration run: composer validate --strict diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index d36323dfe..1cec88931 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -11,8 +11,8 @@ jobs: strategy: fail-fast: false matrix: - operating-system: [ ubuntu-latest, windows-latest, macOS-latest ] - php-versions: [ '7.4', '8.0', '8.1', '8.2' ] + operating-system: [ubuntu-latest, windows-latest] + php-versions: ["8.0", "8.1", "8.2", "8.3"] steps: - name: Set git to use LF @@ -21,9 +21,7 @@ jobs: git config --global core.eol lf - name: Checkout - uses: actions/checkout@v3.2.0 - with: - fetch-depth: 1 + uses: actions/checkout@v3 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -35,12 +33,13 @@ jobs: - name: Get Composer Cache Directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - uses: actions/cache@v3 + + - name: Cache Composer dependencies + uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- - name: Check Composer configuration run: composer validate --strict diff --git a/.phan/config.php b/.phan/config.php index 242a55d5c..665b102f6 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -51,7 +51,7 @@ // Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist. // (See `backward_compatibility_checks` for additional options) // Automatically inferred from composer.json requirement for "php" of "^7.4 || ^8.0" - 'target_php_version' => '7.4', + 'target_php_version' => '8.0', // If enabled, missing properties will be created when // they are first seen. If false, we'll report an diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index e134debc6..91d0df704 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -5,7 +5,7 @@ /** * This file is part of the Yasumi package. * - * Copyright (c) 2015 - 2023 AzuyaLabs + * Copyright (c) 2015 - 2024 AzuyaLabs * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,15 +16,19 @@ $config = new PhpCsFixer\Config(); $config->setRiskyAllowed(true)->setRules([ - '@Symfony' => true, '@PER' => true, + '@Symfony' => true, 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, - 'declare_strict_types' => true, + 'explicit_string_variable' => true, 'no_superfluous_elseif' => true, 'no_superfluous_phpdoc_tags' => ['remove_inheritdoc' => true], + 'not_operator_with_successor_space' => true, + 'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true ], + 'ordered_class_elements' => true, - // Risky rules + // Risky + 'declare_strict_types' => true, 'dir_constant' => true, 'get_class_to_class_keyword' => true, 'is_null' => true, diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a5ba753a..0ef0d6d12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,9 @@ -# Change Log +# Changelog All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](https://keepachangelog.com/) and this project adheres -to [Semantic Versioning](https://semver.org). +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Changes related to the business logic of the holidays or their providers are listed first, followed by any technical or architectural changes. @@ -18,6 +18,57 @@ changes. ### Removed +## [2.7.0] - 2024-01-02 + +### Added + +- Mexico Provider [\#329](https://github.com/azuyalabs/yasumi/pull/329) ([Luis Gonzalez](https://github.com/gogl92)). +- From 2024, Romania will officially include the holidays of St. Johns ('Sfântul Ioan Botezătorul') and Epiphany ('Bobotează'). + [#310](https://github.com/azuyalabs/yasumi/pull/310) ([AngelinCalu](https://github.com/AngelinCalu) ) +- For the German state of Mecklenburg-Western Pomerania, International Women's Day is considered to be officially + observed. [#311](https://github.com/azuyalabs/yasumi/pull/311) ([ihmels](https://github.com/ihmels)) +- Recently, the South Korean government announced a bill to apply alternative public holidays to Buddha's Day + and Christmas Day. + [\#314](https://github.com/azuyalabs/yasumi/pull/314) ([barami](https://github.com/barami)) +- Extra checks in case date subtraction fails for some holiday providers. +- PHP 8.3 support for the unit test CI pipeline. [#328](https://github.com/azuyalabs/yasumi/pull/328) ([fezfez](https://github.com/fezfez)) +- Add code styling rules to have a space after the `NOT` operator and mark parameters with a default null value as nullable. + +### Changed + +- Refactor the rules for calculating holidays in South Korea based on the history of holiday changes. + ([#314](https://github.com/azuyalabs/yasumi/issues/314)) [barami](https://github.com/barams@gmail.com) +- Update links to related documentation in the South Korea provider's note and added links to conversion utilities. + [\#314](https://github.com/azuyalabs/yasumi/pull/314) ([barami](https://github.com/barami)) +- Optimize the method for the Emperor's birthday calculation in Japan. +- For Croatia, extract Day of Antifascist Struggle calculation to a private method and simplify Statehood Day calculation + to make it more concise. +- Simplify the conditions for the Coming of Age day (Japan) calculation. +- Simplify the calculation of Carnival in Argentina, Brazil and the Netherlands to reduce duplication. +- Avoid silent exceptions by throwing a new one from the previous exception. + +### Fixed + +- For South Korea, some of the past dates for Buddha's Day, Chuseok, Armed Forces Day + and United Nations Day were incorrectly calculated during for certain periods. [\#314](https://github.com/azuyalabs/yasumi/pull/314) ([barami](https://github.com/barami)) +- The holiday `twoDaysLaterNewYearsDay` of South Korea has been removed from 1990, however the unit test for the name + and holiday type allowed the possible testing range to include the year 1990. +- New Years Day tests for South Korea were failing due to incorrect date checks. +- The Easter Date calculation resulted in wrong values for the year 2025, due to an incorrect rounding for the lunar + correction when the calendar extension is not used. [#326](https://github.com/azuyalabs/yasumi/pull/326) ([rChassat](https://github.com/rChassat)) + +### Removed + +- Denmark will abolish Great Prayer Day ('store bededag') from 2024. [#308](https://github.com/azuyalabs/yasumi/pull/308) ([c960657](https://github.com/c960657)) +- Summertime and Wintertime in the Netherlands and Denmark as these can't be reliably established for historical dates and + aren't true holidays in the context of Yasumi. Refer to this [discussion](https://github.com/azuyalabs/yasumi/discussions/321) + for further details and rationale. [#322](https://github.com/azuyalabs/yasumi/pull/322) +- PHP 7.4 support. +- The PHP [Infection](https://infection.github.io/) test package as it was hardly used. +- Unit tests from a Git export to reduce the export size. [#323](https://github.com/azuyalabs/yasumi/pull/323) ([fezfez](https://github.com/fezfez)) +- Checks for superfluous naming as we follow PER which supports such convention. +- MacOS from testing matrix as it returns errors (requires further investigation). + ## [2.6.0] - 2023-04-27 ### Added @@ -758,7 +809,9 @@ changes. - Initial Release -[Unreleased]: https://github.com/azuyalabs/yasumi/compare/2.6.0...HEAD +[Unreleased]: https://github.com/azuyalabs/yasumi/compare/2.7.0...HEAD + +[2.7.0]: https://github.com/azuyalabs/yasumi/compare/2.6.0...2.7.0 [2.6.0]: https://github.com/azuyalabs/yasumi/compare/2.5.0...2.6.0 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 2a00fc8e8..4572578fe 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -13,19 +13,19 @@ We pledge to act and interact in ways that contribute to an open, welcoming, div Examples of behavior that contributes to a positive environment for our community include: -* Demonstrating empathy and kindness toward other people -* Being respectful of differing opinions, viewpoints, and experiences -* Giving and gracefully accepting constructive feedback -* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience -* Focusing on what is best not just for us as individuals, but for the overall community +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +- Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: -* The use of sexualized language or imagery, and sexual attention or advances of any kind -* Trolling, insulting or derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or email address, without their explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting +- The use of sexualized language or imagery, and sexual attention or advances of any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email address, without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities @@ -102,11 +102,7 @@ For answers to common questions about this code of conduct, see the FAQ at at [https://www.contributor-covenant.org/translations][translations]. [homepage]: https://www.contributor-covenant.org - [v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html - [Mozilla CoC]: https://github.com/mozilla/diversity - [FAQ]: https://www.contributor-covenant.org/faq - [translations]: https://www.contributor-covenant.org/translations diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 49c1c9f31..e68e0bd46 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ When contributing there are a few guidelines we'd like you to keep in mind: - **[PSR-12 Coding Standard](https://www.php-fig.org/psr/psr-12/)** Please use the following command after you have completed your work: - ``` shell + ```shell composer format ``` @@ -39,12 +39,12 @@ When contributing there are a few guidelines we'd like you to keep in mind: ## Running Tests -``` shell +```shell composer test ``` Or, alternatively run with: -``` shell +```shell vendor/bin/phpunit ``` diff --git a/LICENSE b/LICENSE index 5276fcb26..3e5247433 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 - 2023 AzuyaLabs +Copyright (c) 2015 - 2024 AzuyaLabs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 5aa7bd19a..ca2d3ebea 100644 --- a/composer.json +++ b/composer.json @@ -35,18 +35,17 @@ } ], "require": { - "php": ">=7.4", + "php": ">=8.0", "ext-json": "*" }, "require-dev": { "ext-intl": "*", - "friendsofphp/php-cs-fixer": "^2.19 || ^3.16", - "infection/infection": "^0.17 || ^0.26", + "friendsofphp/php-cs-fixer": "^2.19 || ^3.40", "mikey179/vfsstream": "^1.6", "phan/phan": "^5.4", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^8.5 || ^9.6", - "vimeo/psalm": "^5.9" + "vimeo/psalm": "^5.16" }, "suggest": { "ext-calendar": "For calculating the date of Easter" @@ -64,8 +63,7 @@ }, "config": { "allow-plugins": { - "composer/package-versions-deprecated": true, - "infection/extension-installer": true + "composer/package-versions-deprecated": true }, "sort-packages": true }, @@ -75,7 +73,6 @@ "@psalm" ], "format": "./vendor/bin/php-cs-fixer fix", - "infection": "vendor/bin/infection run -j 2", "phan": "vendor/bin/phan -C", "phpstan": "vendor/bin/phpstan analyse", "psalm": "vendor/bin/psalm --threads=2", diff --git a/examples/custom_provider.php b/examples/custom_provider.php index 907b58698..773f93cc3 100644 --- a/examples/custom_provider.php +++ b/examples/custom_provider.php @@ -9,12 +9,12 @@ require 'vendor/autoload.php'; /** Provider for all observed holidays by the NYSE (New York Stock Exchange) */ -class NYSE extends \Yasumi\Provider\USA +class NYSE extends Yasumi\Provider\USA { /** * Initialize holidays for the NYSE. * - * @throws \Exception + * @throws Exception */ public function initialize(): void { diff --git a/infection.json b/infection.json deleted file mode 100644 index 254270a99..000000000 --- a/infection.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "source": { - "directories": [ - "src\/Yasumi" - ] - }, - "timeout": 20, - "logs": { - "text": "var/infection.log", - "summary": "var/summary.log", - "debug": "var/debug.log", - "perMutator": "var/per-mutator.md" - }, - "mutators": { - "@default": true - } -} diff --git a/phpinsights.php b/phpinsights.php new file mode 100644 index 000000000..4b5520d8b --- /dev/null +++ b/phpinsights.php @@ -0,0 +1,113 @@ + 'symfony', + + /* + |-------------------------------------------------------------------------- + | IDE + |-------------------------------------------------------------------------- + | + | This options allow to add hyperlinks in your terminal to quickly open + | files in your favorite IDE while browsing your PhpInsights report. + | + | Supported: "textmate", "macvim", "emacs", "sublime", "phpstorm", + | "atom", "vscode". + | + | If you have another IDE that is not in this list but which provide an + | url-handler, you could fill this config with a pattern like this: + | + | myide://open?url=file://%f&line=%l + | + */ + + 'ide' => null, + + /* + |-------------------------------------------------------------------------- + | Configuration + |-------------------------------------------------------------------------- + | + | Here you may adjust all the various `Insights` that will be used by PHP + | Insights. You can either add, remove or configure `Insights`. Keep in + | mind, that all added `Insights` must belong to a specific `Metric`. + | + */ + + 'exclude' => [ + // 'path/to/directory-or-file' + ], + + 'add' => [ + // ExampleMetric::class => [ + // ExampleInsight::class, + // ] + ], + + 'remove' => [ + PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\TodoSniff::class, + SlevomatCodingStandard\Sniffs\ControlStructures\DisallowShortTernaryOperatorSniff::class, + SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff::class, + SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff::class, + + // Remove checks for superfluous naming as we follow PER which supports such convention + SlevomatCodingStandard\Sniffs\Classes\SuperfluousInterfaceNamingSniff::class, + SlevomatCodingStandard\Sniffs\Classes\SuperfluousAbstractClassNamingSniff::class, + SlevomatCodingStandard\Sniffs\Classes\SuperfluousExceptionNamingSniff::class, + ], + + 'config' => [ + PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff::class => [ + 'lineLimit' => 120, + 'absoluteLineLimit' => 140, + 'ignoreComments' => false, + ], + ], + + /* + |-------------------------------------------------------------------------- + | Requirements + |-------------------------------------------------------------------------- + | + | Here you may define a level you want to reach per `Insights` category. + | When a score is lower than the minimum level defined, then an error + | code will be returned. This is optional and individually defined. + | + */ + + 'requirements' => [ + 'min-quality' => 90, + 'min-complexity' => 90, + 'min-architecture' => 90, + 'min-style' => 90, + 'disable-security-check' => false, + ], + + /* + |-------------------------------------------------------------------------- + | Threads + |-------------------------------------------------------------------------- + | + | Here you may adjust how many threads (core) PHPInsights can use to perform + | the analyse. This is optional, don't provide it and the tool will guess + | the max core number available. It accepts null value or integer > 0. + | + */ + + 'threads' => null, +]; diff --git a/phpstan.neon.dist b/phpstan.neon.dist index fad49a494..f9ac466cf 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,10 +1,13 @@ parameters: - level: 6 - paths: - - src - - examples - ignoreErrors: - - - message: '#Comparison operation "<=" between [0-9]+ and int<[0-9]+, max> is always true.#' - path: src/Yasumi/Provider/Turkey.php - checkGenericClassInNonGenericObjectType: false + level: 6 + paths: + - src + - examples + ignoreErrors: + - + message: '#Comparison operation "<=" between [0-9]+ and int<[0-9]+, max> is always true.#' + path: src/Yasumi/Provider/Turkey.php + checkGenericClassInNonGenericObjectType: false + reportUnmatchedIgnoredErrors: true # Do not allow outdated errors in the baseline + treatPhpDocTypesAsCertain: false + tipsOfTheDay: false diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ba4a53739..fcf8aea40 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,17 +2,22 @@ - + + ./src/Yasumi @@ -21,6 +26,7 @@ ./src/Yasumi/data + ./tests diff --git a/psalm.xml.dist b/psalm.xml.dist index 089c58eb9..870259810 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -2,7 +2,7 @@