1313use PHPStan \Reflection \ParametersAcceptorSelector ;
1414use PHPStan \Type \MethodTypeSpecifyingExtension ;
1515use PHPStan \Type \TypeCombinator ;
16- use Symfony \Component \HttpFoundation \Request ;
1716
1817final class RequestTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
1918{
2019
20+ private const REQUEST_CLASS = 'Symfony\Component\HttpFoundation\Request ' ;
21+ private const HAS_METHOD_NAME = 'hasSession ' ;
22+ private const GET_METHOD_NAME = 'getSession ' ;
23+
2124 /** @var Broker */
2225 private $ broker ;
2326
@@ -31,21 +34,21 @@ public function __construct(Broker $broker)
3134
3235 public function getClass (): string
3336 {
34- return Request::class ;
37+ return self :: REQUEST_CLASS ;
3538 }
3639
3740 public function isMethodSupported (MethodReflection $ methodReflection , MethodCall $ node , TypeSpecifierContext $ context ): bool
3841 {
39- return $ methodReflection ->getName () === ' hasSession ' && !$ context ->null ();
42+ return $ methodReflection ->getName () === self :: HAS_METHOD_NAME && !$ context ->null ();
4043 }
4144
4245 public function specifyTypes (MethodReflection $ methodReflection , MethodCall $ node , Scope $ scope , TypeSpecifierContext $ context ): SpecifiedTypes
4346 {
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 ();
4649
4750 return $ this ->typeSpecifier ->create (
48- new MethodCall ($ node ->var , ' getSession ' ),
51+ new MethodCall ($ node ->var , self :: GET_METHOD_NAME ),
4952 TypeCombinator::removeNull (ParametersAcceptorSelector::selectSingle ($ methodVariants )->getReturnType ()),
5053 $ context
5154 );
0 commit comments