From 9311dfeb319970603ed710d1ac64bfdfe44777b7 Mon Sep 17 00:00:00 2001 From: Alex Wells Date: Tue, 16 Sep 2025 12:15:13 +0200 Subject: [PATCH 1/2] fix: PHPStan failing on older dependencies --- .github/workflows/tests.yml | 8 ++++++-- composer.json | 2 +- src/PHPStan/ReflectorReturnType.php | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index de0e552..59ec0e4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,12 +4,16 @@ on: [push, pull_request, workflow_dispatch] jobs: phpunit: - name: PHPUnit on PHP v${{ matrix.php }} + name: PHPUnit on PHP v${{ matrix.php }} ${{ matrix.dependencies }} runs-on: ubuntu-latest strategy: fail-fast: true matrix: php: [ 8.2, 8.3, 8.4 ] + dependencies: ['', --prefer-lowest] + exclude: + - php: 8.4 + dependencies: --prefer-lowest steps: - name: Checkout code @@ -35,7 +39,7 @@ jobs: ${{ runner.os }}-php- - name: Install dependencies - run: composer install --prefer-dist --no-progress + run: composer install --prefer-dist --no-progress ${{ matrix.dependencies }} - name: Execute phpunit run: composer test -- --colors=always diff --git a/composer.json b/composer.json index 541952e..18ae6ad 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "nikic/php-parser": "^5.0", "phpstan/phpdoc-parser": "^2.1", "psr/simple-cache": "^3.0", - "symfony/cache": "^7.0", + "symfony/cache": "^7.3", "symfony/var-exporter": "^7.0", "webmozart/assert": "^1.11" }, diff --git a/src/PHPStan/ReflectorReturnType.php b/src/PHPStan/ReflectorReturnType.php index 9ada9a1..d36b2eb 100644 --- a/src/PHPStan/ReflectorReturnType.php +++ b/src/PHPStan/ReflectorReturnType.php @@ -87,7 +87,9 @@ private function reflectionTypeClassName(Type $type): ?string private function typeFromMethodCall(MethodCall $methodCall, Scope $scope): ?Type { - $nameArg = $methodCall->getArg('name', 0); + $nameArg = method_exists($methodCall, 'getArg') ? + $methodCall->getArg('name', 0) : + $methodCall->getArgs()[0] ?? null; if (!$nameArg) { return null; From 74594ca9a63a1fa8a49bd681a632a22a2f304679 Mon Sep 17 00:00:00 2001 From: Alex Wells Date: Tue, 16 Sep 2025 12:21:22 +0200 Subject: [PATCH 2/2] fix: PHPStan failing --- .github/workflows/tests.yml | 3 +-- src/PHPStan/ReflectorReturnType.php | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 59ec0e4..39e4fb8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,6 @@ jobs: name: PHPUnit on PHP v${{ matrix.php }} ${{ matrix.dependencies }} runs-on: ubuntu-latest strategy: - fail-fast: true matrix: php: [ 8.2, 8.3, 8.4 ] dependencies: ['', --prefer-lowest] @@ -39,7 +38,7 @@ jobs: ${{ runner.os }}-php- - name: Install dependencies - run: composer install --prefer-dist --no-progress ${{ matrix.dependencies }} + run: composer update --prefer-dist --no-progress ${{ matrix.dependencies }} - name: Execute phpunit run: composer test -- --colors=always diff --git a/src/PHPStan/ReflectorReturnType.php b/src/PHPStan/ReflectorReturnType.php index d36b2eb..af2133c 100644 --- a/src/PHPStan/ReflectorReturnType.php +++ b/src/PHPStan/ReflectorReturnType.php @@ -87,6 +87,7 @@ private function reflectionTypeClassName(Type $type): ?string private function typeFromMethodCall(MethodCall $methodCall, Scope $scope): ?Type { + /** @phpstan-ignore function.alreadyNarrowedType */ $nameArg = method_exists($methodCall, 'getArg') ? $methodCall->getArg('name', 0) : $methodCall->getArgs()[0] ?? null;