I have a project (PHP 8.2.6, Yii2, PHPStan). After running phpstan command, I got a list of errors that should be fixed for successful checking. Example of errors:
- Access to an undefined property
yii\base\Application::$request
. - Access to an undefined property
yii\base\Application::$response
.
This errors caused because of use such code:
Yii::$app->request->post()
or Yii::$app->response
, etc.
The first solution is to add /** @phpstan-ignore-next-line */
everywhere in the code where, for example, Yii::$app->response-> will be used.
Question, is there any other proper way to get rid of such errors?
My PHPStan configuration:
parameters:
level: 2
bootstrapFiles:
- vendor/yiisoft/yii2/Yii.php
excludePaths:
- 'runtime/*'
- 'vendor/*'
- 'tests/*'
stubFiles:
- stubs/ActiveRecord.stub
- stubs/Yii.stub
- stubs/YiiRbac.stub
- stubs/YiiBase.stub
- stubs/YiiWeb.stub
- stubs/YiiConsole.stub
universalObjectCratesClasses:
- stdClass