prestashop / phpstan-prestashop
PrestaShop 对 PHPStan 的扩展
Requires
- php: ^7.2|^8.0
- phpstan/phpstan: ^1.2.0
Requires (Dev)
- nikic/php-parser: ^4.10
- phpstan/phpstan-phpunit: ^1.0.0
- phpstan/phpstan-strict-rules: ^1.1.0
- phpunit/phpunit: ^8.5
- symfony/console: ^5.2
README
内容
此 PHPStan 扩展向 PHPStan 添加自定义规则
- ClassConstantsMustHaveVisibilityRule
- UseStrictTypesForNewClassesRule
- UseTypeHintForNewMethodsRule
- UseTypedReturnForNewMethodsRule
安装
使用 Composer 安装依赖项
composer install
测试
使用 Composer 安装开发依赖项
composer install --dev
使用 PHPUnit 运行测试
vendor/bin/phpunit -c tests/phpunit.xml tests
使用 PHPStan RuleTestCase 测试规则
使用 PHPStan 运行静态分析
vendor/bin/phpstan analyse src tests/Rules -l 5
使用真实的 PHPStan phar 验证扩展
bash tests/Acceptance/run.sh
在项目中使用
要使用此扩展,首先在 Composer 中引入它
composer require --dev prestashop/phpstan-prestashop
然后您需要在项目的 PHPStan 配置中包含 extension.neon
includes: - vendor/prestashop/phpstan-prestashop/extension.neon
所需设置
UseStrictTypesForNewClassesRule
规则 UseStrictTypesForNewClassesRule
需要加载配置资源。
您需要提供一个名为 @strictTypesForNewClassesRuleConfigurationFileLoader
的服务,该服务是 PHPStanForPrestaShop\PHPConfigurationLoader\ConfigurationLoaderInterface
的实例。它应加载一个数组,其中包含不应应用 UseStrictTypesForNewClassesRule
的类。
有两个可用的实现:PHPStanForPrestaShop\PHPConfigurationLoader\ArrayConfigurationLoader
和 PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader
。
使用 PHPConfigurationFileLoader
的示例
services: strictTypesForNewClassesRuleConfigurationFileLoader: class: PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader arguments: - .github/workflows/phpstan/exclude-class-list.php
UseTypedReturnForNewMethodsRule
规则 UseTypedReturnForNewMethodsRule
需要加载配置资源。
您需要提供一个名为 @returnTypesForNewMethodsRuleConfigurationFileLoader
的服务,该服务是 PHPStanForPrestaShop\PHPConfigurationLoader\ConfigurationLoaderInterface
的实例。它应加载一个数组,其中包含不应应用 UseTypedReturnForNewMethodsRule
的类方法。
有两个可用的实现:PHPStanForPrestaShop\PHPConfigurationLoader\ArrayConfigurationLoader
和 PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader
。
使用 PHPConfigurationFileLoader
的示例
services: returnTypesForNewMethodsRuleConfigurationFileLoader: class: PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader arguments: - .github/workflows/phpstan/exclude-return-functions-list.php
UseTypeHintForNewMethodsRule
类似于 UseTypedReturnForNewMethodsRule
,规则 UseTypeHintForNewMethodsRule
也需要加载 PHPStanForPrestaShop\PHPConfigurationLoader\ConfigurationLoaderInterface
的实例,名为 @typeHintsForNewMethodsRuleConfigurationFileLoader
。它应加载一个数组,其中包含不应应用 UseTypeHintForNewMethodsRule
的类方法。
有两个可用的实现:PHPStanForPrestaShop\PHPConfigurationLoader\ArrayConfigurationLoader
和 PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader
。
使用 PHPConfigurationFileLoader
的示例
services: typeHintsForNewMethodsRuleConfigurationFileLoader: class: PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader arguments: - .github/workflows/phpstan/exclude-typehint-functions-list.php