13
13
use PHPStan \Reflection \ParametersAcceptorSelector ;
14
14
use PHPStan \Type \MethodTypeSpecifyingExtension ;
15
15
use PHPStan \Type \TypeCombinator ;
16
- use Symfony \Component \HttpFoundation \Request ;
17
16
18
17
final class RequestTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
19
18
{
20
19
20
+ private const REQUEST_CLASS = 'Symfony\Component\HttpFoundation\Request ' ;
21
+ private const HAS_METHOD_NAME = 'hasSession ' ;
22
+ private const GET_METHOD_NAME = 'getSession ' ;
23
+
21
24
/** @var Broker */
22
25
private $ broker ;
23
26
@@ -31,21 +34,21 @@ public function __construct(Broker $broker)
31
34
32
35
public function getClass (): string
33
36
{
34
- return Request::class ;
37
+ return self :: REQUEST_CLASS ;
35
38
}
36
39
37
40
public function isMethodSupported (MethodReflection $ methodReflection , MethodCall $ node , TypeSpecifierContext $ context ): bool
38
41
{
39
- return $ methodReflection ->getName () === ' hasSession ' && !$ context ->null ();
42
+ return $ methodReflection ->getName () === self :: HAS_METHOD_NAME && !$ context ->null ();
40
43
}
41
44
42
45
public function specifyTypes (MethodReflection $ methodReflection , MethodCall $ node , Scope $ scope , TypeSpecifierContext $ context ): SpecifiedTypes
43
46
{
44
- $ classReflection = $ this ->broker ->getClass (Request::class );
45
- $ methodVariants = $ classReflection ->getNativeMethod (' getSession ' )->getVariants ();
47
+ $ classReflection = $ this ->broker ->getClass (self :: REQUEST_CLASS );
48
+ $ methodVariants = $ classReflection ->getNativeMethod (self :: GET_METHOD_NAME )->getVariants ();
46
49
47
50
return $ this ->typeSpecifier ->create (
48
- new MethodCall ($ node ->var , ' getSession ' ),
51
+ new MethodCall ($ node ->var , self :: GET_METHOD_NAME ),
49
52
TypeCombinator::removeNull (ParametersAcceptorSelector::selectSingle ($ methodVariants )->getReturnType ()),
50
53
$ context
51
54
);
0 commit comments