diff --git a/src/Reflection/RepositoryCountByMethodsClassReflectionExtension.php b/src/Reflection/RepositoryCountByMethodsClassReflectionExtension.php index 7232f6f..bb5209e 100644 --- a/src/Reflection/RepositoryCountByMethodsClassReflectionExtension.php +++ b/src/Reflection/RepositoryCountByMethodsClassReflectionExtension.php @@ -32,6 +32,10 @@ public function hasMethod(ClassReflection $classReflection, string $methodName): return false; } + if ($classReflection->isAbstract()) { + return false; + } + if (strpos($methodName, 'countBy') !== 0) { return false; } diff --git a/src/Reflection/RepositoryFindMethodsClassReflectionExtension.php b/src/Reflection/RepositoryFindMethodsClassReflectionExtension.php index 48f7371..0b9f62d 100644 --- a/src/Reflection/RepositoryFindMethodsClassReflectionExtension.php +++ b/src/Reflection/RepositoryFindMethodsClassReflectionExtension.php @@ -34,6 +34,10 @@ public function hasMethod(ClassReflection $classReflection, string $methodName): return false; } + if ($classReflection->isAbstract()) { + return false; + } + if (strpos($methodName, 'findOneBy') === 0) { $propertyName = lcfirst(substr($methodName, 9)); } elseif (strpos($methodName, 'findBy') === 0) { diff --git a/tests/Unit/Type/data/repository-stub-files.php b/tests/Unit/Type/data/repository-stub-files.php index 40a39b8..8fdada0 100644 --- a/tests/Unit/Type/data/repository-stub-files.php +++ b/tests/Unit/Type/data/repository-stub-files.php @@ -14,6 +14,14 @@ class MyModel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity } +class ExtendingMyAbstractModel extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity +{ + + /** @var string */ + protected $foo; + +} + namespace RepositoryStubFiles\My\Test\Extension\Domain\Repository; use function PHPStan\Testing\assertType; @@ -55,10 +63,51 @@ public function myTests(): void 'int', $this->countByFoo('a') ); + + // call findBy with non-existing model property + assertType( + '*ERROR*', + $this->findByNonexisting('a') + ); + assertType( + '*ERROR*', + $this->countByNonexisting('a') + ); + } + +} + +/** @extends \TYPO3\CMS\Extbase\Persistence\Repository<\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface> */ +abstract class MyAbstractModelRepository extends \TYPO3\CMS\Extbase\Persistence\Repository +{ + +} + +/** @template TEntityClass of \RepositoryStubFiles\My\Test\Extension\Domain\Model\ExtendingMyAbstractModel **/ +class ExtendingMyAbstractModelRepository extends MyAbstractModelRepository +{ + + public function myTests(): void + { + // call findBy with a non existing model property + assertType( + 'TYPO3\CMS\Extbase\Persistence\QueryResultInterface', + $this->findByFoo('a') + ); + // call findBy with a non existing model property + assertType( + '*ERROR*', + $this->findByNonexisting('a') + ); + assertType( + '*ERROR*', + $this->countByNonexisting('a') + ); } } + class MyModelWithoutExtends extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {