Skip to content

Commit 1ed9e62

Browse files
vranaondrejmirtes
authored andcommitted
Allow literal string dynamic property
1 parent 7493a9f commit 1ed9e62

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Rules/VariableVariables/VariablePropertyFetchRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public function processNode(Node $node, Scope $scope): array
4444
return [];
4545
}
4646

47+
if ($scope->getType($node->name)->isLiteralString()->yes()) {
48+
return [];
49+
}
50+
4751
$fetchedOnType = $scope->getType($node->var);
4852
foreach ($fetchedOnType->getObjectClassNames() as $referencedClass) {
4953
if (!$this->reflectionProvider->hasClass($referencedClass)) {

tests/Rules/VariableVariables/data/properties.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ class Bar extends stdClass
1515
}
1616

1717
function (stdClass $std, Foo $foo, Bar $bar) {
18-
$str = 'str';
18+
$str = sprintf('str%d', time());
1919

2020
$std->foo;
2121
$std->$str;
2222

2323
$foo->foo;
2424
$foo->$str;
25+
$foo->{'str'};
2526

2627
$bar->foo;
2728
$bar->$str;

0 commit comments

Comments
 (0)