File tree Expand file tree Collapse file tree 2 files changed +84
-1
lines changed
tests/DoctrineIntegration/ORM Expand file tree Collapse file tree 2 files changed +84
-1
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,10 @@ final class EntityManagerIntegrationTest extends LevelsTestCase
1212 */
1313 public function dataTopics (): array
1414 {
15- return [['entityManagerDynamicReturn ' ]];
15+ return [
16+ ['entityManagerDynamicReturn ' ],
17+ ['entityRepositoryDynamicReturn ' ],
18+ ];
1619 }
1720
1821 public function getDataPath (): string
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \DoctrineIntegration \ORM \EntityRepositoryDynamicReturn ;
4+
5+ use Doctrine \ORM \EntityManagerInterface ;
6+ use Doctrine \ORM \EntityRepository ;
7+ use Doctrine \ORM \Mapping as ORM ;
8+ use RuntimeException ;
9+
10+ class Example
11+ {
12+ /**
13+ * @var EntityRepository
14+ */
15+ private $ repository ;
16+
17+ public function __construct (EntityManagerInterface $ entityManager )
18+ {
19+ $ this ->repository = $ entityManager ->getRepository (MyEntity::class);
20+ }
21+
22+ public function findDynamicType (): void
23+ {
24+ $ test = $ this ->repository ->find (1 );
25+
26+ if ($ test === null ) {
27+ throw new RuntimeException ('Sorry, but no... ' );
28+ }
29+
30+ $ test ->doSomething ();
31+ }
32+
33+ public function findOneByDynamicType (): void
34+ {
35+ $ test = $ this ->repository ->findOneBy (['blah ' => 'testing ' ]);
36+
37+ if ($ test === null ) {
38+ throw new RuntimeException ('Sorry, but no... ' );
39+ }
40+
41+ $ test ->doSomething ();
42+ }
43+
44+ public function findAllDynamicType (): void
45+ {
46+ $ items = $ this ->repository ->findAll ();
47+
48+ foreach ($ items as $ test ) {
49+ $ test ->doSomething ();
50+ }
51+ }
52+
53+ public function findByDynamicType (): void
54+ {
55+ $ items = $ this ->repository ->findBy (['blah ' => 'testing ' ]);
56+
57+ foreach ($ items as $ test ) {
58+ $ test ->doSomething ();
59+ }
60+ }
61+ }
62+
63+ /**
64+ * @ORM\Entity()
65+ */
66+ class MyEntity
67+ {
68+ /**
69+ * @ORM\Id()
70+ * @ORM\GeneratedValue()
71+ * @ORM\Column(type="integer")
72+ *
73+ * @var int
74+ */
75+ private $ id ;
76+
77+ public function doSomething (): void
78+ {
79+ }
80+ }
You can’t perform that action at this time.
0 commit comments