erickskrauch / phpstan-yii2
Yii2 extension for PHPStan
Installs: 50 314
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 1
Forks: 6
Open Issues: 7
pkg:composer/erickskrauch/phpstan-yii2
Requires
- php: ^7.4 || ^8.0
 - nikic/php-parser: ^4 || ^5
 - phpstan/phpstan: ^2
 - yiisoft/yii2: ~2.0.36
 
Requires (Dev)
This package is auto-updated.
Last update: 2025-10-29 09:53:27 UTC
README
An extension for PHPStan providing types support and rules to work with the Yii2 framework. Hardfork of proget-hq/phpstan-yii2.
What does it do?
- 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\Configurableclass constructor. - Mark 
YII_*constants as dynamic. - Significantly improves support for 
ActiveRecordandActiveQuery. - 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$firstparameter. - Provides reflection extension for 
BaseObject's getters and setters. 
Installation
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
Configuration
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.