Skip to content

Commit 6433ebf

Browse files
authored
Merge pull request #9 from ebln/fix-self-static
Fix class name resolution for self & static
2 parents df3b0fc + 7fa30c2 commit 6433ebf

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/ForceFactoryRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private function getFactoriesFromAttributeByClass(\ReflectionClass $reflection):
161161
private function getClassNames(\PhpParser\Node $node, \PHPStan\Analyser\Scope $scope): array
162162
{
163163
if ($node->class instanceof \PhpParser\Node\Name) {
164-
return [[(string)$node->class, \true]];
164+
return [[$scope->resolveName($node->class), \true]];
165165
}
166166
if ($node->class instanceof \PhpParser\Node\Stmt\Class_) {
167167
$classNames = $scope->getType($node)->getObjectClassNames();

tests/dataAttrib/EmptyFactory.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@
66

77
use Test\Ebln\PHPStan\EnforceFactory\dataAttrib\code\EmptyProduct;
88

9-
class EmptyFactory
9+
final class EmptyFactory
1010
{
1111
public function class(): EmptyProduct
1212
{
1313
return new EmptyProduct();
1414
}
15+
16+
public static function createSelf(): self
17+
{
18+
return new self();
19+
}
20+
21+
public static function createStatic(): static
22+
{
23+
return new static();
24+
}
1525
}

tests/dataAttrib/code/FreeProduct.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66

77
class FreeProduct
88
{
9-
109
}

0 commit comments

Comments
 (0)