From a624060bffaa182b05cacfe9e67b22169f359f5c Mon Sep 17 00:00:00 2001 From: Yohta Kimura Date: Thu, 21 Apr 2022 10:37:40 +0900 Subject: [PATCH] `Access to an undefined property` should be appropriate for these cases. Should be fixed by specifying types in isset. Related issue https://github.com/phpstan/phpstan/issues/3171 --- src/Rules/Properties/AccessPropertiesRule.php | 2 +- tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Rules/Properties/AccessPropertiesRule.php b/src/Rules/Properties/AccessPropertiesRule.php index 7c389eff86..55d2e237f2 100644 --- a/src/Rules/Properties/AccessPropertiesRule.php +++ b/src/Rules/Properties/AccessPropertiesRule.php @@ -79,7 +79,7 @@ private function processSingleProperty(Scope $scope, PropertyFetch $node, string return []; } - if ($type->canAccessProperties()->no() || $type->canAccessProperties()->maybe() && !$this->canAccessUndefinedProperties($scope, $node)) { + if ($type->canAccessProperties()->no() || $type->canAccessProperties()->maybe() && !$scope->isUndefinedExpressionAllowed($node)) { return [ RuleErrorBuilder::message(sprintf( 'Cannot access property $%s on %s.', diff --git a/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php index 902127910b..1ee7b1aec8 100644 --- a/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php @@ -495,7 +495,7 @@ public function testAccessPropertiesOnDynamicProperties(): void 299, ], [ - 'Cannot access property $foo on TestAccessProperties\PropertyIssetOnPossibleFalse|false.', + 'Access to an undefined property TestAccessProperties\PropertyIssetOnPossibleFalse|false::$foo.', 315, ], [ @@ -511,7 +511,7 @@ public function testAccessPropertiesOnDynamicProperties(): void 402, ], [ - 'Cannot access property $array on stdClass|null.', + 'Access to an undefined property stdClass|null::$array.', 412, ], ],