Skip to content

Commit b3f4ca1

Browse files
Merge pull request #141 from sascha-egerer/feature/do-not-try-to-find-model-for-abstract-repository
[BUGFIX] Do not try to find model for abstract repository
2 parents ebfc114 + a2359a3 commit b3f4ca1

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/Reflection/RepositoryCountByMethodsClassReflectionExtension.php

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
3232
return false;
3333
}
3434

35+
if ($classReflection->isAbstract()) {
36+
return false;
37+
}
38+
3539
if (strpos($methodName, 'countBy') !== 0) {
3640
return false;
3741
}

src/Reflection/RepositoryFindMethodsClassReflectionExtension.php

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
3434
return false;
3535
}
3636

37+
if ($classReflection->isAbstract()) {
38+
return false;
39+
}
40+
3741
if (strpos($methodName, 'findOneBy') === 0) {
3842
$propertyName = lcfirst(substr($methodName, 9));
3943
} elseif (strpos($methodName, 'findBy') === 0) {

tests/Unit/Type/data/repository-stub-files.php

+49
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ class MyModel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
1414

1515
}
1616

17+
class ExtendingMyAbstractModel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
18+
{
19+
20+
/** @var string */
21+
protected $foo;
22+
23+
}
24+
1725
namespace RepositoryStubFiles\My\Test\Extension\Domain\Repository;
1826

1927
use function PHPStan\Testing\assertType;
@@ -55,10 +63,51 @@ public function myTests(): void
5563
'int',
5664
$this->countByFoo('a')
5765
);
66+
67+
// call findBy with non-existing model property
68+
assertType(
69+
'*ERROR*',
70+
$this->findByNonexisting('a')
71+
);
72+
assertType(
73+
'*ERROR*',
74+
$this->countByNonexisting('a')
75+
);
76+
}
77+
78+
}
79+
80+
/** @extends \TYPO3\CMS\Extbase\Persistence\Repository<\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface> */
81+
abstract class MyAbstractModelRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
82+
{
83+
84+
}
85+
86+
/** @template TEntityClass of \RepositoryStubFiles\My\Test\Extension\Domain\Model\ExtendingMyAbstractModel **/
87+
class ExtendingMyAbstractModelRepository extends MyAbstractModelRepository
88+
{
89+
90+
public function myTests(): void
91+
{
92+
// call findBy with a non existing model property
93+
assertType(
94+
'TYPO3\CMS\Extbase\Persistence\QueryResultInterface<RepositoryStubFiles\My\Test\Extension\Domain\Model\ExtendingMyAbstractModel>',
95+
$this->findByFoo('a')
96+
);
97+
// call findBy with a non existing model property
98+
assertType(
99+
'*ERROR*',
100+
$this->findByNonexisting('a')
101+
);
102+
assertType(
103+
'*ERROR*',
104+
$this->countByNonexisting('a')
105+
);
58106
}
59107

60108
}
61109

110+
62111
class MyModelWithoutExtends extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
63112
{
64113

0 commit comments

Comments
 (0)