A PHPStan package that supports working with Extbase

Overview

PHPStan for Extbase

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

Examples

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
        $this->itemRepository->findAll()->getFirst();

        # 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.
            $item->getFoo();
        }

        # 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);
    }
}

Installation

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

includes:
	- 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.

You might also like...
Various PHPStan rules we found useful in ShipMonk.

ShipMonk PHPStan rules Various rules we found useful in ShipMonk. You may found some of them opinionated, so we recommend picking only those fitting y

PHPStan extension for sealed classes and interfaces.

Sealed classes with PHPStan This extension adds support for sealed classes and interfaces to PHPStan. Installation To use this extension, require it v

Extension for PHPStan to allow analysis of Drupal code.
Extension for PHPStan to allow analysis of Drupal code.

phpstan-drupal Extension for PHPStan to allow analysis of Drupal code. Sponsors Would you like to sponsor? Usage When you are using phpstan/extension-

Repository containing all the PHPStan rules from the book
Repository containing all the PHPStan rules from the book "Recipes for Decoupling"

PHPStan rules from the book "Recipes for Decoupling" by Matthias Noback In the book "Recipes for Decoupling" we discuss how to decouple from web and C

WordPress extensions for PHPStan ⛏️

WordPress extensions for PHPStan Static analysis for the WordPress ecosystem. PHPStan WordPress Installation Add this package to your project. compose

Perform static analysis of Drupal PHP code with phpstan-drupal.

Perform static analysis of Drupal PHP code with PHPStan and PHPStan-Drupal on Drupal using PHP 8. For example: docker run --rm \ -v $(pwd)/example01

A set of utilities for working with vk api!

vk-utils Документация на русском языке Installation composer require labile/vk-utils How to use it? Simple example use Astaroth\VkUtils\Client; $api

A plugin for working with popular money libraries in Pest

This package is a plugin for Pest PHP. It allows you to write tests against monetary values provided by either brick/money or moneyphp/money using the same declarative syntax you're used to with Pest's expectation syntax.

Iran decoration platform is an open source Php web application where you can find your job as a freelancer working in people home in decoration positions and others.

Iran-Decoration Platform Iran decoration platform is an open source Php web application where you can find your job as a freelancer working in people

Owner
Alexander Schnitzler
Plugin Framework Component merger @TYPO3. TYPO3 and symfony freelancer.
Alexander Schnitzler
Strings Package provide a fluent, object-oriented interface for working with multibyte string

Strings Package provide a fluent, object-oriented interface for working with multibyte string, allowing you to chain multiple string operations together using a more readable syntax compared to traditional PHP strings functions.

Glowy PHP 14 Mar 12, 2022
PHPStan extension to support #[Readonly] constructor properties

icanhazstring/phpstan-readonly-property Support #[Readonly] promoted constructor properties for PHPStan. This library is used to have a full transitio

Andreas Frömer 4 Apr 5, 2022
Analyzes PHPStan baseline files and creates aggregated error trend-reports

Analyzes phpstan baseline files Analyzes PHPStan baseline files and creates aggregated error trend-reports.

Markus Staab 22 Dec 23, 2022
Magento specific extension for phpstan

bitexpert/phpstan-magento This package provides some additional features for PHPStan to make it work for Magento 2 projects. Installation The preferre

bitExpert AG 92 Dec 7, 2022
Sandbox project for the PHPStan workshop

Sandbox project for a PHPStan workshop Installation Requirements Docker Engine Docker Compose Git Bash Getting started Clone this repository (git clon

Matthias Noback 4 Oct 17, 2022
Custom PHPStan rules

phpstan-rules Provides additional rules for phpstan/phpstan. Installation Run $ composer require --dev alister/phpstan-rules Usage All of the rules pr

Alister Bulman 1 Nov 4, 2021
The main scope of this extension is to help phpstan to detect the type of object after the Assert\Assertion validation.

PHPStan beberlei/assert extension PHPStan beberlei/assert Description The main scope of this extension is to help phpstan to detect the type of object

PHPStan 33 Jan 2, 2023
Doctrine extensions for PHPStan

Doctrine extensions for PHPStan PHPStan Doctrine This extension provides following features: DQL validation for parse errors, unknown entity classes a

PHPStan 478 Jan 3, 2023
PHPStan extension for webmozart/assert

PHPStan webmozart/assert extension PHPStan webmozart/assert Description The main scope of this extension is to help phpstan to detect the type of obje

PHPStan 139 Dec 22, 2022
An extension for PHPStan for adding analysis for PHP Language Extensions.

PHPStan PHP Language Extensions (currently in BETA) This is an extension for PHPStan for adding analysis for PHP Language Extensions. Language feature

Dave Liddament 9 Nov 30, 2022