Skip to content

Commit

Permalink
Turns out static property can be accessed on trait too
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 7, 2021
1 parent 10a833f commit 688a87f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
11 changes: 0 additions & 11 deletions src/Rules/Properties/AccessStaticPropertiesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'], []);
}

}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Properties/data/bug-5143.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Bug5143;

trait Foo
{
public static $property = 0;
}

class Bar
{

public function doFoo(): void
{
echo Foo::$property;
}

}

0 comments on commit 688a87f

Please sign in to comment.