Skip to content

Commit 7014f5b

Browse files
authored
Simplify access to reflections in SymfonyCmfRoutingInClassMethodSignatureRule and TestClassesProtectedPropertyModulesRule. (#717)
1 parent cbed039 commit 7014f5b

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

src/Rules/Deprecations/SymfonyCmfRoutingInClassMethodSignatureRule.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PhpParser\Node;
77
use PHPStan\Analyser\Scope;
88
use PHPStan\Node\InClassMethodNode;
9-
use PHPStan\Reflection\MethodReflection;
109
use PHPStan\Reflection\ParametersAcceptorSelector;
1110
use PHPStan\Rules\Rule;
1211
use PHPStan\Rules\RuleErrorBuilder;
@@ -30,10 +29,7 @@ public function processNode(Node $node, Scope $scope): array
3029
if ($major !== '9' || (int) $minor < 1) {
3130
return [];
3231
}
33-
$method = $scope->getFunction();
34-
if (!$method instanceof MethodReflection) {
35-
throw new \PHPStan\ShouldNotHappenException();
36-
}
32+
$method = $node->getMethodReflection();
3733

3834
$cmfRouteObjectInterfaceType = new ObjectType(\Symfony\Cmf\Component\Routing\RouteObjectInterface::class);
3935
$cmfRouteProviderInterfaceType = new ObjectType(\Symfony\Cmf\Component\Routing\RouteProviderInterface::class);

src/Rules/Drupal/TestClassesProtectedPropertyModulesRule.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Node\ClassPropertyNode;
1010
use PHPStan\Rules\Rule;
1111
use PHPStan\Rules\RuleErrorBuilder;
12-
use PHPStan\ShouldNotHappenException;
1312
use PHPUnit\Framework\TestCase;
1413

1514
class TestClassesProtectedPropertyModulesRule implements Rule
@@ -27,15 +26,11 @@ public function processNode(Node $node, Scope $scope): array
2726
{
2827
assert($node instanceof ClassPropertyNode);
2928

30-
if (!$scope->isInClass()) {
31-
throw new ShouldNotHappenException();
32-
}
33-
3429
if ($node->getName() !== 'modules') {
3530
return [];
3631
}
3732

38-
$scopeClassReflection = $scope->getClassReflection();
33+
$scopeClassReflection = $node->getClassReflection();
3934
if ($scopeClassReflection->isAnonymous()) {
4035
return [];
4136
}

0 commit comments

Comments
 (0)