Skip to content

Commit

Permalink
Attributes rules use In*Node virtual nodes for more precise Scope
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 20, 2024
1 parent c5df243 commit 90e48fa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/Rules/Functions/ArrowFunctionAttributesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use Attribute;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InArrowFunctionNode;
use PHPStan\Rules\AttributesCheck;
use PHPStan\Rules\Rule;

/**
* @implements Rule<Node\Expr\ArrowFunction>
* @implements Rule<InArrowFunctionNode>
*/
final class ArrowFunctionAttributesRule implements Rule
{
Expand All @@ -20,14 +21,14 @@ public function __construct(private AttributesCheck $attributesCheck)

public function getNodeType(): string
{
return Node\Expr\ArrowFunction::class;
return InArrowFunctionNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
return $this->attributesCheck->check(
$scope,
$node->attrGroups,
$node->getOriginalNode()->attrGroups,
Attribute::TARGET_FUNCTION,
'function',
);
Expand Down
7 changes: 4 additions & 3 deletions src/Rules/Functions/ClosureAttributesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use Attribute;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClosureNode;
use PHPStan\Rules\AttributesCheck;
use PHPStan\Rules\Rule;

/**
* @implements Rule<Node\Expr\Closure>
* @implements Rule<InClosureNode>
*/
final class ClosureAttributesRule implements Rule
{
Expand All @@ -20,14 +21,14 @@ public function __construct(private AttributesCheck $attributesCheck)

public function getNodeType(): string
{
return Node\Expr\Closure::class;
return InClosureNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
return $this->attributesCheck->check(
$scope,
$node->attrGroups,
$node->getOriginalNode()->attrGroups,
Attribute::TARGET_FUNCTION,
'function',
);
Expand Down
7 changes: 4 additions & 3 deletions src/Rules/Functions/FunctionAttributesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use Attribute;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InFunctionNode;
use PHPStan\Rules\AttributesCheck;
use PHPStan\Rules\Rule;

/**
* @implements Rule<Node\Stmt\Function_>
* @implements Rule<InFunctionNode>
*/
final class FunctionAttributesRule implements Rule
{
Expand All @@ -20,14 +21,14 @@ public function __construct(private AttributesCheck $attributesCheck)

public function getNodeType(): string
{
return Node\Stmt\Function_::class;
return InFunctionNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
return $this->attributesCheck->check(
$scope,
$node->attrGroups,
$node->getOriginalNode()->attrGroups,
Attribute::TARGET_FUNCTION,
'function',
);
Expand Down
7 changes: 4 additions & 3 deletions src/Rules/Methods/MethodAttributesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use Attribute;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClassMethodNode;
use PHPStan\Rules\AttributesCheck;
use PHPStan\Rules\Rule;

/**
* @implements Rule<Node\Stmt\ClassMethod>
* @implements Rule<InClassMethodNode>
*/
final class MethodAttributesRule implements Rule
{
Expand All @@ -20,14 +21,14 @@ public function __construct(private AttributesCheck $attributesCheck)

public function getNodeType(): string
{
return Node\Stmt\ClassMethod::class;
return InClassMethodNode::class;
}

public function processNode(Node $node, Scope $scope): array
{
return $this->attributesCheck->check(
$scope,
$node->attrGroups,
$node->getOriginalNode()->attrGroups,
Attribute::TARGET_METHOD,
'method',
);
Expand Down

0 comments on commit 90e48fa

Please sign in to comment.