Skip to content

Bug: Return type of Repository::createQuery #164

@rvock

Description

@rvock

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions