An extension for PHPStan providing types support and rules to work with the Yii2 framework. Hardfork of proget-hq/phpstan-yii2.
- Provides stub files for better analysis of array shapes.
- Provide array shape analyse for
Yii:createObject()
. - Provide analyse for the last array argument of the
yii\base\Configurable
class constructor. - Mark
YII_*
constants as dynamic. - Significantly improves support for
ActiveRecord
andActiveQuery
. - Provides correct return type for
Yii::$container->get('service_id')
method. - Provides correct return type for
Yii::$app->request->headers->get('authorization')
method based on the$first
parameter. - Provides reflection extension for
BaseObject
's getters and setters.
To use this extension, require it in Composer:
composer require --dev erickskrauch/phpstan-yii2
If you also install phpstan/extension-installer then you're all set!
Manual installation
If you don't want to use phpstan/extension-installer
, include extension.neon
in your project's PHPStan config:
includes:
- vendor/erickskrauch/phpstan-yii2/extension.neon
- vendor/erickskrauch/phpstan-yii2/rules.neon
You have to provide the path to the configuration file for your application. For Advanced project template your path might look like this:
parameters:
yii2:
config_path: common/config/main.php
You may want to create a separate configuration file for PHPStan describing the services available throughout the application. But usually, common
is sufficient, because it contains all the services universally available in any module of the application.