From d14df582e8c823d0c963bc3da5f37ab89c626ae5 Mon Sep 17 00:00:00 2001 From: Daniel Opitz Date: Sat, 9 Sep 2023 18:52:35 +0200 Subject: [PATCH] Require PHP 8.1+ --- .cs.php | 22 +++++- .editorconfig | 13 ++++ .gitattributes | 36 ++++++---- .github/workflows/build.yml | 71 ++++++++++--------- .gitignore | 9 +-- .scrutinizer.yml | 69 +++++++++--------- LICENSE | 11 +-- README.md | 2 +- composer.json | 16 +++-- phpcs.xml | 5 +- phpstan.neon | 12 +--- phpunit.xml | 20 +++--- src/Resolver/ConstructorResolver.php | 2 +- tests/TestCase/ContainerTest.php | 6 +- .../Resolver/ConstructorResolverTest.php | 4 +- 15 files changed, 166 insertions(+), 132 deletions(-) diff --git a/.cs.php b/.cs.php index 9653bee..2bba5e9 100644 --- a/.cs.php +++ b/.cs.php @@ -20,6 +20,13 @@ 'cast_spaces' => ['space' => 'none'], 'concat_space' => ['spacing' => 'one'], 'compact_nullable_typehint' => true, + 'declare_equal_normalize' => ['space' => 'single'], + 'general_phpdoc_annotation_remove' => [ + 'annotations' => [ + 'author', + 'package', + ], + ], 'increment_style' => ['style' => 'post'], 'list_syntax' => ['syntax' => 'short'], 'echo_tag_syntax' => ['format' => 'long'], @@ -33,11 +40,22 @@ 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], 'ordered_imports' => [ 'sort_algorithm' => 'alpha', - 'imports_order' => ['class', 'const', 'function'] + 'imports_order' => ['class', 'const', 'function'], ], 'single_line_throw' => false, + 'declare_strict_types' => false, + 'blank_line_between_import_groups' => true, 'fully_qualified_strict_types' => true, - 'global_namespace_import' => false, + 'no_null_property_initialization' => false, + 'operator_linebreak' => [ + 'only_booleans' => true, + 'position' => 'beginning', + ], + 'global_namespace_import' => [ + 'import_classes' => true, + 'import_constants' => null, + 'import_functions' => null + ] ] ) ->setFinder( diff --git a/.editorconfig b/.editorconfig index 2c10224..0a6abee 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,16 @@ end_of_line = lf [composer.json] indent_size = 4 + +[*.js] +indent_size = 4 + +[*.neon] +indent_size = 4 +indent_style = tab + +[*.xml] +indent_size = 4 + +[*.yml] +indent_size = 4 diff --git a/.gitattributes b/.gitattributes index c65a80e..0e58fb3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,14 +1,29 @@ -# Path-based git attributes -# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html - -public/* linguist-vendored -docs/* linguist-documentation - # Set the default behavior, in case people don't have core.autocrlf set. # Git will always convert line endings to LF on checkout. You should use # this for files that must keep LF endings, even on Windows. * text eol=lf +# ------------------------------------------------------------------------------ +# All the files and directories that can be excluded from dist, +# we could have a more clean vendor/ +# +# So when someone will install that package through with --prefer-dist option, +# all the files and directories listed in .gitattributes file will be excluded. +# This could have a big impact on big deployments and/or testing. +# ------------------------------------------------------------------------------ + +/tests export-ignore +/build export-ignore +/docs export-ignore +/build.xml export-ignore +/phpunit.xml export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.travis.* export-ignore +/.scrutinizer.* export-ignore +/.editorconfig export-ignore +/.coveralls.* export-ignore + # Define binary file attributes. # - Do not treat them as text. # - Include binary diff in patches instead of "binary files differ." @@ -17,13 +32,6 @@ docs/* linguist-documentation *.gif binary *.ico binary *.jpg binary +*.jpeg binary *.png binary -*.phar binary *.zip binary -*.gz binary -*.otf binary -*.eot binary -*.svg binary -*.ttf binary -*.woff binary -*.woff2 binary diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8ca1e0f..a4bf3d5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,38 +3,39 @@ name: build on: [ push, pull_request ] jobs: - run: - runs-on: ${{ matrix.operating-system }} - strategy: - matrix: - operating-system: [ ubuntu-latest ] - php-versions: [ '8.0', '8.1' ] - name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} - - steps: - - name: Checkout - uses: actions/checkout@v1 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - coverage: none - - - name: Check PHP Version - run: php -v - - - name: Check Composer Version - run: composer -V - - - name: Check PHP Extensions - run: php -m - - - name: Validate composer.json and composer.lock - run: composer validate - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --no-suggest - - - name: Run test suite - run: composer test:all + run: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: [ ubuntu-latest ] + php-versions: [ '8.1', '8.2' ] + name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl, zip + coverage: none + + - name: Check PHP Version + run: php -v + + - name: Check Composer Version + run: composer -V + + - name: Check PHP Extensions + run: php -m + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run test suite + run: composer test:all diff --git a/.gitignore b/.gitignore index 8ae6c37..a4689b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,7 @@ .idea/ -nbproject/ composer.lock -.DS_STORE -cache.properties -.php_cs.cache -.vscode/ -.phpunit.result.cache +nbproject/ vendor/ build/ +.phpunit.cache/ +.phpunit.result.cache \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 9cf2601..3514e2e 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,42 +1,41 @@ filter: - paths: [ "src/*" ] - excluded_paths: [ "vendor/*", "tests/*" ] + paths: [ "src/*" ] + excluded_paths: [ "vendor/*", "tests/*" ] checks: - php: - code_rating: true - duplication: true + php: + code_rating: true + duplication: true tools: - external_code_coverage: false + external_code_coverage: false build: - environment: - php: - version: 8.1.2 - ini: - xdebug.mode: coverage - mysql: false - node: false - postgresql: false - mongodb: false - elasticsearch: false - redis: false - memcached: false - neo4j: false - rabbitmq: false - nodes: - analysis: - tests: - override: - - php-scrutinizer-run - dependencies: - before: - - composer self-update - - composer install --no-interaction --prefer-dist --no-progress - tests: - before: - - command: composer test:coverage - coverage: - file: 'build/logs/clover.xml' - format: 'clover' + environment: + php: + version: 8.1.2 + ini: + xdebug.mode: coverage + mysql: false + node: false + postgresql: false + mongodb: false + elasticsearch: false + redis: false + memcached: false + neo4j: false + rabbitmq: false + nodes: + analysis: + tests: + override: + - php-scrutinizer-run + dependencies: + before: + - composer self-update + tests: + before: + - command: composer test:coverage + coverage: + file: 'build/logs/clover.xml' + format: 'clover' diff --git a/LICENSE b/LICENSE index b899bb1..bf7a9a3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,11 +1,13 @@ +The MIT License (MIT) + Copyright (c) 2023 odan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is furnished -to do so, subject to the following conditions: +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. @@ -15,5 +17,6 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md index 2a95f2b..4e9451d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ A PSR-11 container implementation with optional **autowiring**. ## Requirements - * PHP 8.0+ + * PHP 8.1+ ## Installation diff --git a/composer.json b/composer.json index 27c455f..1c3c3cb 100644 --- a/composer.json +++ b/composer.json @@ -7,13 +7,13 @@ "psr-11" ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.1", "psr/container": "^2.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3", "phpstan/phpstan": "^1", - "phpunit/phpunit": "^9 || ^10", + "phpunit/phpunit": "^10", "squizlabs/php_codesniffer": "^3", "symfony/event-dispatcher": "^5 || 6.0.*" }, @@ -31,11 +31,17 @@ "sort-packages": true }, "scripts": { - "cs:check": "php-cs-fixer fix --dry-run --format=txt --verbose --diff --config=.cs.php --ansi", - "cs:fix": "php-cs-fixer fix --config=.cs.php --ansi", + "cs:check": [ + "@putenv PHP_CS_FIXER_IGNORE_ENV=1", + "php-cs-fixer fix --dry-run --format=txt --verbose --diff --config=.cs.php --ansi" + ], + "cs:fix": [ + "@putenv PHP_CS_FIXER_IGNORE_ENV=1", + "php-cs-fixer fix --config=.cs.php --ansi --verbose" + ], "sniffer:check": "phpcs --standard=phpcs.xml", "sniffer:fix": "phpcbf --standard=phpcs.xml", - "stan": "phpstan analyse -c phpstan.neon --no-progress --ansi --xdebug", + "stan": "phpstan analyse -c phpstan.neon --no-progress --ansi", "test": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always", "test:all": [ "@cs:check", diff --git a/phpcs.xml b/phpcs.xml index 19179d8..f2f42d9 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -9,8 +9,7 @@ ./src ./tests - - + warning @@ -27,4 +26,4 @@ - + \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index b96d74c..0b6508e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,14 +1,4 @@ parameters: level: 8 paths: - - src - - tests - reportUnmatchedIgnoredErrors: false - ignoreErrors: - - '/Parameter \#1 \$argument of class ReflectionClass constructor expects class-string\\|T of object, string given/' - - '/Parameter \#1 \$id of method Selective\\Container\\Resolver\\ConstructorResolver\:\:resolve\(\) expects class-string, string given/' - - '/Parameter \#1 \$objectOrClass of class ReflectionClass constructor expects class\-string/' - - '#Parameter \#1 \$stack of function array_shift expects array, mixed given.#' - - '#Parameter \#1 \$array of function array_shift expects array, mixed given.#' - - '#Parameter \#2 \$haystack of method PHPUnit\\Framework\\Assert\:\:assertCount\(\) expects Countable\|iterable, mixed given.#' - - "#Trying to invoke mixed but it's not a callable.#" + - src \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index f2e36c3..2927473 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,9 +3,16 @@ bootstrap="vendor/autoload.php" colors="true" backupGlobals="false" - backupStaticAttributes="false" - xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> - + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" + cacheDirectory=".phpunit.cache" + backupStaticProperties="false"> + + + + tests + + + src @@ -13,10 +20,5 @@ vendor build - - - - tests - - + diff --git a/src/Resolver/ConstructorResolver.php b/src/Resolver/ConstructorResolver.php index 3feef01..81ad25e 100644 --- a/src/Resolver/ConstructorResolver.php +++ b/src/Resolver/ConstructorResolver.php @@ -33,7 +33,7 @@ public function __construct(ContainerInterface $container) /** * Autowire dependencies. * - * @param string|class-string $id The id + * @param class-string $id The id * * @throws InvalidDefinitionException * diff --git a/tests/TestCase/ContainerTest.php b/tests/TestCase/ContainerTest.php index 5b600c2..6c9801a 100644 --- a/tests/TestCase/ContainerTest.php +++ b/tests/TestCase/ContainerTest.php @@ -114,7 +114,7 @@ public function testFactory(): void public function testReplace(): void { $this->expectException(LogicException::class); - $this->expectErrorMessage('The factory cannot be modified'); + $this->expectExceptionMessage('The factory cannot be modified'); $container = new Container(); @@ -331,7 +331,7 @@ public function testAutowireWithInvalidInternalInterface(): void public function testAutowireWithInvalidAbstractClass(): void { $this->expectException(InvalidDefinitionException::class); - $this->expectErrorMessage('Entry "Selective\Container\Test\TestCase\Service\MyAbstractService" cannot ' . + $this->expectExceptionMessage('Entry "Selective\Container\Test\TestCase\Service\MyAbstractService" cannot ' . 'be resolved: the class is not instantiable'); $container = new Container(); @@ -347,7 +347,7 @@ public function testAutowireWithInvalidAbstractClass(): void public function testAutowireWithNotExistingClass(): void { $this->expectException(NotFoundException::class); - $this->expectErrorMessage('There is no service with id "Nada\Foo"'); + $this->expectExceptionMessage('There is no service with id "Nada\Foo"'); $container = new Container(); $container->addResolver(new ConstructorResolver($container)); diff --git a/tests/TestCase/Resolver/ConstructorResolverTest.php b/tests/TestCase/Resolver/ConstructorResolverTest.php index b94568c..33279a9 100644 --- a/tests/TestCase/Resolver/ConstructorResolverTest.php +++ b/tests/TestCase/Resolver/ConstructorResolverTest.php @@ -1,7 +1,5 @@