Extensions for PHPStan
To use this extension, require it in Composer:
composer require --dev slam/phpstan-extensionsWhen you are using phpstan/extension-installer,
conf/slam-rules.neon will be automatically included.
Otherwise you need to include conf/slam-rules.neon in your phpstan.neon:
includes:
- vendor/slam/phpstan-extensions/conf/slam-rules.neonSlamPhpStan\DateTimeImmutableAlteredAndUnusedRule: check for DateTimeImmutable calls that alter the object but don't use the result; likely an error of the transition from mutable DateTime classSlamPhpStan\SymfonyFilesystemRule: forbid calls to raw filesystem functions well wrapped bysymfony/filesystemcomponentSlamPhpStan\SymfonyProcessRule: forbid calls to raw system functions well wrapped bysymfony/processcomponentSlamPhpStan\UnusedVariableRule: check for variable inside functions never used after initial assignmentSlamPhpStan\MissingClosureParameterTypehintRule: requires parameter typehints for closures; WARNING: no PhpDoc allowed, seephpstan/phpstan-strict-rules#87SlamPhpStan\StringToClassRule: requires strings that refer to classes to be expressed with::classnotationSlamPhpStan\GotoRule: no goto allowedSlamPhpStan\ClassNotationRule:- Interfaces must end with "Interface"
- Traits must end with "Trait"
- Abstract classes must start with "Abstract"
- Exceptions must end with "Exception"
SlamPhpStan\PhpUnitFqcnAnnotationRule: classes found in following PHPUnit annotations must exist:@expectedException@covers@coversDefaultClass@uses
SlamPhpStan\AccessGlobalVariableWithinContextRule: inhibit the access to globals within classes that extend or implement a certain class/interfaceSlamPhpStan\AccessStaticPropertyWithinModelContextRule: inhibit the access to static attributes of a class within classes that extend or implement a certain class/interface, useful to prohibit usage of singletons in models
A yii-rules.neon config is present for Yii projects:
includes:
- vendor/slam/phpstan-extensions/conf/yii-rules.neonWith the following configurations:
SlamPhpStan\AccessGlobalVariableWithinContextRuleto deny the usage of$_GET,$_POSTand other global variables in models implementingyii\db\ActiveRecordInterface: accessing to singletons in models is considered an anti-patternSlamPhpStan\AccessStaticPropertyWithinModelContextRuleto deny the usage ofyii\BaseYiistatic variables like$appin models implementingyii\db\ActiveRecordInterface: accessing to singletons in models is considered an anti-pattern
