diff --git a/src/Rules/VariableVariables/VariablePropertyFetchRule.php b/src/Rules/VariableVariables/VariablePropertyFetchRule.php index 760bff6..44fc32e 100644 --- a/src/Rules/VariableVariables/VariablePropertyFetchRule.php +++ b/src/Rules/VariableVariables/VariablePropertyFetchRule.php @@ -44,6 +44,10 @@ public function processNode(Node $node, Scope $scope): array return []; } + if ($scope->getType($node->name)->isLiteralString()->yes()) { + return []; + } + $fetchedOnType = $scope->getType($node->var); foreach ($fetchedOnType->getObjectClassNames() as $referencedClass) { if (!$this->reflectionProvider->hasClass($referencedClass)) { diff --git a/tests/Rules/VariableVariables/data/properties.php b/tests/Rules/VariableVariables/data/properties.php index 703b94e..a0bfc88 100644 --- a/tests/Rules/VariableVariables/data/properties.php +++ b/tests/Rules/VariableVariables/data/properties.php @@ -15,13 +15,14 @@ class Bar extends stdClass } function (stdClass $std, Foo $foo, Bar $bar) { - $str = 'str'; + $str = sprintf('str%d', time()); $std->foo; $std->$str; $foo->foo; $foo->$str; + $foo->{'str'}; $bar->foo; $bar->$str;