Skip to content

Commit 20c3dea

Browse files
fix: Add PHPStan extension installer instructions and improve ServiceMap configuration handling. (#26)
1 parent 83d26da commit 20c3dea

24 files changed

+580
-120
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Change Log
22

3-
## 0.2.3 Under development
3+
## 0.2.3 June 05, 2025
44

55
- Enh #25: Add support for PHPStan Extension Installer (@samuelrajan747)
6+
- Enh #26: Add PHPStan extension installer instructions and improve `ServiceMap` configuration handling.
67

78
## 0.2.2 June 04, 2025
89

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ parameters:
114114
config_path: %currentWorkingDirectory%/config/test.php
115115
```
116116

117-
**Note:** When you define `dynamicConstantNames` in your configuration, it **replaces** the extension's default
117+
**Note:** When you define `dynamicConstantNames` in your configuration, it **replaces** the extension's default
118118
constants.
119119
To maintain the `Yii2` constants recognition, you must include them explicitly along with your custom constants, as
120120
shown above.
@@ -156,9 +156,70 @@ parameters:
156156
config_path: %currentWorkingDirectory%/config/web.php
157157
```
158158

159+
### PHPstan extension installer
160+
161+
You can use the `phpstan-extension-installer` to automatically install this extension.
162+
163+
To do this, you need to add the following configuration to your `composer.json` file:
164+
165+
```shell
166+
composer require --dev phpstan/extension-installer
167+
```
168+
169+
or, add the following to your `composer.json`:
170+
171+
```json
172+
{
173+
"require-dev": {
174+
"phpstan/extension-installer": "^1.4"
175+
},
176+
"config": {
177+
"allow-plugins": {
178+
"phpstan/extension-installer": true
179+
}
180+
},
181+
}
182+
```
183+
184+
### Config `yii2` application for PHPStan
185+
186+
To configure the `yii2` application, you can use the `yii2` section in your `phpstan.neon` file:
187+
188+
```neon
189+
parameters:
190+
yii2:
191+
# Path to your `Yii2` configuration file
192+
config_path: %currentWorkingDirectory%/config/test.php
193+
```
194+
195+
`config/test.php` file should return an array with the application configuration, similar to the following:
196+
197+
```php
198+
<?php
199+
200+
declare(strict_types=1);
201+
202+
use yii2\extensions\localeurls\UrlLanguageManager;
203+
204+
return [
205+
'components' => [
206+
// custom component
207+
'helper' => [
208+
'class' => \yii2\extensions\helper\Helper::class,
209+
],
210+
// your component extended
211+
'urlManager' => [
212+
'class' => UrlLanguageManager::class,
213+
],
214+
],
215+
];
216+
```
217+
218+
219+
159220
## Quality code
160221

161-
[![phpstan-level](https://img.shields.io/badge/PHPStan%20level-9-blue)](https://github.com/yii2-extensions/phpstan/actions/workflows/static.yml)
222+
[![phpstan-level](https://img.shields.io/badge/PHPStan%20level-max-blue)](https://github.com/yii2-extensions/phpstan/actions/workflows/static.yml)
162223
[![style-ci](https://github.styleci.io/repos/701347895/shield?branch=main)](https://github.styleci.io/repos/701347895?branch=main)
163224

164225
## Testing

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ parameters:
1212
- '#Calling PHPStan\\Reflection\\Annotations\\AnnotationsPropertiesClassReflectionExtension\:\:(has|get)Property\(\) is not covered.+#'
1313
- '#Creating new PHPStan\\Reflection\\Dummy\\DummyPropertyReflection is not covered.+#'
1414

15-
level: 9
15+
level: max
1616

1717
paths:
1818
- src

0 commit comments

Comments
 (0)