Skip to content

Commit db81b18

Browse files
Use stubfile extension for PasswordUpgraderInterface
1 parent e0823d3 commit db81b18

4 files changed

+56
-5
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"require": {
1616
"php": "^7.2 || ^8.0",
1717
"ext-simplexml": "*",
18-
"phpstan/phpstan": "^1.9.4"
18+
"phpstan/phpstan": "^1.9.18"
1919
},
2020
"conflict": {
2121
"symfony/framework-bundle": "<3.0"

extension.neon

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ parameters:
5858
- stubs/Symfony/Component/Security/Core/Authentication/Token/TokenInterface.stub
5959
- stubs/Symfony/Component/Security/Core/Authorization/Voter/Voter.stub
6060
- stubs/Symfony/Component/Security/Core/Authorization/Voter/VoterInterface.stub
61-
- stubs/Symfony/Component/Security/Core/User/PasswordAuthenticatedUserInterface.stub
62-
- stubs/Symfony/Component/Security/Core/User/PasswordUpgraderInterface.stub
6361
- stubs/Symfony/Component/Serializer/Encoder/ContextAwareDecoderInterface.stub
6462
- stubs/Symfony/Component/Serializer/Encoder/DecoderInterface.stub
6563
- stubs/Symfony/Component/Serializer/Encoder/EncoderInterface.stub
@@ -298,6 +296,10 @@ services:
298296
class: PHPStan\Symfony\InputBagStubFilesExtension
299297
tags:
300298
- phpstan.stubFilesExtension
299+
-
300+
class: PHPStan\Symfony\PasswordAuthenticatedUserStubFilesExtension
301+
tags:
302+
- phpstan.stubFilesExtension
301303

302304
# FormInterface::getErrors() return type
303305
-

src/Symfony/InputBagStubFilesExtension.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22

33
namespace PHPStan\Symfony;
44

5+
use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound;
6+
use PHPStan\BetterReflection\Reflector\Reflector;
57
use PHPStan\PhpDoc\StubFilesExtension;
6-
use function class_exists;
78

89
class InputBagStubFilesExtension implements StubFilesExtension
910
{
1011

12+
/** @var Reflector */
13+
private $reflector;
14+
15+
public function __construct(
16+
Reflector $reflector
17+
)
18+
{
19+
$this->reflector = $reflector;
20+
}
21+
1122
public function getFiles(): array
1223
{
13-
if (!class_exists('Symfony\Component\HttpFoundation\InputBag')) {
24+
try {
25+
$this->reflector->reflectClass('Symfony\Component\HttpFoundation\InputBag');
26+
} catch (IdentifierNotFound $e) {
1427
return [];
1528
}
1629

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Symfony;
4+
5+
use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound;
6+
use PHPStan\BetterReflection\Reflector\Reflector;
7+
use PHPStan\PhpDoc\StubFilesExtension;
8+
9+
class PasswordAuthenticatedUserStubFilesExtension implements StubFilesExtension
10+
{
11+
12+
/** @var Reflector */
13+
private $reflector;
14+
15+
public function __construct(
16+
Reflector $reflector
17+
)
18+
{
19+
$this->reflector = $reflector;
20+
}
21+
22+
public function getFiles(): array
23+
{
24+
try {
25+
$this->reflector->reflectClass('Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface');
26+
} catch (IdentifierNotFound $e) {
27+
return [];
28+
}
29+
30+
return [
31+
__DIR__ . '/../../stubs/Symfony/Component/Security/Core/User/PasswordAuthenticatedUserInterface.stub',
32+
__DIR__ . '/../../stubs/Symfony/Component/Security/Core/User/PasswordUpgraderInterface.stub',
33+
];
34+
}
35+
36+
}

0 commit comments

Comments
 (0)