Inconsistent PHPDoc and type definitions across Yii2 (for example `BaseYii::$app`).
Several Yii2 classes contain inconsistent or incomplete PHPDoc annotations that affect static analysis (PHPStan/Psalm) and IDE inference.
A representative example is found in BaseYii.php:
/**
* @var \yii\console\Application|\yii\web\Application the application instance
*
* @phpstan-var \yii\console\Application|\yii\web\Application<TUserIdentity>
* @psalm-var \yii\console\Application|\yii\web\Application<TUserIdentity>
*/
public static $app;
However, in many parts of the framework, $app can be null (for example, during test teardown or before bootstrap), leading to PHPStan errors like:
Property Yii::$app (yii\web\Application|yii\console\Application) does not accept null.
This specific case also appears in:
tests/TestCase.php tests/framework/console/controllers/DbMessageControllerTest.php tests/framework/i18n/DbMessageSourceTest.php
The same pattern occurs elsewhere: properties and return types that are dynamically nullable or polymorphic, but their PHPDoc types don’t reflect that.
A review of the phpstan-baseline.neon file shows multiple suppressions related to:
null assignments to properties without null
mixed or union type mismatches
This indicates a systemic documentation/type inconsistency between runtime behavior and declared PHPDoc types.
Yes, many of these issues have been fixed, but many still remain. I plan to fix some of them when updating PHPStan level to 4.
It would also be great to include tests in the analysis, but I don't have enough time to fix all the errors yet, as there are many of them.
It would also be great to include tests in the analysis, but I don't have enough time to fix all the errors yet, as there are many of them.
Once we fix the PHPDoc inconsistencies, then I'll fix the static analysis in the tests.