From 176ee6e722692ff658a47d58769c30defa2d75da Mon Sep 17 00:00:00 2001 From: Julien Deniau Date: Thu, 26 Mar 2026 15:02:49 +0000 Subject: [PATCH 1/2] Upgrade to PHPStan 2.x --- .scenarios.lock/symfony6/composer.json | 8 +- .scenarios.lock/symfony6/composer.lock | 61 +++++---- .scenarios.lock/symfony7/composer.json | 8 +- .scenarios.lock/symfony7/composer.lock | 61 +++++---- .scenarios.lock/symfony8/composer.json | 8 +- .scenarios.lock/symfony8/composer.lock | 61 +++++---- composer.json | 8 +- composer.lock | 65 +++++---- phpstan-baseline.neon | 183 +++++++++++++++++++++++-- src/Collection/Collection.php | 8 +- src/Model/ModelHydrator.php | 4 +- 11 files changed, 328 insertions(+), 147 deletions(-) diff --git a/.scenarios.lock/symfony6/composer.json b/.scenarios.lock/symfony6/composer.json index 82cfe61..bd466a4 100644 --- a/.scenarios.lock/symfony6/composer.json +++ b/.scenarios.lock/symfony6/composer.json @@ -27,10 +27,10 @@ "g1a/composer-test-scenarios": "^3.0", "giggsey/libphonenumber-for-php": "^8.0", "friendsofphp/php-cs-fixer": "^3.0.0", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-phpunit": "^1.3", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan-deprecation-rules": "*" + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan-deprecation-rules": "^2.0" }, "suggest": { "giggsey/libphonenumber-for-php": "^1.1 to manage integration with phone number bundle" diff --git a/.scenarios.lock/symfony6/composer.lock b/.scenarios.lock/symfony6/composer.lock index f60312a..825b924 100644 --- a/.scenarios.lock/symfony6/composer.lock +++ b/.scenarios.lock/symfony6/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c4444e75afb8a5fb7b3fda1412a17fca", + "content-hash": "e8509247b8d3e3b8f6274f92f8cf4390", "packages": [ { "name": "friendsofphp/proxy-manager-lts", @@ -2783,15 +2783,15 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.33", + "version": "2.1.44", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/37982d6fc7cbb746dda7773530cda557cdf119e1", - "reference": "37982d6fc7cbb746dda7773530cda557cdf119e1", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/4a88c083c668b2c364a425c9b3171b2d9ea5d218", + "reference": "4a88c083c668b2c364a425c9b3171b2d9ea5d218", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -2832,30 +2832,30 @@ "type": "github" } ], - "time": "2026-02-28T20:30:03+00:00" + "time": "2026-03-25T17:34:21+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", - "version": "1.2.1", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", - "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82" + "reference": "6b5571001a7f04fa0422254c30a0017ec2f2cacc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/f94d246cc143ec5a23da868f8f7e1393b50eaa82", - "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/6b5571001a7f04fa0422254c30a0017ec2f2cacc", + "reference": "6b5571001a7f04fa0422254c30a0017ec2f2cacc", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.39" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" }, "type": "phpstan-extension", "extra": { @@ -2875,38 +2875,42 @@ "MIT" ], "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "keywords": [ + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", - "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.2.1" + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.4" }, - "time": "2024-09-11T15:52:35+00:00" + "time": "2026-02-09T13:21:14+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "1.4.2", + "version": "2.0.16", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "72a6721c9b64b3e4c9db55abbc38f790b318267e" + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/72a6721c9b64b3e4c9db55abbc38f790b318267e", - "reference": "72a6721c9b64b3e4c9db55abbc38f790b318267e", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/6ab598e1bc106e6827fd346ae4a12b4a5d634c32", + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.32" }, "conflict": { "phpunit/phpunit": "<7.0" }, "require-dev": { - "nikic/php-parser": "^4.13.0", + "nikic/php-parser": "^5", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-strict-rules": "^1.5.1", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6" }, "type": "phpstan-extension", "extra": { @@ -2927,11 +2931,14 @@ "MIT" ], "description": "PHPUnit extensions and rules for PHPStan", + "keywords": [ + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.4.2" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.16" }, - "time": "2024-12-17T17:20:49+00:00" + "time": "2026-02-14T09:05:21+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/.scenarios.lock/symfony7/composer.json b/.scenarios.lock/symfony7/composer.json index fc1d9ea..9ccdb51 100644 --- a/.scenarios.lock/symfony7/composer.json +++ b/.scenarios.lock/symfony7/composer.json @@ -27,10 +27,10 @@ "g1a/composer-test-scenarios": "^3.0", "giggsey/libphonenumber-for-php": "^8.0", "friendsofphp/php-cs-fixer": "^3.0.0", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-phpunit": "^1.3", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan-deprecation-rules": "*" + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan-deprecation-rules": "^2.0" }, "suggest": { "giggsey/libphonenumber-for-php": "^1.1 to manage integration with phone number bundle" diff --git a/.scenarios.lock/symfony7/composer.lock b/.scenarios.lock/symfony7/composer.lock index 41d900f..383a50f 100644 --- a/.scenarios.lock/symfony7/composer.lock +++ b/.scenarios.lock/symfony7/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4b46eec4ad5e0e54395685c4ba218276", + "content-hash": "0f13aa076908861f51f587b76b50c3d1", "packages": [ { "name": "friendsofphp/proxy-manager-lts", @@ -2700,15 +2700,15 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.33", + "version": "2.1.44", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/37982d6fc7cbb746dda7773530cda557cdf119e1", - "reference": "37982d6fc7cbb746dda7773530cda557cdf119e1", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/4a88c083c668b2c364a425c9b3171b2d9ea5d218", + "reference": "4a88c083c668b2c364a425c9b3171b2d9ea5d218", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -2749,30 +2749,30 @@ "type": "github" } ], - "time": "2026-02-28T20:30:03+00:00" + "time": "2026-03-25T17:34:21+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", - "version": "1.2.1", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", - "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82" + "reference": "6b5571001a7f04fa0422254c30a0017ec2f2cacc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/f94d246cc143ec5a23da868f8f7e1393b50eaa82", - "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/6b5571001a7f04fa0422254c30a0017ec2f2cacc", + "reference": "6b5571001a7f04fa0422254c30a0017ec2f2cacc", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.39" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" }, "type": "phpstan-extension", "extra": { @@ -2792,38 +2792,42 @@ "MIT" ], "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "keywords": [ + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", - "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.2.1" + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.4" }, - "time": "2024-09-11T15:52:35+00:00" + "time": "2026-02-09T13:21:14+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "1.4.2", + "version": "2.0.16", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "72a6721c9b64b3e4c9db55abbc38f790b318267e" + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/72a6721c9b64b3e4c9db55abbc38f790b318267e", - "reference": "72a6721c9b64b3e4c9db55abbc38f790b318267e", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/6ab598e1bc106e6827fd346ae4a12b4a5d634c32", + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.32" }, "conflict": { "phpunit/phpunit": "<7.0" }, "require-dev": { - "nikic/php-parser": "^4.13.0", + "nikic/php-parser": "^5", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-strict-rules": "^1.5.1", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6" }, "type": "phpstan-extension", "extra": { @@ -2844,11 +2848,14 @@ "MIT" ], "description": "PHPUnit extensions and rules for PHPStan", + "keywords": [ + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.4.2" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.16" }, - "time": "2024-12-17T17:20:49+00:00" + "time": "2026-02-14T09:05:21+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/.scenarios.lock/symfony8/composer.json b/.scenarios.lock/symfony8/composer.json index 1cef155..128abb8 100644 --- a/.scenarios.lock/symfony8/composer.json +++ b/.scenarios.lock/symfony8/composer.json @@ -27,10 +27,10 @@ "g1a/composer-test-scenarios": "^3.0", "giggsey/libphonenumber-for-php": "^8.0", "friendsofphp/php-cs-fixer": "^3.0.0", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-phpunit": "^1.3", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan-deprecation-rules": "*" + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan-deprecation-rules": "^2.0" }, "suggest": { "giggsey/libphonenumber-for-php": "^1.1 to manage integration with phone number bundle" diff --git a/.scenarios.lock/symfony8/composer.lock b/.scenarios.lock/symfony8/composer.lock index 679c181..810b795 100644 --- a/.scenarios.lock/symfony8/composer.lock +++ b/.scenarios.lock/symfony8/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "49a0d7ad33b8766a33a3cdbf4e65fdc6", + "content-hash": "86d119e525c322fe23cf0ae9a08d6a93", "packages": [ { "name": "friendsofphp/proxy-manager-lts", @@ -2698,15 +2698,15 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.33", + "version": "2.1.44", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/37982d6fc7cbb746dda7773530cda557cdf119e1", - "reference": "37982d6fc7cbb746dda7773530cda557cdf119e1", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/4a88c083c668b2c364a425c9b3171b2d9ea5d218", + "reference": "4a88c083c668b2c364a425c9b3171b2d9ea5d218", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -2747,30 +2747,30 @@ "type": "github" } ], - "time": "2026-02-28T20:30:03+00:00" + "time": "2026-03-25T17:34:21+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", - "version": "1.2.1", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", - "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82" + "reference": "6b5571001a7f04fa0422254c30a0017ec2f2cacc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/f94d246cc143ec5a23da868f8f7e1393b50eaa82", - "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/6b5571001a7f04fa0422254c30a0017ec2f2cacc", + "reference": "6b5571001a7f04fa0422254c30a0017ec2f2cacc", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.39" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" }, "type": "phpstan-extension", "extra": { @@ -2790,38 +2790,42 @@ "MIT" ], "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "keywords": [ + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", - "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.2.1" + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.4" }, - "time": "2024-09-11T15:52:35+00:00" + "time": "2026-02-09T13:21:14+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "1.4.2", + "version": "2.0.16", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "72a6721c9b64b3e4c9db55abbc38f790b318267e" + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/72a6721c9b64b3e4c9db55abbc38f790b318267e", - "reference": "72a6721c9b64b3e4c9db55abbc38f790b318267e", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/6ab598e1bc106e6827fd346ae4a12b4a5d634c32", + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.32" }, "conflict": { "phpunit/phpunit": "<7.0" }, "require-dev": { - "nikic/php-parser": "^4.13.0", + "nikic/php-parser": "^5", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-strict-rules": "^1.5.1", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6" }, "type": "phpstan-extension", "extra": { @@ -2842,11 +2846,14 @@ "MIT" ], "description": "PHPUnit extensions and rules for PHPStan", + "keywords": [ + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.4.2" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.16" }, - "time": "2024-12-17T17:20:49+00:00" + "time": "2026-02-14T09:05:21+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/composer.json b/composer.json index 7c0b792..f18f541 100644 --- a/composer.json +++ b/composer.json @@ -27,10 +27,10 @@ "g1a/composer-test-scenarios": "^3.0", "giggsey/libphonenumber-for-php": "^8.0", "friendsofphp/php-cs-fixer": "^3.0.0", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-phpunit": "^1.3", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan-deprecation-rules": "^1.2" + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan-deprecation-rules": "^2.0" }, "suggest": { "giggsey/libphonenumber-for-php": "^1.1 to manage integration with phone number bundle" diff --git a/composer.lock b/composer.lock index 261ec1b..91df9aa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f287ab352646a93d8c3ad327c04fb476", + "content-hash": "7a30683e64adfecbfa351e811bf409bb", "packages": [ { "name": "friendsofphp/proxy-manager-lts", @@ -2698,15 +2698,15 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.33", + "version": "2.1.44", "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/37982d6fc7cbb746dda7773530cda557cdf119e1", - "reference": "37982d6fc7cbb746dda7773530cda557cdf119e1", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/4a88c083c668b2c364a425c9b3171b2d9ea5d218", + "reference": "4a88c083c668b2c364a425c9b3171b2d9ea5d218", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -2747,30 +2747,30 @@ "type": "github" } ], - "time": "2026-02-28T20:30:03+00:00" + "time": "2026-03-25T17:34:21+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", - "version": "1.2.1", + "version": "2.0.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-deprecation-rules.git", - "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82" + "reference": "6b5571001a7f04fa0422254c30a0017ec2f2cacc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/f94d246cc143ec5a23da868f8f7e1393b50eaa82", - "reference": "f94d246cc143ec5a23da868f8f7e1393b50eaa82", + "url": "https://api.github.com/repos/phpstan/phpstan-deprecation-rules/zipball/6b5571001a7f04fa0422254c30a0017ec2f2cacc", + "reference": "6b5571001a7f04fa0422254c30a0017ec2f2cacc", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.39" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6" }, "type": "phpstan-extension", "extra": { @@ -2790,38 +2790,42 @@ "MIT" ], "description": "PHPStan rules for detecting usage of deprecated classes, methods, properties, constants and traits.", + "keywords": [ + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/phpstan-deprecation-rules/issues", - "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/1.2.1" + "source": "https://github.com/phpstan/phpstan-deprecation-rules/tree/2.0.4" }, - "time": "2024-09-11T15:52:35+00:00" + "time": "2026-02-09T13:21:14+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "1.4.2", + "version": "2.0.16", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "72a6721c9b64b3e4c9db55abbc38f790b318267e" + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/72a6721c9b64b3e4c9db55abbc38f790b318267e", - "reference": "72a6721c9b64b3e4c9db55abbc38f790b318267e", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/6ab598e1bc106e6827fd346ae4a12b4a5d634c32", + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.32" }, "conflict": { "phpunit/phpunit": "<7.0" }, "require-dev": { - "nikic/php-parser": "^4.13.0", + "nikic/php-parser": "^5", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-strict-rules": "^1.5.1", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6" }, "type": "phpstan-extension", "extra": { @@ -2842,11 +2846,14 @@ "MIT" ], "description": "PHPUnit extensions and rules for PHPStan", + "keywords": [ + "static analysis" + ], "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.4.2" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.16" }, - "time": "2024-12-17T17:20:49+00:00" + "time": "2026-02-14T09:05:21+00:00" }, { "name": "phpunit/php-code-coverage", @@ -6018,12 +6025,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { "php": "^8.4" }, - "platform-dev": [], + "platform-dev": {}, "plugin-api-version": "2.6.0" } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 97136bf..e2c5946 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,76 +1,229 @@ parameters: ignoreErrors: - - message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, Closure\\(array\\|null\\)\\: \\(object\\|null\\) given\\.$#" + rawMessage: 'Parameter #1 $id of method Mapado\RestClientSdk\UnitOfWork::clear() expects string, mixed given.' + identifier: argument.type + count: 1 + path: src/EntityRepository.php + + - + rawMessage: 'Parameter #1 $id of method Mapado\RestClientSdk\UnitOfWork::getDirtyEntity() expects string, mixed given.' + identifier: argument.type + count: 1 + path: src/EntityRepository.php + + - + rawMessage: 'Parameter #1 $id of method Mapado\RestClientSdk\UnitOfWork::registerClean() expects string, mixed given.' + identifier: argument.type + count: 3 + path: src/EntityRepository.php + + - + rawMessage: 'Parameter #1 $key of method Mapado\RestClientSdk\EntityRepository::removeFromCache() expects string, mixed given.' + identifier: argument.type + count: 2 + path: src/EntityRepository.php + + - + rawMessage: 'Parameter #1 $key of method Mapado\RestClientSdk\EntityRepository::saveToCache() expects string, mixed given.' + identifier: argument.type + count: 3 + path: src/EntityRepository.php + + - + rawMessage: 'Parameter #1 $path of method Mapado\RestClientSdk\EntityRepository::addQueryParameter() expects string, mixed given.' + identifier: argument.type + count: 1 + path: src/EntityRepository.php + + - + rawMessage: 'Parameter #1 $path of method Mapado\RestClientSdk\RestClient::delete() expects string, mixed given.' + identifier: argument.type + count: 1 + path: src/EntityRepository.php + + - + rawMessage: 'Parameter #1 $array of function array_diff_assoc expects an array of values castable to string, array given.' + identifier: argument.type + count: 1 + path: src/Helper/ArrayHelper.php + + - + rawMessage: 'Parameter #2 $arrays of function array_diff_assoc expects an array of values castable to string, array given.' + identifier: argument.type + count: 1 + path: src/Helper/ArrayHelper.php + + - + rawMessage: 'Parameter #1 $callback of function array_map expects (callable(mixed): mixed)|null, Closure(array|null): (object|null) given.' + identifier: argument.type count: 1 path: src/Model/ModelHydrator.php - - message: "#^Call to function is_object\\(\\) with object will always evaluate to true\\.$#" + rawMessage: 'Call to function is_object() with object will always evaluate to true.' + identifier: function.alreadyNarrowedType count: 1 path: src/Model/Serializer.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:addIdentifiers\\(\\) has parameter \\$dirtyFields with no value type specified in iterable type array\\.$#" + rawMessage: Cannot cast mixed to string. + identifier: cast.string count: 1 + path: src/Model/Serializer.php + + - + rawMessage: 'Method Mapado\RestClientSdk\Model\Serializer::recursiveSerialize() should return array|string but returns mixed.' + identifier: return.type + count: 1 + path: src/Model/Serializer.php + + - + rawMessage: 'Argument of an invalid type mixed supplied for foreach, only iterables are supported.' + identifier: foreach.nonIterable + count: 1 + path: src/UnitOfWork.php + + - + rawMessage: Cannot access offset mixed on mixed. + identifier: offsetAccess.nonOffsetAccessible + count: 2 + path: src/UnitOfWork.php + + - + rawMessage: Cannot access offset non-falsy-string on mixed. + identifier: offsetAccess.nonOffsetAccessible + count: 2 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:addIdentifiers\\(\\) has parameter \\$newSerializedModel with no value type specified in iterable type array\\.$#" + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::addIdentifiers() has parameter $dirtyFields with no value type specified in iterable type array.' + identifier: missingType.iterableValue count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:addIdentifiers\\(\\) return type has no value type specified in iterable type array\\.$#" + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::addIdentifiers() has parameter $newSerializedModel with no value type specified in iterable type array.' + identifier: missingType.iterableValue count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:findOldRelation\\(\\) has parameter \\$oldValue with no value type specified in iterable type array\\.$#" + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::addIdentifiers() return type has no value type specified in iterable type array.' + identifier: missingType.iterableValue count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:findOldRelation\\(\\) has parameter \\$relationValue with no value type specified in iterable type array\\.$#" + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::findOldRelation() has parameter $oldValue with no value type specified in iterable type array.' + identifier: missingType.iterableValue count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:findOldRelation\\(\\) return type has no value type specified in iterable type array\\.$#" + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::findOldRelation() has parameter $relationValue with no value type specified in iterable type array.' + identifier: missingType.iterableValue count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:getDirtyData\\(\\) has parameter \\$newSerializedModel with no value type specified in iterable type array\\.$#" + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::findOldRelation() return type has no value type specified in iterable type array.' + identifier: missingType.iterableValue count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:getDirtyData\\(\\) has parameter \\$oldSerializedModel with no value type specified in iterable type array\\.$#" + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::findOldRelation() should return array|string but returns mixed.' + identifier: return.type count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:getDirtyData\\(\\) return type has no value type specified in iterable type array\\.$#" + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::getDirtyData() has parameter $newSerializedModel with no value type specified in iterable type array.' + identifier: missingType.iterableValue count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:getDirtyFields\\(\\) has parameter \\$newSerializedModel with no value type specified in iterable type array\\.$#" + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::getDirtyData() has parameter $oldSerializedModel with no value type specified in iterable type array.' + identifier: missingType.iterableValue count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:getDirtyFields\\(\\) has parameter \\$oldSerializedModel with no value type specified in iterable type array\\.$#" + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::getDirtyData() return type has no value type specified in iterable type array.' + identifier: missingType.iterableValue + count: 1 + path: src/UnitOfWork.php + + - + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::getDirtyFields() has parameter $newSerializedModel with no value type specified in iterable type array.' + identifier: missingType.iterableValue + count: 1 + path: src/UnitOfWork.php + + - + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::getDirtyFields() has parameter $oldSerializedModel with no value type specified in iterable type array.' + identifier: missingType.iterableValue + count: 1 + path: src/UnitOfWork.php + + - + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::getDirtyFields() return type has no value type specified in iterable type array.' + identifier: missingType.iterableValue + count: 1 + path: src/UnitOfWork.php + + - + rawMessage: 'Method Mapado\RestClientSdk\UnitOfWork::getEntityId() has parameter $stringOrEntity with no value type specified in iterable type array.' + identifier: missingType.iterableValue + count: 1 + path: src/UnitOfWork.php + + - + rawMessage: 'Parameter #1 $newSerializedModel of method Mapado\RestClientSdk\UnitOfWork::addIdentifiers() expects array, mixed given.' + identifier: argument.type + count: 1 + path: src/UnitOfWork.php + + - + rawMessage: 'Parameter #1 $newSerializedModel of method Mapado\RestClientSdk\UnitOfWork::getDirtyFields() expects array, mixed given.' + identifier: argument.type + count: 2 + path: src/UnitOfWork.php + + - + rawMessage: 'Parameter #1 $relationValue of method Mapado\RestClientSdk\UnitOfWork::findOldRelation() expects array|string, mixed given.' + identifier: argument.type + count: 1 + path: src/UnitOfWork.php + + - + rawMessage: 'Parameter #1 $stringOrEntity of static method Mapado\RestClientSdk\UnitOfWork::getEntityId() expects array|string, mixed given.' + identifier: argument.type + count: 3 + path: src/UnitOfWork.php + + - + rawMessage: 'Parameter #1 $value of function count expects array|Countable, mixed given.' + identifier: argument.type + count: 2 + path: src/UnitOfWork.php + + - + rawMessage: 'Parameter #2 $array2 of static method Mapado\RestClientSdk\Helper\ArrayHelper::arraySame() expects array, mixed given.' + identifier: argument.type count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:getDirtyFields\\(\\) return type has no value type specified in iterable type array\\.$#" + rawMessage: 'Parameter #2 $oldSerializedModel of method Mapado\RestClientSdk\UnitOfWork::getDirtyFields() expects array, mixed given.' + identifier: argument.type count: 1 path: src/UnitOfWork.php - - message: "#^Method Mapado\\\\RestClientSdk\\\\UnitOfWork\\:\\:getEntityId\\(\\) has parameter \\$stringOrEntity with no value type specified in iterable type array\\.$#" + rawMessage: 'Parameter #2 $oldValue of method Mapado\RestClientSdk\UnitOfWork::findOldRelation() expects array, mixed given.' + identifier: argument.type count: 1 path: src/UnitOfWork.php diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index bf0daf3..91fe781 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -94,7 +94,7 @@ public function getTotalItems(): int } /** - * @param mixed|null $offset + * @param array-key|null $offset * * @phpstan-param E $value */ @@ -108,7 +108,7 @@ public function offsetSet($offset, $value): void } /** - * @param mixed|null $offset + * @param array-key|null $offset */ public function offsetExists($offset): bool { @@ -116,7 +116,7 @@ public function offsetExists($offset): bool } /** - * @param mixed|null $offset + * @param array-key|null $offset */ public function offsetUnset($offset): void { @@ -124,7 +124,7 @@ public function offsetUnset($offset): void } /** - * @param mixed|null $offset + * @param array-key|null $offset * * @return mixed|null * diff --git a/src/Model/ModelHydrator.php b/src/Model/ModelHydrator.php index 1f77fe2..35d07d1 100644 --- a/src/Model/ModelHydrator.php +++ b/src/Model/ModelHydrator.php @@ -124,7 +124,7 @@ private function deserializeAll(array $data, string $modelName): Collection /** * convert array to entity * - * @param array|null $data + * @param array|null $data * @param class-string $modelName */ private function deserialize(?array $data, string $modelName): ?object @@ -139,7 +139,7 @@ private function deserialize(?array $data, string $modelName): ?object /** * guess collection classname according to response data * - * @param array $data + * @param array $data */ private function guessCollectionClassname(array $data): string { From f66c9a447af28a32a231d1b6ae531a5a02a5d3b5 Mon Sep 17 00:00:00 2001 From: Julien Deniau Date: Thu, 26 Mar 2026 16:01:58 +0000 Subject: [PATCH 2/2] extension : phpstan 2 compatibility --- CHANGELOG.md | 1 + .../RepositoryMagicFindExtension.php | 47 ++++++++++++------- ...etRepositoryDynamicReturnTypeExtension.php | 40 +++++++++------- .../Type/ObjectMetadataResolver.php | 7 ++- ...ctRepositoryDynamicReturnTypeExtension.php | 24 +++++----- phpstan.neon | 1 + 6 files changed, 75 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 091d7d0..6f14605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - [BREAKING] Drop support for PHP < 8.4 - [BREAKING] Drop support for Symfony < 6.0 - Allow Symfony 7 and 8 +- [BREAKING] phpstan-extension: Drop support PHPStan < 2.0 ## 2.1.1 diff --git a/phpstan-extension/Reflection/RepositoryMagicFindExtension.php b/phpstan-extension/Reflection/RepositoryMagicFindExtension.php index 33e99f3..2b601f1 100644 --- a/phpstan-extension/Reflection/RepositoryMagicFindExtension.php +++ b/phpstan-extension/Reflection/RepositoryMagicFindExtension.php @@ -4,42 +4,57 @@ namespace Mapado\RestClientSdk\PHPStan\Reflection; -use PHPStan\Broker\Broker; -use PHPStan\Reflection\BrokerAwareExtension; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\Dummy\DummyMethodReflection; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\MethodsClassReflectionExtension; +use PHPStan\Reflection\ReflectionProvider; -class RepositoryMagicFindExtension implements MethodsClassReflectionExtension, BrokerAwareExtension +class RepositoryMagicFindExtension implements MethodsClassReflectionExtension { - /** @var Broker */ - private $broker; + private ReflectionProvider $reflectionProvider; - public function setBroker(Broker $broker): void + public function __construct(ReflectionProvider $reflectionProvider) { - $this->broker = $broker; + $this->reflectionProvider = $reflectionProvider; } - public function hasMethod(ClassReflection $classReflection, string $methodName): bool - { - if (0 !== mb_strpos($methodName, 'findBy') - && 0 !== mb_strpos($methodName, 'findOneBy') + public function hasMethod( + ClassReflection $classReflection, + string $methodName, + ): bool { + if ( + 0 !== mb_strpos($methodName, 'findBy') && + 0 !== mb_strpos($methodName, 'findOneBy') ) { return false; } - if ('Mapado\RestClientSdk\EntityRepository' === $classReflection->getName()) { + if ( + 'Mapado\RestClientSdk\EntityRepository' === + $classReflection->getName() + ) { return true; } - if (!$this->broker->hasClass('Mapado\RestClientSdk\EntityRepository')) { + if ( + !$this->reflectionProvider->hasClass( + 'Mapado\RestClientSdk\EntityRepository', + ) + ) { return false; } - return $classReflection->isSubclassOf('Mapado\RestClientSdk\EntityRepository'); + return $classReflection->isSubclassOfClass( + $this->reflectionProvider->getClass( + 'Mapado\RestClientSdk\EntityRepository', + ), + ); } - public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection - { + public function getMethod( + ClassReflection $classReflection, + string $methodName, + ): MethodReflection { + /** @phpstan-ignore-next-line phpstanApi.constructor */ return new DummyMethodReflection($methodName); } } diff --git a/phpstan-extension/Type/GetRepositoryDynamicReturnTypeExtension.php b/phpstan-extension/Type/GetRepositoryDynamicReturnTypeExtension.php index 2d33d68..87f8caa 100644 --- a/phpstan-extension/Type/GetRepositoryDynamicReturnTypeExtension.php +++ b/phpstan-extension/Type/GetRepositoryDynamicReturnTypeExtension.php @@ -8,29 +8,29 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParametersAcceptorSelector; -use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\MixedType; use PHPStan\Type\Type; -class GetRepositoryDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension +class GetRepositoryDynamicReturnTypeExtension implements + DynamicMethodReturnTypeExtension { - /** @var string */ - private $sdkClientClass; + private string $sdkClientClass; - /** @var ObjectMetadataResolver */ - private $metadataResolver; + private ObjectMetadataResolver $metadataResolver; public function __construct( string $sdkClientClass, - ObjectMetadataResolver $metadataResolver + ObjectMetadataResolver $metadataResolver, ) { + /** @var class-string $sdkClientClass */ $this->sdkClientClass = $sdkClientClass; $this->metadataResolver = $metadataResolver; } public function getClass(): string { + /** @var class-string */ return $this->sdkClientClass; } @@ -42,20 +42,28 @@ public function isMethodSupported(MethodReflection $methodReflection): bool public function getTypeFromMethodCall( MethodReflection $methodReflection, MethodCall $methodCall, - Scope $scope + Scope $scope, ): Type { - if (0 === count($methodCall->args)) { - return ParametersAcceptorSelector::selectSingle( - $methodReflection->getVariants() + $args = $methodCall->getArgs(); + if (0 === count($args)) { + return ParametersAcceptorSelector::selectFromArgs( + $scope, + $args, + $methodReflection->getVariants(), )->getReturnType(); } - $argType = $scope->getType($methodCall->args[0]->value); - if (!$argType instanceof ConstantStringType) { + $argType = $scope->getType($args[0]->value); + $constantStrings = $argType->getConstantStrings(); + if (count($constantStrings) === 0) { return new MixedType(); } - $objectName = $argType->getValue(); - $className = $this->metadataResolver->resolveClassnameForKey($objectName); - $repositoryClass = $this->metadataResolver->getRepositoryClass($className); + $objectName = $constantStrings[0]->getValue(); + $className = $this->metadataResolver->resolveClassnameForKey( + $objectName, + ); + $repositoryClass = $this->metadataResolver->getRepositoryClass( + $className, + ); return new ObjectRepositoryType($className, $repositoryClass); } diff --git a/phpstan-extension/Type/ObjectMetadataResolver.php b/phpstan-extension/Type/ObjectMetadataResolver.php index fec181f..d5e71c7 100644 --- a/phpstan-extension/Type/ObjectMetadataResolver.php +++ b/phpstan-extension/Type/ObjectMetadataResolver.php @@ -52,6 +52,8 @@ public function getRepositoryClass(string $className): string private function getMetadataForKeyOrClassname(string $value): ClassMetadata { + assert($this->registry !== null); + foreach ($this->registry->getSdkClientList() as $sdkClient) { $mapping = $sdkClient->getMapping(); @@ -78,6 +80,9 @@ private function loadRegistry(string $registryFile): ?SdkClientRegistry throw new \PHPStan\ShouldNotHappenException('Object manager could not be loaded'); } - return require $registryFile; + /** @var SdkClientRegistry|null */ + $registry = require $registryFile; + + return $registry; } } diff --git a/phpstan-extension/Type/ObjectRepositoryDynamicReturnTypeExtension.php b/phpstan-extension/Type/ObjectRepositoryDynamicReturnTypeExtension.php index ca8ab74..66f1377 100644 --- a/phpstan-extension/Type/ObjectRepositoryDynamicReturnTypeExtension.php +++ b/phpstan-extension/Type/ObjectRepositoryDynamicReturnTypeExtension.php @@ -6,24 +6,22 @@ use PhpParser\Node\Expr\MethodCall; use PHPStan\Analyser\Scope; -use PHPStan\Broker\Broker; -use PHPStan\Reflection\BrokerAwareExtension; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParametersAcceptorSelector; +use PHPStan\Reflection\ReflectionProvider; +use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; -use PHPStan\Type\TypeWithClassName; -class ObjectRepositoryDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension, BrokerAwareExtension +class ObjectRepositoryDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { - /** @var Broker */ - private $broker; + private ReflectionProvider $reflectionProvider; - public function setBroker(Broker $broker): void + public function __construct(ReflectionProvider $reflectionProvider) { - $this->broker = $broker; + $this->reflectionProvider = $reflectionProvider; } public function getClass(): string @@ -50,13 +48,15 @@ public function getTypeFromMethodCall( Scope $scope ): Type { $calledOnType = $scope->getType($methodCall->var); - if (!$calledOnType instanceof TypeWithClassName) { + $classNames = $calledOnType->getObjectClassNames(); + if (count($classNames) === 0) { return new MixedType(); } + $className = $classNames[0]; $methodName = $methodReflection->getName(); - if ($this->broker->hasClass($calledOnType->getClassName())) { - $repositoryClassReflection = $this->broker->getClass($calledOnType->getClassName()); + if ($this->reflectionProvider->hasClass($className)) { + $repositoryClassReflection = $this->reflectionProvider->getClass($className); if ( ( ( @@ -71,7 +71,7 @@ public function getTypeFromMethodCall( ) { return ParametersAcceptorSelector::selectFromArgs( $scope, - $methodCall->args, + $methodCall->getArgs(), $repositoryClassReflection->getNativeMethod($methodName)->getVariants() )->getReturnType(); } diff --git a/phpstan.neon b/phpstan.neon index a302d8e..937afe3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,4 +10,5 @@ parameters: paths: - src + - phpstan-extension # - Tests/Units