saschaegerer / phpstan-typo3
TYPO3 CMS class reflection extension for PHPStan
Fund package maintenance!
sascha-egerer
Liberapay
Installs: 757 775
Dependents: 120
Suggesters: 0
Security: 0
Stars: 34
Watchers: 6
Forks: 17
Open Issues: 3
Type:phpstan-extension
Requires
- php: ^7.2 || ^8.0
- bnf/phpstan-psr-container: ^1.0
- nikic/php-parser: ^4.15.1
- phpstan/phpstan: ^1.8.9
- typo3/cms-core: ^10.4 || ^11.5 || ^12.0
- typo3/cms-extbase: ^10.4 || ^11.5 || ^12.0
Requires (Dev)
- consistence-community/coding-standard: ^3.10.1
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.2
- phing/phing: ^2.17.4
- php-parallel-lint/php-parallel-lint: ^1.3.2
- phpstan/phpstan-strict-rules: ^1.4.4
- phpunit/phpunit: ^8.5.30
- slevomat/coding-standard: ^6.4.1
- symfony/polyfill-php80: ^1.26.0
This package is auto-updated.
Last update: 2023-01-30 09:11:23 UTC
README
TYPO3 CMS class reflection extension for PHPStan & framework-specific rules
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!
Manual installation
If you don't want to use phpstan/extension-installer
, put this into your phpstan.neon config:
includes: - vendor/saschaegerer/phpstan-typo3/extension.neon
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');