A PHPStan package that supports working with Extbase

Fund package maintenance!

Installs: 1 414

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 4

Forks: 1

Open Issues: 1


0.1.1 2021-10-07 08:49 UTC

This package is auto-updated.

Last update: 2024-07-07 15:41:28 UTC


PHPStan for Extbase

This package provides a couple of stubs and services to make your life easier when working with PHPStan and Extbase.


class Item extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {}

 * @template TEntityClass of Item
 * @template-extends Repository<TEntityClass>
class ItemRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {}

class ItemController
    private ItemRepository $itemRepository;

    public function listAction()
        # this call does not longer generate a "call getFirst() on array" error

        # PHPStan does now understand that this is a collection of Item classes.
        # This is made possible with @template and @template-extends annotations on your repositories
        $items = $this->itemRepository->findAll();

        foreach($this->itemRepository->findAll() as $item) {
            # PHPStan does now know that $item is an instance of Item which does not have method getFoo() defined.

        # PHPStan does now know that $item can be null
        $item = $this->itemRepository->findByUid(1);

        #PHPStan does no longer report an error for such comparisons due to the former detection
        if ($item !== null) {

        # PHPStan understands that $query deals with Item objects
        $query = $this->itemRepository->createQuery();

        # PHPStan does now know that execute returns a QueryResult<Item> with the argument set to false.
        $queryResult = $query->execute(false);

        # PHPStan does now know that execute returns an array of arrays (array<int,array<string,mixed>>) with the argument set to true.
        $array = $query->execute(true);


composer require schnitzler/phpstan-typo3-extbase
# phpstan.neon

	- vendor/schnitzler/phpstan-typo3-extbase/extension.neon

Why yet another package?

Well, that's because it's easier for me to work on it with my own pace. Also, this package is not feature complete yet. I am in contact and will continue to be with other package maintainers and maybe there will once be just one package for all TYPO3 needs. But for now, this is the way to go.