Skip to content

Commit 84a19b9

Browse files
committed
Use constants instead of using class
1 parent 4001513 commit 84a19b9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Diff for: src/Type/Symfony/RequestTypeSpecifyingExtension.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
use PHPStan\Reflection\ParametersAcceptorSelector;
1414
use PHPStan\Type\MethodTypeSpecifyingExtension;
1515
use PHPStan\Type\TypeCombinator;
16-
use Symfony\Component\HttpFoundation\Request;
1716

1817
final 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

Comments
 (0)