File tree Expand file tree Collapse file tree
rules-tests/Bundle230/Rector/Class_/AddAnnotationToRepositoryRector/Fixture
rules/Bundle230/Rector/Class_ Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525 TypedPropertyFromToOneRelationTypeRector::class,
2626 CompleteReturnDocblockFromToManyRector::class,
2727
28- // annotations generics
28+ // @extends annotations service repository generics
2929 AddAnnotationToRepositoryRector::class,
3030 ]);
3131
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Doctrine \Tests \Bundle230 \Rector \Class_ \AddAnnotationToRepositoryRector \Fixture ;
4+
5+ use Doctrine \Bundle \MongoDBBundle \Repository \ServiceDocumentRepository ;
6+ use Doctrine \Persistence \ManagerRegistry ;
7+ use App \Entity \SomeEntity ;
8+
9+ final class SomeServiceDocumentRepository extends ServiceDocumentRepository
10+ {
11+ public function __construct (ManagerRegistry $ registry )
12+ {
13+ parent ::__construct ($ registry , SomeEntity::class);
14+ }
15+ }
16+
17+ ?>
18+ -----
19+ <?php
20+
21+ namespace Rector \Doctrine \Tests \Bundle230 \Rector \Class_ \AddAnnotationToRepositoryRector \Fixture ;
22+
23+ use Doctrine \Bundle \MongoDBBundle \Repository \ServiceDocumentRepository ;
24+ use Doctrine \Persistence \ManagerRegistry ;
25+ use App \Entity \SomeEntity ;
26+
27+ /**
28+ * @extends \Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository<\App\Entity\SomeEntity>
29+ */
30+ final class SomeServiceDocumentRepository extends ServiceDocumentRepository
31+ {
32+ public function __construct (ManagerRegistry $ registry )
33+ {
34+ parent ::__construct ($ registry , SomeEntity::class);
35+ }
36+ }
37+
38+ ?>
Original file line number Diff line number Diff line change @@ -37,9 +37,11 @@ public function __construct(
3737
3838 public function getRuleDefinition (): RuleDefinition
3939 {
40- return new RuleDefinition ('Add @extends ServiceEntityRepository<T> annotation to repository classes ' , [
41- new CodeSample (
42- <<<'CODE_SAMPLE'
40+ return new RuleDefinition (
41+ 'Add @extends ServiceEntityRepository<T> annotation to repository classes that extends ServiceEntityRepository or ServiceDocumentRepository ' ,
42+ [
43+ new CodeSample (
44+ <<<'CODE_SAMPLE'
4345use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
4446
4547final class SomeRepository extends ServiceEntityRepository
@@ -50,8 +52,8 @@ public function __construct(ManagerRegistry $registry)
5052 }
5153}
5254CODE_SAMPLE
53- ,
54- <<<'CODE_SAMPLE'
55+ ,
56+ <<<'CODE_SAMPLE'
5557use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
5658
5759/**
@@ -65,8 +67,10 @@ public function __construct(ManagerRegistry $registry)
6567 }
6668}
6769CODE_SAMPLE
68- ),
69- ]);
70+ ),
71+
72+ ]
73+ );
7074 }
7175
7276 /**
@@ -102,7 +106,11 @@ private function isRepositoryClass(Class_ $class): bool
102106 return false ;
103107 }
104108
105- return $ this ->isName ($ class ->extends , DoctrineClass::SERVICE_ENTITY_REPOSITORY );
109+ if ($ this ->isName ($ class ->extends , DoctrineClass::SERVICE_ENTITY_REPOSITORY )) {
110+ return true ;
111+ }
112+
113+ return $ this ->isName ($ class ->extends , DoctrineClass::SERVICE_DOCUMENT_REPOSITORY );
106114 }
107115
108116 private function getEntityClassFromConstructor (Class_ $ class ): ?string
You can’t perform that action at this time.
0 commit comments