This PHPStan extension adds custom rules to PHPStan:
- ClassConstantsMustHaveVisibilityRule
- UseStrictTypesForNewClassesRule
- UseTypeHintForNewMethodsRule
- UseTypedReturnForNewMethodsRule
Install the dependencies with Composer:
composer installInstall the dev dependencies with Composer:
composer install --devRun tests using PHPUnit:
vendor/bin/phpunit -c tests/phpunit.xml testsRules are tested using PHPStan RuleTestCase.
Run static analysis with PHPStan:
vendor/bin/phpstan analyse src tests/Rules -l 5Extension is validated using a real PHPStan phar
bash tests/Acceptance/run.shTo use this extension, first require it in Composer:
composer require --dev prestashop/phpstan-prestashopThen you need to include extension.neon in your project's PHPStan config:
includes:
- vendor/prestashop/phpstan-prestashop/extension.neonRule UseStrictTypesForNewClassesRule requires loading of a configuration asset.
You need to provide a service that is an instance of PHPStanForPrestaShop\PHPConfigurationLoader\ConfigurationLoaderInterface,
named @strictTypesForNewClassesRuleConfigurationFileLoader. It should load an array of classes for which
the UseStrictTypesForNewClassesRule should not be applied.
There is two available implementations: PHPStanForPrestaShop\PHPConfigurationLoader\ArrayConfigurationLoader
and PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader.
Example with PHPConfigurationFileLoader:
services:
strictTypesForNewClassesRuleConfigurationFileLoader:
class: PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader
arguments:
- .github/workflows/phpstan/exclude-class-list.phpRule UseTypedReturnForNewMethodsRule requires loading of a configuration asset.
You need to provide a service that is an instance of PHPStanForPrestaShop\PHPConfigurationLoader\ConfigurationLoaderInterface,
named @returnTypesForNewMethodsRuleConfigurationFileLoader. It should load an array of class methods for which
the UseTypedReturnForNewMethodsRule should not be applied.
There is two available implementations: PHPStanForPrestaShop\PHPConfigurationLoader\ArrayConfigurationLoader
and PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader.
Example with PHPConfigurationFileLoader:
services:
returnTypesForNewMethodsRuleConfigurationFileLoader:
class: PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader
arguments:
- .github/workflows/phpstan/exclude-return-functions-list.phpSimilarly to UseTypedReturnForNewMethodsRule, rule UseTypeHintForNewMethodsRule requires loading of an instance of PHPStanForPrestaShop\PHPConfigurationLoader\ConfigurationLoaderInterface,
named @typeHintsForNewMethodsRuleConfigurationFileLoader. It should load an array of class methods for which
the UseTypeHintForNewMethodsRule should not be applied.
There is two available implementations: PHPStanForPrestaShop\PHPConfigurationLoader\ArrayConfigurationLoader
and PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader.
Example with PHPConfigurationFileLoader:
services:
typeHintsForNewMethodsRuleConfigurationFileLoader:
class: PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader
arguments:
- .github/workflows/phpstan/exclude-typehint-functions-list.php