Skip to content

Commit

Permalink
Process attribute arguments recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 20, 2021
1 parent 0837be4 commit 0cfeb1b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private function processStmtNode(
foreach ($stmt->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$nodeCallback($arg->value, $scope);
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
Expand Down Expand Up @@ -469,7 +469,7 @@ private function processStmtNode(
foreach ($stmt->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$nodeCallback($arg->value, $scope);
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
Expand Down Expand Up @@ -644,7 +644,7 @@ private function processStmtNode(
foreach ($stmt->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$nodeCallback($arg->value, $classScope);
$this->processExprNode($arg->value, $classScope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
Expand All @@ -660,7 +660,7 @@ private function processStmtNode(
foreach ($stmt->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$nodeCallback($arg->value, $scope);
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
Expand Down Expand Up @@ -1378,7 +1378,7 @@ private function processStmtNode(
foreach ($stmt->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$nodeCallback($arg->value, $scope);
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
Expand Down Expand Up @@ -3068,7 +3068,7 @@ private function processParamNode(
foreach ($param->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$nodeCallback($arg->value, $scope);
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@ public function testRule(): void
]);
}

public function testBug5651(): void
{
if (PHP_VERSION_ID < 80000 && !self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires PHP 8.0.');
}

$this->analyse([__DIR__ . '/data/bug-5651.php'], []);
}

}
30 changes: 30 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-5651.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Bug5651;

#[\Attribute]
class MyAttribute
{

/** @var string[] */
public $values;

/**
* @param string[] $values
*/
public function __construct(array $values)
{
$this->values = $values;
}
}

class HelloWorld
{
private const BAR = 'bar';

#[MyAttribute(['foo' => self::BAR])]
public function sayHello(): void
{

}
}

0 comments on commit 0cfeb1b

Please sign in to comment.