Skip to content

Commit

Permalink
NodeScopeResolver: call nodeCallback for all attribute-related nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed May 20, 2022
1 parent 19a2b6b commit f85639d
Showing 1 changed file with 30 additions and 42 deletions.
72 changes: 30 additions & 42 deletions src/Analyser/NodeScopeResolver.php
Expand Up @@ -8,6 +8,7 @@
use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch;
Expand Down Expand Up @@ -395,13 +396,7 @@ private function processStmtNode(
} elseif ($stmt instanceof Node\Stmt\Function_) {
$hasYield = false;
$throwPoints = [];
foreach ($stmt->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
$this->processAttributeGroups($stmt->attrGroups, $scope, $nodeCallback);
[$templateTypeMap, $phpDocParameterTypes, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure] = $this->getPhpDocs($scope, $stmt);

foreach ($stmt->params as $param) {
Expand Down Expand Up @@ -456,13 +451,7 @@ private function processStmtNode(
} elseif ($stmt instanceof Node\Stmt\ClassMethod) {
$hasYield = false;
$throwPoints = [];
foreach ($stmt->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
$this->processAttributeGroups($stmt->attrGroups, $scope, $nodeCallback);
[$templateTypeMap, $phpDocParameterTypes, $phpDocReturnType, $phpDocThrowType, $deprecatedDescription, $isDeprecated, $isInternal, $isFinal, $isPure] = $this->getPhpDocs($scope, $stmt);

foreach ($stmt->params as $param) {
Expand Down Expand Up @@ -632,13 +621,7 @@ private function processStmtNode(
throw new ShouldNotHappenException();
}

foreach ($stmt->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$this->processExprNode($arg->value, $classScope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
$this->processAttributeGroups($stmt->attrGroups, $scope, $nodeCallback);

$classStatementsGatherer = new ClassStatementsGatherer($classReflection, $nodeCallback);
$this->processStmtNodes($stmt, $stmt->stmts, $classScope, $classStatementsGatherer);
Expand All @@ -649,13 +632,8 @@ private function processStmtNode(
} elseif ($stmt instanceof Node\Stmt\Property) {
$hasYield = false;
$throwPoints = [];
foreach ($stmt->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
$this->processAttributeGroups($stmt->attrGroups, $scope, $nodeCallback);

foreach ($stmt->props as $prop) {
$this->processStmtNode($prop, $scope, $nodeCallback);
[,,,,,,,,,$isReadOnly, $docComment] = $this->getPhpDocs($scope, $stmt);
Expand Down Expand Up @@ -1406,13 +1384,7 @@ private function processStmtNode(
$hasYield = false;
$throwPoints = [];
if ($stmt instanceof Node\Stmt\ClassConst) {
foreach ($stmt->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
$this->processAttributeGroups($stmt->attrGroups, $scope, $nodeCallback);
}
foreach ($stmt->consts as $const) {
$nodeCallback($const, $scope);
Expand Down Expand Up @@ -3108,13 +3080,7 @@ private function processParamNode(
callable $nodeCallback,
): void
{
foreach ($param->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
$this->processAttributeGroups($param->attrGroups, $scope, $nodeCallback);
$nodeCallback($param, $scope);
if ($param->type !== null) {
$nodeCallback($param->type, $scope);
Expand All @@ -3126,6 +3092,28 @@ private function processParamNode(
$this->processExprNode($param->default, $scope, $nodeCallback, ExpressionContext::createDeep());
}

/**
* @param AttributeGroup[] $attrGroups
* @param callable(Node $node, Scope $scope): void $nodeCallback
*/
private function processAttributeGroups(
array $attrGroups,
MutatingScope $scope,
callable $nodeCallback,
): void
{
foreach ($attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
$nodeCallback($arg, $scope);
}
$nodeCallback($attr, $scope);
}
$nodeCallback($attrGroup, $scope);
}
}

/**
* @param MethodReflection|FunctionReflection|null $calleeReflection
* @param Node\Arg[] $args
Expand Down

0 comments on commit f85639d

Please sign in to comment.