@@ -18,8 +18,8 @@ parameters:
1818 paths:
1919 - src
2020
21- tmpDir: %currentWorkingDirectory%/runtime
22-
21+ tmpDir: %currentWorkingDirectory%/runtime
22+
2323 yii2:
2424 config_path: config/phpstan-config.php
2525```
@@ -38,7 +38,7 @@ parameters:
3838 - config/
3939 - runtime/
4040 - vendor/
41- - web/assets/
41+ - web/assets/
4242
4343 level: 6
4444
@@ -107,7 +107,7 @@ parameters:
107107 - commands
108108 - console
109109
110- tmpDir: %currentWorkingDirectory%/runtime
110+ tmpDir: %currentWorkingDirectory%/runtime
111111
112112 yii2:
113113 config_path: config/phpstan-console-config.php
@@ -167,14 +167,14 @@ return [
167167 'class' => \yii\db\Connection::class,
168168 'dsn' => 'mysql:host=localhost;dbname=test',
169169 ],
170-
170+
171171 // User component with identity class
172172 'user' => [
173173 'class' => \yii\web\User::class,
174174 'identityClass' => \app\models\User::class,
175175 'loginUrl' => ['/site/login'],
176176 ],
177-
177+
178178 // Mailer
179179 'mailer' => [
180180 'class' => \yii\symfonymailer\Mailer::class,
@@ -183,19 +183,19 @@ return [
183183 'host' => 'localhost',
184184 ],
185185 ],
186-
186+
187187 // Cache
188188 'cache' => [
189189 'class' => \yii\caching\FileCache::class,
190190 'cachePath' => '@runtime/cache',
191191 ],
192-
192+
193193 // Custom components
194194 'paymentService' => [
195195 'class' => \app\services\PaymentService::class,
196196 'apiKey' => 'test-key',
197197 ],
198-
198+
199199 // URL Manager
200200 'urlManager' => [
201201 'class' => \yii\web\UrlManager::class,
@@ -274,16 +274,16 @@ class UserController
274274 {
275275 // ✅ PHPStan knows this is User<app \models\User >
276276 $user = Yii::$app->user;
277-
277+
278278 // ✅ PHPStan knows identity is app\models\User
279279 $identity = $user->identity;
280-
280+
281281 // ✅ PHPStan knows this is Repository<app \models\User >
282282 $repository = Yii::$app->userRepository;
283-
283+
284284 // ✅ PHPStan knows this is Collection<app \models\Post >
285285 $collection = Yii::$app->postCollection;
286-
286+
287287 return $this->render('profile', ['user' => $identity]);
288288 }
289289}
@@ -304,24 +304,24 @@ use yii\base\Component;
304304
305305/**
306306 * Generic repository component.
307- *
307+ *
308308 * @template T of \yii\db\ActiveRecord
309309 */
310310class Repository extends Component
311311{
312- /**
312+ /**
313313 * @phpstan-var class-string<T >
314314 */
315315 public string $modelClass;
316-
316+
317317 /**
318318 * @phpstan-return T|null
319319 */
320320 public function findOne(int $id): \yii\db\ActiveRecord|null
321321 {
322322 return $this->modelClass::findOne($id);
323323 }
324-
324+
325325 /**
326326 * @phpstan-return T[]
327327 */
@@ -343,29 +343,29 @@ use yii\base\Component;
343343
344344/**
345345 * Generic collection component.
346- *
346+ *
347347 * @template T
348348 */
349349class Collection extends Component
350350{
351- /**
351+ /**
352352 * @phpstan-var class-string<T >
353353 */
354354 public string $elementType;
355-
356- /**
355+
356+ /**
357357 * @phpstan-var T[]
358358 */
359359 private array $items = [];
360-
360+
361361 /**
362362 * @phpstan-param T $item
363363 */
364364 public function add($item): void
365365 {
366366 $this->items[] = $item;
367367 }
368-
368+
369369 /**
370370 * @phpstan-return T[]
371371 */
@@ -438,19 +438,19 @@ return [
438438 // Interface to implementation mapping
439439 \Psr\Log\LoggerInterface::class => \Monolog\Logger::class,
440440 \app\contracts\PaymentInterface::class => \app\services\StripePayment::class,
441-
441+
442442 // Service definitions
443443 'logger' => [
444444 'class' => \Monolog\Logger::class,
445445 ['name' => 'app'],
446446 ],
447-
447+
448448 // Closure definitions
449449 'eventDispatcher' => function() {
450450 return new \app\services\EventDispatcher();
451451 },
452452 ],
453-
453+
454454 'singletons' => [
455455 // Singleton services
456456 \app\services\CacheManager::class => \app\services\CacheManager::class,
@@ -480,15 +480,15 @@ parameters:
480480 - vendor/
481481
482482 level: 8
483-
483+
484484 paths:
485485 - src
486486 - controllers
487487 - models
488488 - widgets
489489 - components
490490
491- tmpDir: %currentWorkingDirectory%/runtime
491+ tmpDir: %currentWorkingDirectory%/runtime
492492
493493 yii2:
494494 config_path: config/phpstan-config.php
@@ -502,7 +502,7 @@ parameters:
502502 reportAnyTypeWideningInVarTag: true
503503 reportPossiblyNonexistentConstantArrayOffset: true
504504 reportPossiblyNonexistentGeneralArrayOffset: true
505-
505+
506506 ignoreErrors:
507507 # Ignore specific errors
508508 - '#Call to an undefined method.*#'
@@ -512,7 +512,7 @@ parameters:
512512### Performance optimization
513513
514514``` neon
515- parameters:
515+ parameters:
516516 # Bootstrap optimization
517517 bootstrapFiles:
518518 - vendor/autoload.php
@@ -563,13 +563,15 @@ This will work with basic type inference but won't have custom component types.
563563For projects with both web and console applications:
564564
565565### Project structure
566+
566567``` text
567568phpstan-web.neon # Web-specific configuration
568569phpstan-console.neon # Console-specific configuration
569570phpstan.neon # Base configuration
570571```
571572
572573### Base configuration
574+
573575``` neon
574576# phpstan.neon
575577includes:
@@ -582,6 +584,7 @@ parameters:
582584```
583585
584586### Web configuration
587+
585588``` neon
586589# phpstan-web.neon
587590includes:
@@ -599,6 +602,7 @@ parameters:
599602```
600603
601604### Console configuration
605+
602606``` neon
603607# phpstan-console.neon
604608includes:
@@ -614,11 +618,12 @@ parameters:
614618```
615619
616620### Usage
621+
617622``` bash
618623# Analyze web application
619624vendor/bin/phpstan analyse -c phpstan-web.neon
620625
621- # Analyze console application
626+ # Analyze console application
622627vendor/bin/phpstan analyse -c phpstan-console.neon
623628```
624629
0 commit comments