Skip to content

Commit 90e48fa

Browse files
committed
Attributes rules use In*Node virtual nodes for more precise Scope
1 parent c5df243 commit 90e48fa

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

src/Rules/Functions/ArrowFunctionAttributesRule.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
use Attribute;
66
use PhpParser\Node;
77
use PHPStan\Analyser\Scope;
8+
use PHPStan\Node\InArrowFunctionNode;
89
use PHPStan\Rules\AttributesCheck;
910
use PHPStan\Rules\Rule;
1011

1112
/**
12-
* @implements Rule<Node\Expr\ArrowFunction>
13+
* @implements Rule<InArrowFunctionNode>
1314
*/
1415
final class ArrowFunctionAttributesRule implements Rule
1516
{
@@ -20,14 +21,14 @@ public function __construct(private AttributesCheck $attributesCheck)
2021

2122
public function getNodeType(): string
2223
{
23-
return Node\Expr\ArrowFunction::class;
24+
return InArrowFunctionNode::class;
2425
}
2526

2627
public function processNode(Node $node, Scope $scope): array
2728
{
2829
return $this->attributesCheck->check(
2930
$scope,
30-
$node->attrGroups,
31+
$node->getOriginalNode()->attrGroups,
3132
Attribute::TARGET_FUNCTION,
3233
'function',
3334
);

src/Rules/Functions/ClosureAttributesRule.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
use Attribute;
66
use PhpParser\Node;
77
use PHPStan\Analyser\Scope;
8+
use PHPStan\Node\InClosureNode;
89
use PHPStan\Rules\AttributesCheck;
910
use PHPStan\Rules\Rule;
1011

1112
/**
12-
* @implements Rule<Node\Expr\Closure>
13+
* @implements Rule<InClosureNode>
1314
*/
1415
final class ClosureAttributesRule implements Rule
1516
{
@@ -20,14 +21,14 @@ public function __construct(private AttributesCheck $attributesCheck)
2021

2122
public function getNodeType(): string
2223
{
23-
return Node\Expr\Closure::class;
24+
return InClosureNode::class;
2425
}
2526

2627
public function processNode(Node $node, Scope $scope): array
2728
{
2829
return $this->attributesCheck->check(
2930
$scope,
30-
$node->attrGroups,
31+
$node->getOriginalNode()->attrGroups,
3132
Attribute::TARGET_FUNCTION,
3233
'function',
3334
);

src/Rules/Functions/FunctionAttributesRule.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
use Attribute;
66
use PhpParser\Node;
77
use PHPStan\Analyser\Scope;
8+
use PHPStan\Node\InFunctionNode;
89
use PHPStan\Rules\AttributesCheck;
910
use PHPStan\Rules\Rule;
1011

1112
/**
12-
* @implements Rule<Node\Stmt\Function_>
13+
* @implements Rule<InFunctionNode>
1314
*/
1415
final class FunctionAttributesRule implements Rule
1516
{
@@ -20,14 +21,14 @@ public function __construct(private AttributesCheck $attributesCheck)
2021

2122
public function getNodeType(): string
2223
{
23-
return Node\Stmt\Function_::class;
24+
return InFunctionNode::class;
2425
}
2526

2627
public function processNode(Node $node, Scope $scope): array
2728
{
2829
return $this->attributesCheck->check(
2930
$scope,
30-
$node->attrGroups,
31+
$node->getOriginalNode()->attrGroups,
3132
Attribute::TARGET_FUNCTION,
3233
'function',
3334
);

src/Rules/Methods/MethodAttributesRule.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
use Attribute;
66
use PhpParser\Node;
77
use PHPStan\Analyser\Scope;
8+
use PHPStan\Node\InClassMethodNode;
89
use PHPStan\Rules\AttributesCheck;
910
use PHPStan\Rules\Rule;
1011

1112
/**
12-
* @implements Rule<Node\Stmt\ClassMethod>
13+
* @implements Rule<InClassMethodNode>
1314
*/
1415
final class MethodAttributesRule implements Rule
1516
{
@@ -20,14 +21,14 @@ public function __construct(private AttributesCheck $attributesCheck)
2021

2122
public function getNodeType(): string
2223
{
23-
return Node\Stmt\ClassMethod::class;
24+
return InClassMethodNode::class;
2425
}
2526

2627
public function processNode(Node $node, Scope $scope): array
2728
{
2829
return $this->attributesCheck->check(
2930
$scope,
30-
$node->attrGroups,
31+
$node->getOriginalNode()->attrGroups,
3132
Attribute::TARGET_METHOD,
3233
'method',
3334
);

0 commit comments

Comments
 (0)