prestashop/phpstan-prestashop

PrestaShop 对 PHPStan 的扩展

安装: 1,621,403

依赖关系: 0

建议者: 0

安全性: 0

星标: 5

关注者: 12

分支: 3

开放问题: 5

类型:phpstan-extension

2.0.0 2021-11-23 09:22 UTC

This package is auto-updated.

Last update: 2024-08-23 16:34:24 UTC


README

PHP tests Static Analysis GitHub release GitHub license

内容

此 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\ArrayConfigurationLoaderPHPStanForPrestaShop\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\ArrayConfigurationLoaderPHPStanForPrestaShop\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\ArrayConfigurationLoaderPHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader

使用 PHPConfigurationFileLoader 的示例

services:
    typeHintsForNewMethodsRuleConfigurationFileLoader:
        class: PHPStanForPrestaShop\PHPConfigurationLoader\PHPConfigurationFileLoader
        arguments:
            - .github/workflows/phpstan/exclude-typehint-functions-list.php