phpstan-typo3 icon indicating copy to clipboard operation
phpstan-typo3 copied to clipboard

Bug: Return type of Repository::createQuery

Open rvock opened this issue 1 year ago • 0 comments

I am getting an error when creating a custom repository with a createQuery method:

Return type (TYPO3\CMS\Extbase\Persistence\QueryInterface<TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface>) of method Example\Example\Domain\Repository\NewsRepository::createQuery()
should be compatible with return type (TYPO3\CMS\Extbase\Persistence\QueryInterface<object>)
of method TYPO3\CMS\Extbase\Persistence\RepositoryInterface<object>::createQuery()

My repository looks like this:

<?php
declare(strict_types = 1);

namespace Example\Example\Domain\Repository;

use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
use Example\Example\Domain\Model\News;

/**
 * @extends Repository<News>
 */
class NewsRepository extends Repository {
	public function createQuery(): QueryInterface {
		$query = parent::createQuery();
		$query->getQuerySettings()->setRespectStoragePage(false);
		return $query;
	}
}

I think, the Repository stub is not needed any more in TYPO3 v12. The default Extbase Repository also has a Template:

/**
 * The base repository - will usually be extended by a more concrete repository.
 * @template T of \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
 * @implements RepositoryInterface<T>
 */
class Repository implements RepositoryInterface, SingletonInterface

But PHPStan TYPO3 overwrites this with its own template:

/**
 * @template TEntityClass of \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
 */
class Repository

When I remove the stub, the PHPStan error disappears.

rvock avatar Jul 04 '24 12:07 rvock