From 688a87f7036ad154b1e9d27be1e763872d30e7e1 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 7 Jun 2021 10:39:14 +0200 Subject: [PATCH] Turns out static property can be accessed on trait too https://github.com/phpstan/phpstan-src/commit/86c11d335debcfd926ec53213a11d19831891566 --- .../Properties/AccessStaticPropertiesRule.php | 11 ----------- .../AccessStaticPropertiesRuleTest.php | 5 +++++ .../PHPStan/Rules/Properties/data/bug-5143.php | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 tests/PHPStan/Rules/Properties/data/bug-5143.php diff --git a/src/Rules/Properties/AccessStaticPropertiesRule.php b/src/Rules/Properties/AccessStaticPropertiesRule.php index 4ae0bdf44f..4233156fdf 100644 --- a/src/Rules/Properties/AccessStaticPropertiesRule.php +++ b/src/Rules/Properties/AccessStaticPropertiesRule.php @@ -142,17 +142,6 @@ private function processSingleProperty(Scope $scope, StaticPropertyFetch $node, $classType = $scope->resolveTypeByName($node->class); } - - $classReflection = $classType->getClassReflection(); - if ($classReflection !== null && $classReflection->isTrait()) { - return [ - RuleErrorBuilder::message(sprintf( - 'Access to static property $%s on trait %s.', - $name, - $classReflection->getName() - ))->build(), - ]; - } } else { $classTypeResult = $this->ruleLevelHelper->findTypeToCheck( $scope, diff --git a/tests/PHPStan/Rules/Properties/AccessStaticPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/AccessStaticPropertiesRuleTest.php index 8d0736c71d..cf1b46e976 100644 --- a/tests/PHPStan/Rules/Properties/AccessStaticPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/AccessStaticPropertiesRuleTest.php @@ -186,4 +186,9 @@ public function testClassExists(): void $this->analyse([__DIR__ . '/data/static-properties-class-exists.php'], []); } + public function testBug5143(): void + { + $this->analyse([__DIR__ . '/data/bug-5143.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Properties/data/bug-5143.php b/tests/PHPStan/Rules/Properties/data/bug-5143.php new file mode 100644 index 0000000000..78c8572ee5 --- /dev/null +++ b/tests/PHPStan/Rules/Properties/data/bug-5143.php @@ -0,0 +1,18 @@ +