Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Return type of Repository::createQuery #164

Open
rvock opened this issue Jul 4, 2024 · 0 comments
Open

Bug: Return type of Repository::createQuery #164

rvock opened this issue Jul 4, 2024 · 0 comments

Comments

@rvock
Copy link

rvock commented Jul 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant