@@ -32,7 +32,7 @@ The preferred way to install this extension is through [composer](https://getcom
3232
3333Either run
3434
35- ``` shel
35+ ``` shell
3636composer require --dev --prefer-dist yii2-extensions/phpstan:^0.2
3737```
3838
@@ -44,33 +44,119 @@ or add
4444
4545## Usage
4646
47+ This extension provides enhanced static analysis for ` Yii2 ` applications by adding:
48+
49+ - ** Container service resolution** with proper type inference.
50+ - ** Dynamic method return types** for ` ActiveRecord ` and ` ActiveQuery ` .
51+ - ** Header collection dynamic methods** support.
52+ - ** Property reflection extensions** for ` Application ` , ` Request ` , ` Response ` , and ` User ` components.
53+ - ** Service map integration** for dependency injection analysis.
54+
55+ ### Basic Configuration
56+
4757To use this extension, you need to add the following configuration to your ` phpstan.neon ` file:
4858
4959``` neon
5060includes:
51- - vendor/yii2-extensions/phpstan/extension.neon
61+ - vendor/yii2-extensions/phpstan/extension.neon
5262
5363parameters:
5464 bootstrapFiles:
5565 - tests/bootstrap.php
5666
57- dynamicConstantNames:
58- - YII_DEBUG
59- - YII_ENV
60-
6167 level: 5
6268
6369 paths:
6470 - src
6571
66- scanFiles:
67- - vendor/yiisoft/yii2/Yii.php
72+ # Exclude paths from analysis
73+ excludePaths:
74+ - c3.php
75+ - requirements.php
76+ - config
77+ - tests
78+ - vendor
6879
6980 yii2:
70- # Path to your Yii2 configuration file
81+ # Path to your `Yii2` configuration file (optional)
82+ # If not provided or empty, will work without explicit configuration
7183 config_path: %currentWorkingDirectory%/config/test.php
7284```
7385
86+ ### Dynamic Constants Configuration
87+
88+ The extension automatically recognizes common ` Yii2 ` dynamic constants:
89+
90+ - ` YII_DEBUG `
91+ - ` YII_ENV `
92+ - ` YII_ENV_DEV `
93+ - ` YII_ENV_PROD `
94+ - ` YII_ENV_TEST `
95+
96+ If you need to add additional dynamic constants, you can extend the configuration:
97+
98+ ``` neon
99+ includes:
100+ - vendor/yii2-extensions/phpstan/extension.neon
101+
102+ parameters:
103+ # Your existing dynamic constants will be merged with the extension's defaults
104+ dynamicConstantNames:
105+ - YII_DEBUG # Already included by the extension
106+ - YII_ENV # Already included by the extension
107+ - YII_ENV_DEV # Already included by the extension
108+ - YII_ENV_PROD # Already included by the extension
109+ - YII_ENV_TEST # Already included by the extension
110+ - MY_CUSTOM_CONSTANT
111+ - ANOTHER_CONSTANT
112+
113+ yii2:
114+ config_path: %currentWorkingDirectory%/config/test.php
115+ ```
116+
117+ ** Note:** When you define ` dynamicConstantNames ` in your configuration, it ** replaces** the extension's default
118+ constants.
119+ To maintain the ` Yii2 ` constants recognition, you must include them explicitly along with your custom constants, as
120+ shown above.
121+
122+ ### Advanced Configuration Example
123+
124+ ``` neon
125+ includes:
126+ - vendor/yii2-extensions/phpstan/extension.neon
127+
128+ parameters:
129+ level: 8
130+
131+ paths:
132+ - src
133+ - controllers
134+ - models
135+ - widgets
136+
137+ excludePaths:
138+ - src/legacy
139+ - tests/_support
140+ - vendor
141+
142+ bootstrapFiles:
143+ - config/bootstrap.php
144+ - tests/bootstrap.php
145+
146+ # Complete dynamic constants list (extension defaults + custom)
147+ dynamicConstantNames:
148+ - YII_DEBUG
149+ - YII_ENV
150+ - YII_ENV_DEV
151+ - YII_ENV_PROD
152+ - YII_ENV_TEST
153+ - APP_VERSION
154+ - MAINTENANCE_MODE
155+
156+ yii2:
157+ config_path: %currentWorkingDirectory%/config/web.php
158+ ```
159+
74160## Quality code
75161
76162[ ![ phpstan-level] ( https://img.shields.io/badge/PHPStan%20level-9-blue )] ( https://github.com/yii2-extensions/phpstan/actions/workflows/static.yml )
0 commit comments