From 6f701a344ecf417efe99cffe30a39b5508109c45 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 19 Feb 2023 14:59:59 +0100 Subject: [PATCH 1/4] Use stubfile extension for PasswordUpgraderInterface --- extension.neon | 6 +++-- ...ordAuthenticatedUserStubFilesExtension.php | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php diff --git a/extension.neon b/extension.neon index e4880077..1a8cf313 100644 --- a/extension.neon +++ b/extension.neon @@ -58,8 +58,6 @@ parameters: - stubs/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.stub - stubs/Symfony/Component/Security/Core/Authorization/Voter/Voter.stub - stubs/Symfony/Component/Security/Core/Authorization/Voter/VoterInterface.stub - - stubs/Symfony/Component/Security/Core/User/PasswordAuthenticatedUserInterface.stub - - stubs/Symfony/Component/Security/Core/User/PasswordUpgraderInterface.stub - stubs/Symfony/Component/Serializer/Encoder/ContextAwareDecoderInterface.stub - stubs/Symfony/Component/Serializer/Encoder/DecoderInterface.stub - stubs/Symfony/Component/Serializer/Encoder/EncoderInterface.stub @@ -298,6 +296,10 @@ services: class: PHPStan\Symfony\InputBagStubFilesExtension tags: - phpstan.stubFilesExtension + - + class: PHPStan\Symfony\PasswordAuthenticatedUserStubFilesExtension + tags: + - phpstan.stubFilesExtension # FormInterface::getErrors() return type - diff --git a/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php b/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php new file mode 100644 index 00000000..a2d1c900 --- /dev/null +++ b/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php @@ -0,0 +1,23 @@ + Date: Sun, 19 Feb 2023 18:03:58 +0100 Subject: [PATCH 2/4] Use interface_exists --- src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php b/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php index a2d1c900..1aed4917 100644 --- a/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php +++ b/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php @@ -3,14 +3,14 @@ namespace PHPStan\Symfony; use PHPStan\PhpDoc\StubFilesExtension; -use function class_exists; +use function interface_exists; class PasswordAuthenticatedUserStubFilesExtension implements StubFilesExtension { public function getFiles(): array { - if (!class_exists('Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface')) { + if (!interface_exists('Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface')) { return []; } From ce7182c683d35f3b84e337fe2bc538245a2f12c5 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 20 Feb 2023 01:00:01 +0100 Subject: [PATCH 3/4] Update stub file extensions checks --- src/Symfony/InputBagStubFilesExtension.php | 17 +++++++++++++++-- ...swordAuthenticatedUserStubFilesExtension.php | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Symfony/InputBagStubFilesExtension.php b/src/Symfony/InputBagStubFilesExtension.php index 834ca228..140dae99 100644 --- a/src/Symfony/InputBagStubFilesExtension.php +++ b/src/Symfony/InputBagStubFilesExtension.php @@ -2,15 +2,28 @@ namespace PHPStan\Symfony; +use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound; +use PHPStan\BetterReflection\Reflector\Reflector; use PHPStan\PhpDoc\StubFilesExtension; -use function class_exists; class InputBagStubFilesExtension implements StubFilesExtension { + /** @var Reflector */ + private $reflector; + + public function __construct( + Reflector $reflector + ) + { + $this->reflector = $reflector; + } + public function getFiles(): array { - if (!class_exists('Symfony\Component\HttpFoundation\InputBag')) { + try { + $this->reflector->reflectClass('Symfony\Component\HttpFoundation\InputBag'); + } catch (IdentifierNotFound $e) { return []; } diff --git a/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php b/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php index 1aed4917..8f8c4782 100644 --- a/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php +++ b/src/Symfony/PasswordAuthenticatedUserStubFilesExtension.php @@ -2,15 +2,28 @@ namespace PHPStan\Symfony; +use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound; +use PHPStan\BetterReflection\Reflector\Reflector; use PHPStan\PhpDoc\StubFilesExtension; -use function interface_exists; class PasswordAuthenticatedUserStubFilesExtension implements StubFilesExtension { + /** @var Reflector */ + private $reflector; + + public function __construct( + Reflector $reflector + ) + { + $this->reflector = $reflector; + } + public function getFiles(): array { - if (!interface_exists('Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface')) { + try { + $this->reflector->reflectClass('Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface'); + } catch (IdentifierNotFound $e) { return []; } From c12047b9a5ab3d7b293923ceaadbdb593fafe082 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 20 Feb 2023 01:14:04 +0100 Subject: [PATCH 4/4] Bump phpstan --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9f8c6569..22501953 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "php": "^7.2 || ^8.0", "ext-simplexml": "*", - "phpstan/phpstan": "^1.9.4" + "phpstan/phpstan": "^1.9.18" }, "conflict": { "symfony/framework-bundle": "<3.0"