Skip to content

Commit d9429f6

Browse files
committed
Fix build
1 parent b1ac906 commit d9429f6

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

src/Reflection/Doctrine/EntityRepositoryClassReflectionExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ public function hasMethod(\PHPStan\Reflection\ClassReflection $classReflection,
6565
return false;
6666
}
6767

68+
$classReflection = $entityClassType->getClassReflection();
69+
if ($classReflection === null) {
70+
return false;
71+
}
72+
6873
$fieldName = $this->classify($methodFieldName);
69-
$classMetadata = $objectManager->getClassMetadata($entityClassType->getClassName());
74+
$classMetadata = $objectManager->getClassMetadata($classReflection->getName());
7075

7176
return $classMetadata->hasField($fieldName) || $classMetadata->hasAssociation($fieldName);
7277
}

src/Rules/Doctrine/ORM/EntityNotFinalRule.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
7+
use PHPStan\Node\InClassNode;
78
use PHPStan\Rules\Rule;
89
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
910
use function sprintf;
1011

1112
/**
12-
* @implements Rule<Node\Stmt\Class_>
13+
* @implements Rule<InClassNode>
1314
*/
1415
class EntityNotFinalRule implements Rule
1516
{
@@ -24,12 +25,16 @@ public function __construct(ObjectMetadataResolver $objectMetadataResolver)
2425

2526
public function getNodeType(): string
2627
{
27-
return Node\Stmt\Class_::class;
28+
return InClassNode::class;
2829
}
2930

3031
public function processNode(Node $node, Scope $scope): array
3132
{
32-
if (! $node->isFinal()) {
33+
$classReflection = $scope->getClassReflection();
34+
if ($classReflection === null) {
35+
throw new \PHPStan\ShouldNotHappenException();
36+
}
37+
if (!$classReflection->isFinal()) {
3338
return [];
3439
}
3540

@@ -38,9 +43,8 @@ public function processNode(Node $node, Scope $scope): array
3843
return [];
3944
}
4045

41-
$className = (string) $node->namespacedName;
4246
try {
43-
if ($objectManager->getMetadataFactory()->isTransient($className)) {
47+
if ($objectManager->getMetadataFactory()->isTransient($classReflection->getName())) {
4448
return [];
4549
}
4650
} catch (\ReflectionException $e) {
@@ -49,7 +53,7 @@ public function processNode(Node $node, Scope $scope): array
4953

5054
return [sprintf(
5155
'Entity class %s is final which can cause problems with proxies.',
52-
$className
56+
$classReflection->getDisplayName()
5357
)];
5458
}
5559

src/Rules/Doctrine/ORM/PropertiesExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public function isAlwaysRead(PropertyReflection $property, string $propertyName)
2828
return $metadata->hasField($propertyName) || $metadata->hasAssociation($propertyName);
2929
}
3030

31+
/**
32+
* @param class-string $className
33+
*/
3134
private function findMetadata(string $className): ?\Doctrine\ORM\Mapping\ClassMetadataInfo
3235
{
3336
$objectManager = $this->objectMetadataResolver->getObjectManager();

src/Rules/Doctrine/ORM/RepositoryMethodCallRule.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ public function processNode(Node $node, Scope $scope): array
5858
if (!$entityClassType instanceof TypeWithClassName) {
5959
return [];
6060
}
61-
$entityClass = $entityClassType->getClassName();
61+
$entityClassReflection = $entityClassType->getClassReflection();
62+
if ($entityClassReflection === null) {
63+
return [];
64+
}
6265

6366
$methodNameIdentifier = $node->name;
6467
if (!$methodNameIdentifier instanceof Node\Identifier) {
@@ -79,7 +82,7 @@ public function processNode(Node $node, Scope $scope): array
7982
return [];
8083
}
8184

82-
$classMetadata = $objectManager->getClassMetadata($entityClass);
85+
$classMetadata = $objectManager->getClassMetadata($entityClassReflection->getName());
8386

8487
$messages = [];
8588
foreach ($argType->getKeyTypes() as $keyType) {
@@ -99,7 +102,7 @@ public function processNode(Node $node, Scope $scope): array
99102
'Call to method %s::%s() - entity %s does not have a field named $%s.',
100103
$calledOnType->describe(VerbosityLevel::typeOnly()),
101104
$methodName,
102-
$entityClass,
105+
$entityClassReflection->getDisplayName(),
103106
$fieldName
104107
);
105108
}

src/Type/Doctrine/ObjectMetadataResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getRepositoryClass(string $className): string
103103
return $this->getResolvedRepositoryClass();
104104
}
105105

106-
$metadata = $objectManager->getClassMetadata($className);
106+
$metadata = $objectManager->getClassMetadata($classReflection->getName());
107107

108108
$ormMetadataClass = 'Doctrine\ORM\Mapping\ClassMetadata';
109109
if ($metadata instanceof $ormMetadataClass) {

0 commit comments

Comments
 (0)