slam / phpstan-extensions
Slam extension of phpstan
Fund package maintenance!
Slamdunk
paypal.me/filippotessarotto
Installs: 1 890 743
Dependents: 110
Suggesters: 0
Security: 0
Stars: 67
Watchers: 5
Forks: 13
Open Issues: 4
Type:phpstan-extension
Requires
- php: ~8.3.0 || ~8.4.0
- phpstan/phpstan: ^2
Requires (Dev)
- nette/di: ^3.2.3
- nette/neon: ^3.4.4
- nikic/php-parser: ^4.19.2 || ^5.3.1
- phpstan/phpstan-phpunit: ^2
- phpunit/phpunit: ^11.4.3
- slam/php-cs-fixer-extensions: ^3.12.0
- dev-master
- v6.6.0
- v6.5.0
- v6.4.1
- v6.4.0
- v6.3.0
- v6.2.0
- v6.1.0
- v6.0.0
- v5.1.0
- v5.0.2
- v5.0.1
- v5.0.0
- v4.0.0
- v3.6.1
- v3.6.0
- v3.5.2
- v3.5.1
- v3.5.0
- v3.4.0
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.0
- v2.0.1
- v2.0.0
- v1.2.1
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- dev-renovate/phpstan-phpstan-phpunit-2.x
- dev-renovate/phpstan-phpstan-2.x
- dev-phpstan_2
- dev-renovate/all-minor-patch
- dev-no_useless_inline_annotations
This package is auto-updated.
Last update: 2024-11-11 08:46:04 UTC
README
Extensions for PHPStan
Installation
To use this extension, require it in Composer:
composer require --dev slam/phpstan-extensions
Usage
When 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.neon
Rules
SlamPhpStan\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#87
SlamPhpStan\StringToClassRule
: requires strings that refer to classes to be expressed with::class
notationSlamPhpStan\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
Not-NOW config
A not-now-rules.neon
config is present for forbidding raw date system calls:
includes: - vendor/slam/phpstan-extensions/conf/not-now-rules.neon
These rules forbid:
new DateTimeImmutable()
new DateTime('yesterday')
date('Y-m-d')
time()
strtotime('noon')
You should instead rely on a clock abstraction like lcobucci/clock
.
WARNING: the rules are not perfect, a user can tricks them easily; they are meant only to help the transition to a proper clock abstraction.
Symfony-specific config
A symfony-rules.neon
config is present for Symfony projects:
includes: - vendor/slam/phpstan-extensions/conf/symfony-rules.neon
With the following configurations:
SlamPhpStan\SymfonyFilesystemRule
: forbid calls to raw filesystem functions well wrapped bysymfony/filesystem
componentSlamPhpStan\SymfonyProcessRule
: forbid calls to raw system functions well wrapped bysymfony/process
component
Yii-specific config
A yii-rules.neon
config is present for Yii projects:
includes: - vendor/slam/phpstan-extensions/conf/yii-rules.neon
With the following configurations:
SlamPhpStan\AccessGlobalVariableWithinContextRule
to deny the usage of$_GET
,$_POST
and other global variables in models implementingyii\db\ActiveRecordInterface
: accessing to singletons in models is considered an anti-patternSlamPhpStan\AccessStaticPropertyWithinModelContextRule
to deny the usage ofyii\BaseYii
static variables like$app
in models implementingyii\db\ActiveRecordInterface
: accessing to singletons in models is considered an anti-pattern