Skip to content

Commit 351c091

Browse files
authored
Doctrine: support EntityRepository constructor (#90)
1 parent 78754dc commit 351c091

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Provider/DoctrineEntrypointProvider.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function isEntrypointMethod(ReflectionMethod $method): bool
3434
|| $this->hasAttribute($method, 'Doctrine\ORM\Mapping\PrePersist')
3535
|| $this->hasAttribute($method, 'Doctrine\ORM\Mapping\PreRemove')
3636
|| $this->hasAttribute($method, 'Doctrine\ORM\Mapping\PreUpdate')
37+
|| $this->isEntityRepositoryConstructor($class, $method)
3738
|| $this->isPartOfAsEntityListener($class, $methodName)
3839
|| $this->isProbablyDoctrineListener($methodName);
3940
}
@@ -88,6 +89,18 @@ private function isPartOfAsEntityListener(ReflectionClass $class, string $method
8889
return false;
8990
}
9091

92+
/**
93+
* @param ReflectionClass<object> $class
94+
*/
95+
private function isEntityRepositoryConstructor(ReflectionClass $class, ReflectionMethod $method): bool
96+
{
97+
if (!$method->isConstructor()) {
98+
return false;
99+
}
100+
101+
return $class->isSubclassOf('Doctrine\ORM\EntityRepository');
102+
}
103+
91104
private function isDoctrineInstalled(): bool
92105
{
93106
return InstalledVersions::isInstalled('doctrine/orm')

tests/Rule/data/DeadMethodRule/providers/doctrine.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
namespace Doctrine;
44

5+
use Doctrine\ORM\EntityManagerInterface;
6+
use Doctrine\ORM\EntityRepository;
7+
use Doctrine\ORM\Mapping\ClassMetadata;
8+
59
class MyEntity
610
{
711

@@ -20,6 +24,17 @@ public function postPersist(): void {}
2024

2125
}
2226

27+
class FooRepository extends EntityRepository {
28+
29+
public function __construct(
30+
EntityManagerInterface $em,
31+
ClassMetadata $class
32+
) {
33+
parent::__construct($em, $class);
34+
}
35+
36+
}
37+
2338
class OldListenerHeuristics {
2439

2540
public function postUpdate(): void {}

0 commit comments

Comments
 (0)