Skip to content

Commit 0cfeb1b

Browse files
committed
Process attribute arguments recursively
1 parent 0837be4 commit 0cfeb1b

3 files changed

Lines changed: 45 additions & 6 deletions

File tree

src/Analyser/NodeScopeResolver.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private function processStmtNode(
408408
foreach ($stmt->attrGroups as $attrGroup) {
409409
foreach ($attrGroup->attrs as $attr) {
410410
foreach ($attr->args as $arg) {
411-
$nodeCallback($arg->value, $scope);
411+
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
412412
}
413413
}
414414
}
@@ -469,7 +469,7 @@ private function processStmtNode(
469469
foreach ($stmt->attrGroups as $attrGroup) {
470470
foreach ($attrGroup->attrs as $attr) {
471471
foreach ($attr->args as $arg) {
472-
$nodeCallback($arg->value, $scope);
472+
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
473473
}
474474
}
475475
}
@@ -644,7 +644,7 @@ private function processStmtNode(
644644
foreach ($stmt->attrGroups as $attrGroup) {
645645
foreach ($attrGroup->attrs as $attr) {
646646
foreach ($attr->args as $arg) {
647-
$nodeCallback($arg->value, $classScope);
647+
$this->processExprNode($arg->value, $classScope, $nodeCallback, ExpressionContext::createDeep());
648648
}
649649
}
650650
}
@@ -660,7 +660,7 @@ private function processStmtNode(
660660
foreach ($stmt->attrGroups as $attrGroup) {
661661
foreach ($attrGroup->attrs as $attr) {
662662
foreach ($attr->args as $arg) {
663-
$nodeCallback($arg->value, $scope);
663+
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
664664
}
665665
}
666666
}
@@ -1378,7 +1378,7 @@ private function processStmtNode(
13781378
foreach ($stmt->attrGroups as $attrGroup) {
13791379
foreach ($attrGroup->attrs as $attr) {
13801380
foreach ($attr->args as $arg) {
1381-
$nodeCallback($arg->value, $scope);
1381+
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
13821382
}
13831383
}
13841384
}
@@ -3068,7 +3068,7 @@ private function processParamNode(
30683068
foreach ($param->attrGroups as $attrGroup) {
30693069
foreach ($attrGroup->attrs as $attr) {
30703070
foreach ($attr->args as $arg) {
3071-
$nodeCallback($arg->value, $scope);
3071+
$this->processExprNode($arg->value, $scope, $nodeCallback, ExpressionContext::createDeep());
30723072
}
30733073
}
30743074
}

tests/PHPStan/Rules/DeadCode/UnusedPrivateConstantRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,13 @@ public function testRule(): void
4646
]);
4747
}
4848

49+
public function testBug5651(): void
50+
{
51+
if (PHP_VERSION_ID < 80000 && !self::$useStaticReflectionProvider) {
52+
$this->markTestSkipped('Test requires PHP 8.0.');
53+
}
54+
55+
$this->analyse([__DIR__ . '/data/bug-5651.php'], []);
56+
}
57+
4958
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Bug5651;
4+
5+
#[\Attribute]
6+
class MyAttribute
7+
{
8+
9+
/** @var string[] */
10+
public $values;
11+
12+
/**
13+
* @param string[] $values
14+
*/
15+
public function __construct(array $values)
16+
{
17+
$this->values = $values;
18+
}
19+
}
20+
21+
class HelloWorld
22+
{
23+
private const BAR = 'bar';
24+
25+
#[MyAttribute(['foo' => self::BAR])]
26+
public function sayHello(): void
27+
{
28+
29+
}
30+
}

0 commit comments

Comments
 (0)