friendsoftypo3 / phpstan-typo3
TYPO3 rules for PHPStan
Installs: 499 361
Dependents: 80
Suggesters: 0
Security: 0
Stars: 17
Watchers: 10
Forks: 7
Open Issues: 0
Type:phpstan-extension
Requires
- php: ^7.2 || ^8.0 || ^8.1
- phpstan/phpstan: ^0.12.99 || ^1.2.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.3
- jangregor/phpstan-prophecy: ^0.6.2
- phpunit/phpunit: ^8.5
- symplify/easy-coding-standard: ^7.2
- typo3/cms-core: ^10.4 || 11.*.*@dev
- typo3/cms-extbase: ^10.4 || 11.*.*@dev
This package is auto-updated.
Last update: 2024-11-19 14:22:54 UTC
README
Note
friendsoftypo3/phpstan-typo3
is obsolete and has been retired.
The package dependency should be removed from TYPO3 project or extension development: composer rem --dev friendsoftypo3/phpstan-typo3
.
See below for transition options.
Migrating away from friendsoftypo3/phpstan-typo3 since TYPO3 core v12
Switch to saschaegerer/phpstan-typo3
Sascha's package saschaegerer/phpstan-typo3 can be an alternative.
Remove package and rely on core annotations
- The list of global TYPO3 specific constants shrunk over time and phpstan finds more of the remaining ones by default.
phpstan may mumble about constants
LF
andCR
not being defined. They can be made known to phpstan like this in aphpstan.neon
config file:
Fileparameters: bootstrapFiles: - phpstan.bootstrap.php
phpstan.bootstrap.php
then contains:<?php define('LF', chr(10)); define('CR', chr(13));
GeneralUtility::makeInstance()
,Context->getAspect()
,Query->execute()
andQueryInterface->execute()
have proper method annotations since TYPO3 v12, the phpstan extension classes are not needed anymore and phpstan "understands" return values of these methods out of the box.ObjectManagerInterface->get()
andObjectManager->get()
extensions have been removed from TYPO3 since v12 and are thus obsolete.
TYPO3 CMS class reflection extension for PHPStan & framework-specific rules
This extension provides the following features:
- Provides correct return type for
\TYPO3\CMS\Core\Context\Context->getAspect()
. - Provides correct return type for
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance()
. - Provides correct return type for
\TYPO3\CMS\Extbase\Object\ObjectManagerInterface->get()
. - Provides correct return type for
\TYPO3\CMS\Extbase\Object\ObjectManager->get()
. - Provides correct return type for
\TYPO3\CMS\Extbase\Persistence\Generic\Query->execute()
. - Provides correct return type for
\TYPO3\CMS\Extbase\Persistence\QueryInterface->execute()
.
Details on GeneralUtility::makeInstance()
Dynamic return types are returned for:
GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class)
GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler')
GeneralUtility::makeInstance(self::class)
GeneralUtility::makeInstance(static::class)
Details on ObjectManagerInterface::get() and ObjectManager::get()
Dynamic return types are returned for:
ObjectManager->get(\TYPO3\CMS\Core\DataHandling\DataHandler::class)
ObjectManager->get('TYPO3\\CMS\\Core\\DataHandling\\DataHandler')
ObjectManager->get(self::class)
ObjectManager->get(static::class)
Installation & Configuration
To use this extension, require it in Composer:
composer require friendsoftypo3/phpstan-typo3 --dev
Once installed, put this into your phpstan.neon
config:
includes:
- vendor/friendsoftypo3/phpstan-typo3/extension.neon
FAQ
I found this extension and the one from Sascha (
saschaegerer/phpstan-typo3
). Why are there two extensions and which should I use?
Well, this package has one specific purpose. It's made to help making the TYPO3 core phpstan max level compatible. To achieve this, the core team needs to be able to have its own extension which can be quickly adjusted as soon as the core itself changes. If for example, a new core version is released, the core team can quickly raise the dependency constraints for typo3/cms-core
and typo3/cms-extbase
which cannot be done when working with Sascha's package.
Also, Sascha's package contains dynamic return type providers that are not needed (yet) to make the core more compatible with phpstan.
To sum it all up: There is no competition between both extensions and this extension should not be used by users but only by the TYPO3 core.