diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index ba3be2994d0..9497c32fc8d 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -6,6 +6,7 @@ use Closure; use PhpParser\Comment\Doc; use PhpParser\Node; +use PhpParser\Node\AttributeGroup; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; @@ -379,13 +380,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) { @@ -440,13 +435,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) { @@ -615,13 +604,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); @@ -631,13 +614,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); $docComment = $stmt->getDocComment(); @@ -1387,13 +1365,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); @@ -3032,13 +3004,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); @@ -3050,6 +3016,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