saschaegerer/phpstan-typo3
TYPO3 CMS class reflection extension for PHPStan
Maintainers
Package info
github.com/sascha-egerer/phpstan-typo3
Type:phpstan-extension
pkg:composer/saschaegerer/phpstan-typo3
Requires
- php: ^8.2
- ext-simplexml: *
- bnf/phpstan-psr-container: ^1.0
- composer/semver: ^3.4
- phpstan/phpstan: ^2.1.33
- ssch/typo3-debug-dump-pass: ^0.0.3
- typo3/cms-core: ^14.0
- typo3/cms-extbase: ^14.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.92
- php-parallel-lint/php-parallel-lint: ^1.4
- phpstan/phpstan-phpunit: ^2.0.3
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^11.5
- rector/rector: ^2.3
- rector/type-perfect: ^2.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT 6aa28e7088113b65f1e9d94e5202ddd2750c4f70
This package is auto-updated.
Last update: 2026-06-13 22:07:21 UTC
README
TYPO3 CMS class reflection extension for PHPStan & framework-specific rules.
This extension provides the following features (!!! not an exhaustive list !!!):
Dynamic Return Type Extensions
- Provides correct return type for
\TYPO3\CMS\Core\Context\Context->getAspect(). - Provides correct return type for
\TYPO3\CMS\Core\Context\DateTimeAspect->get(). - Provides correct return type for
\TYPO3\CMS\Core\Context\UserAspect->get(). - Provides correct return type for
\TYPO3\CMS\Extbase\Property\PropertyMapper->convert(). - Provides correct return type for
\TYPO3\CMS\Core\Utility\MathUtilitymethods likeisIntegerInRange. - Provides correct return type for
\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv(). - Provides correct return type for
\TYPO3\CMS\Extbase\Persistence\QueryInterface->execute(). - Provides correct return type for
\TYPO3\CMS\Extbase\Persistence\ObjectStoragemethods. - Provides correct return type for
\TYPO3\CMS\Core\Site\Entity\Site->getAttribute(). - Provides correct return type for
\Psr\Http\Message\ServerRequestInterface->getAttribute(). - Provides correct return type for
\TYPO3\CMS\Extbase\Validation\ValidatorResolver->createValidator(). - Uses under the hood bnf/phpstan-psr-container
All these dynamic return type extensions are necessary to teach PHPStan what type will be returned by the specific method call.
Framework specific rules
- Validates
\TYPO3\CMS\Core\Context\Context->getAspect()aspect names. - Validates
\Psr\Http\Message\ServerRequestInterface->getAttribute()attribute names. - Validates
\TYPO3\CMS\Core\Site\Entity\Site->getAttribute()attribute names. - Validates
\TYPO3\CMS\Extbase\Validation\ValidatorResolver->createValidator()required options. - Detects private service access via
\Psr\Container\ContainerInterface->get(). - Detects private service access via
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance().
Installation & Configuration
To use this extension, require it in Composer:
composer require --dev saschaegerer/phpstan-typo3
If you also install phpstan/extension-installer then you're all set!
Custom Context API Aspects
If you use custom aspects for the TYPO3 Context API you can add a mapping so PHPStan knows what type of aspect class is returned by the context API
parameters: typo3: contextApiGetAspectMapping: myCustomAspect: FlowdGmbh\MyProject\Context\MyCustomAspect
// PHPStan will now know that $myCustomAspect is of type FlowdGmbh\MyProject\Context\MyCustomAspect $myCustomAspect = GeneralUtility::makeInstance(Context::class)->getAspect('myCustomAspect');
Custom Request Attribute
If you use custom PSR-7 request attribute you can add a mapping so PHPStan knows what type of class is returned by Request::getAttribute()
parameters: typo3: requestGetAttributeMapping: myAttribute: FlowdGmbh\MyProject\Http\MyAttribute myNullableAttribute: FlowdGmbh\MyProject\Http\MyAttribute|null
// PHPStan will now know that $myAttribute is of type FlowdGmbh\MyProject\Http\MyAttribute $myAttribute = $request->getAttribute('myAttribute');
Custom Site Attribute
If you use custom attributes for the TYPO3 Site API you can add a mapping so PHPStan knows what type is returned by the site API
parameters: typo3: siteGetAttributeMapping: myArrayAttribute: array myIntAttribute: int myStringAttribute: string
$site = $this->request->getAttribute('site'); // PHPStan will now know that $myArrayAttribute is of type array<mixed, mixed> $myArrayAttribute = $site->getAttribute('myArrayAttribute'); // PHPStan will now know that $myIntAttribute is of type int $myIntAttribute = $site->getAttribute('myIntAttribute'); // PHPStan will now know that $myStringAttribute is of type string $myStringAttribute = $site->getAttribute('myStringAttribute');
Check for private Services
You have to provide a path to App_KernelDevelopmentDebugContainer.xml or similar XML file describing your container. This is generated by ssch/typo3-debug-dump-pass in your /var/cache/{TYPO3_CONTEXT}/ folder.
parameters: typo3: containerXmlPath: var/cache/development/App_KernelDevelopmentDebugContainer.xml
Development
Running Tests and Quality Checks
The following composer scripts are available for development:
| Command | Description |
|---|---|
composer test |
Run all quality checks (lint, cs, phpstan, phpunit) |
composer test:php-lint |
Run PHP syntax linting using parallel-lint |
composer test:php-cs |
Run code style checks using PHP_CodeSniffer |
composer test:phpstan |
Run static analysis using PHPStan |
composer test:phpunit |
Run PHPUnit tests |
composer fix:php-cs |
Fix code style issues using PHP Code Beautifier |
