airlst/phpstan-config

AirLST项目PHPStan配置

9.0.2 2024-09-23 13:02 UTC

README

Latest Version on Packagist Total Downloads

AirLST项目PHPStan配置。

安装

您可以通过Composer安装此包

composer require --dev airlst/phpstan-config

请确保在您的composer.json中允许运行phpstan/extension-installer插件

{
    "config": {
        "allow-plugins": {
            "phpstan/extension-installer": true
        }
    }
}

使用

在项目根目录创建一个phpstan.php文件,内容如下

<?php

declare(strict_types=1);

$factory = new Airlst\PhpstanConfig\Factory(['src']);

return $factory
    ->level(8)
    ->create();

Factory类的构造函数接受一个数组,包含要扫描的PHP文件路径,用于分析。您可以传递任意数量的路径给它。

配置

您可以在调用create()之前,通过链式调用以下配置选项在Factory类上使用

  • level(int $level): 设置PHPStan的级别
  • include(string $file): 包含额外的PHPStan neon文件
  • exclude(string $file): 排除提供的PHPStan neon文件
  • withBleedingEdge(): 使用前沿版本的PHPStan
  • useCacheDir(string $cacheDir): 使用PHPStan的缓存目录
  • typeCoverage(int $return, int $param, int $property, int $constant): 设置类型覆盖率百分比,默认为所有100%
  • typePerfect(bool $nullOverFalse, bool $noMixedProperty, bool $noMixedCaller, bool $narrowParam, bool $narrowReturn): 设置类型完美配置,默认全部开启。更多详细信息请参阅rectorphp/type-perfect README。
  • addRule(string $file): 向PHPStan添加额外规则
  • ignoreError(string $message, ?string $path, ?int $count, ?bool $reportUnmatched): 忽略提供的错误消息
  • checkMissingIterableValueType(bool $enable = true): 启用/禁用checkMissingIterableValueType规则
  • checkGenericClassInNonGenericObjectType(bool $enable = true): 启用/禁用checkGenericClassInNonGenericObjectType规则
  • strictRules(): 启用/禁用严格规则。有关可用方法参数的信息,请参阅phpstan/phpstan-strict-rules文档

运行PHPStan

使用以下命令运行PHPStan

./vendor/bin/phpstan analyse -c phpstan.php

变更日志

请参阅CHANGELOG以获取有关最近更改的更多信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

许可协议

MIT许可协议(MIT)。有关更多信息,请参阅许可文件