From 46c024cab060b6934ed517f5601fe54290da1bb4 Mon Sep 17 00:00:00 2001 From: Milan Donef Date: Tue, 11 Feb 2025 11:04:39 +0100 Subject: [PATCH 1/3] Update PHP requirements and tooling to PHP 8.0+ compatibility Dropped support for PHP 7.3 and upgraded dependencies to align with PHP 8.0+ requirements, including phpstan 2.0. Updated Docker commands in Makefile to use PHP 8.3 image for consistency with the new requirements. Ensures the codebase remains compatible with modern PHP versions and tools. --- Makefile | 10 +++++----- composer.json | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 022c819..a0cee93 100644 --- a/Makefile +++ b/Makefile @@ -11,16 +11,16 @@ test: $(MAKE) fmt-check phpstan: - docker run -it --rm -v ${PWD}:/app -w /app php:7.3-cli-alpine php -d error_reporting=-1 -d memory_limit=-1 bin/phpstan --ansi analyse + docker run -it --rm -v ${PWD}:/app -w /app php:8.3-cli-alpine php -d error_reporting=-1 -d memory_limit=-1 bin/phpstan --ansi analyse phpstan-clear-cache: - docker run -it --rm -v ${PWD}:/app -w /app php:7.3-cli-alpine php -d error_reporting=-1 -d memory_limit=-1 bin/phpstan --ansi clear-result-cache + docker run -it --rm -v ${PWD}:/app -w /app php:8.3-cli-alpine php -d error_reporting=-1 -d memory_limit=-1 bin/phpstan --ansi clear-result-cache phpunit: - docker run -it --rm -v ${PWD}:/app -w /app php:7.3-cli-alpine php -d error_reporting=-1 bin/phpunit --colors=always -c phpunit.xml + docker run -it --rm -v ${PWD}:/app -w /app php:8.3-cli-alpine php -d error_reporting=-1 bin/phpunit --colors=always -c phpunit.xml fmt-check: - docker run -it --rm -v ${PWD}:/app -w /app php:7.3-cli-alpine php bin/phpcs --standard=./ruleset.xml --extensions=php --tab-width=4 -sp ./src ./tests + docker run -it --rm -v ${PWD}:/app -w /app php:8.3-cli-alpine php bin/phpcs --standard=./ruleset.xml --extensions=php --tab-width=4 -sp ./src ./tests fmt: - docker run -it --rm -v ${PWD}:/app -w /app php:7.3-cli-alpine php bin/phpcbf --standard=./ruleset.xml --extensions=php --tab-width=4 -sp ./src ./tests + docker run -it --rm -v ${PWD}:/app -w /app php:8.3-cli-alpine php bin/phpcbf --standard=./ruleset.xml --extensions=php --tab-width=4 -sp ./src ./tests diff --git a/composer.json b/composer.json index ed9a136..222d15b 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,8 @@ } ], "require": { - "php": ">=7.3|^8.0", - "phpstan/phpstan": "^1.0" + "php": ">=7.4|^8.0", + "phpstan/phpstan": "^2.0" }, "require-dev": { "roave/security-advisories": "dev-latest", @@ -19,7 +19,7 @@ "phpunit/phpunit": "^9.4.2", "slevomat/coding-standard": "^6.4.1", "squizlabs/php_codesniffer": "^3.5.0", - "bonami/collections": "^0.4.5" + "bonami/collections": "dev-upgrade-to-phpstan2" }, "config": { "bin-dir": "bin", From b03818c98920277a472061379e8ddf758eb26dad Mon Sep 17 00:00:00 2001 From: Milan Donef Date: Tue, 11 Feb 2025 13:35:29 +0100 Subject: [PATCH 2/3] Ignore specific PHPStan errors and simplify type assertions --- phpstan.neon | 4 ++++ .../Collection/Phpstan/GroupByMethodReturnTypeExtension.php | 3 ++- tests/Bonami/Collection/Phpstan/MapTest.php | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 90931bc..82eb315 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,6 +2,10 @@ includes: - extension.neon - vendor/phpstan/phpstan/conf/bleedingEdge.neon parameters: + ignoreErrors: + - + identifier: phpstanApi.instanceofType + - '~Method .* should return class-string but returns string.~' reportUnmatchedIgnoredErrors: true level: 9 paths: diff --git a/src/Bonami/Collection/Phpstan/GroupByMethodReturnTypeExtension.php b/src/Bonami/Collection/Phpstan/GroupByMethodReturnTypeExtension.php index 913e840..017713f 100644 --- a/src/Bonami/Collection/Phpstan/GroupByMethodReturnTypeExtension.php +++ b/src/Bonami/Collection/Phpstan/GroupByMethodReturnTypeExtension.php @@ -43,8 +43,9 @@ public function getTypeFromMethodCall( ): Type { $arg = $methodCall->args[0]; assert($arg instanceof Arg); + $closure = $scope->getType($arg->value); - assert($closure instanceof ClosureType || $closure instanceof CallableType); + assert($closure instanceof ClosureType); $listType = $scope->getType($methodCall->var); diff --git a/tests/Bonami/Collection/Phpstan/MapTest.php b/tests/Bonami/Collection/Phpstan/MapTest.php index 04a8222..06b77d4 100644 --- a/tests/Bonami/Collection/Phpstan/MapTest.php +++ b/tests/Bonami/Collection/Phpstan/MapTest.php @@ -12,6 +12,7 @@ class MapTest extends TestCase public function testFromAssociativeArrayReturnType(): void { $genericList = Map::fromAssociativeArray([1 => new Foo()]); + // @phpstan-ignore-next-line $this->requireMapOfFoo($genericList); self::assertInstanceOf(Map::class, $genericList); From a3ba5b3214c0c493acba33e0edc34156e894bf50 Mon Sep 17 00:00:00 2001 From: Milan Donef Date: Fri, 21 Feb 2025 08:45:26 +0100 Subject: [PATCH 3/3] Update PHP versions in CI workflow matrix Remove support for PHP 7.3 and 7.4 while adding support for PHP 8.1. This ensures compatibility with newer PHP versions and drops older, unsupported ones. --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6c15006..7222968 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - php: ['7.3', '7.4', '8.0'] + php: ['8.0','8.1'] steps: - name: "Checkout" @@ -44,7 +44,7 @@ jobs: strategy: matrix: - php: ['7.3', '7.4', '8.0'] + php: ['8.0','8.1'] steps: - name: "Checkout"