ergebnis / phpstan-rules
为 phpstan/phpstan 提供规则。
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- ext-mbstring: *
- nikic/php-parser: ^4.2.3 || ^5.0.0
- phpstan/phpstan: ^1.10.21
Requires (Dev)
- doctrine/orm: ^3.0.0
- ergebnis/composer-normalize: ^2.42.0
- ergebnis/license: ^2.4.0
- ergebnis/php-cs-fixer-config: ^6.22.0
- ergebnis/phpunit-slow-test-detector: ^2.10.0
- nette/di: ^3.2.0
- phpstan/phpstan-deprecation-rules: ^1.1.4
- phpstan/phpstan-strict-rules: ^1.5.2
- phpunit/phpunit: ^10.5.10
- psalm/plugin-phpunit: ~0.18.4
- psr/container: ^2.0.2
- rector/rector: ^1.0.0
- vimeo/psalm: ^5.21.1
- dev-main
- 2.2.0
- 2.1.0
- 2.0.0
- 1.0.0
- 0.15.3
- 0.15.2
- 0.15.1
- 0.15.0
- 0.14.4
- 0.14.3
- 0.14.2
- 0.14.1
- 0.14.0
- 0.13.0
- 0.12.2
- 0.12.1
- 0.12.0
- 0.11.0
- 0.10.0
- 0.9.1
- 0.9.0
- 0.8.1
- 0.8.0
- 0.7.1
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- dev-dependabot/composer/phpstan/phpstan-deprecation-rules-1.2.1
- dev-fix/final-in-abstract-class
This package is auto-updated.
Last update: 2024-09-12 09:34:08 UTC
README
本项目提供了一个包含 composer 包的规则,用于 phpstan/phpstan。
安装
运行
composer require --dev ergebnis/phpstan-rules
用法
此库提供(并使用)的所有规则都包含在 rules.neon 中。
当你使用 phpstan/extension-installer 时,rules.neon 将自动包含。
否则你需要在你的 phpstan.neon 中包含 rules.neon
includes: - vendor/ergebnis/phpstan-rules/rules.neon
💡 你可能希望在这些规则的基础上使用
规则
本软件包为与 phpstan/phpstan 一起使用提供了以下规则
Ergebnis\PHPStan\Rules\Classes\FinalRuleErgebnis\PHPStan\Rules\Classes\NoExtendsRuleErgebnis\PHPStan\Rules\Classes\PHPUnit\Framework\TestCaseWithSuffixRuleErgebnis\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRuleErgebnis\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRuleErgebnis\PHPStan\Rules\Closures\NoParameterWithNullDefaultValueRuleErgebnis\PHPStan\Rules\Expressions\NoCompactRuleErgebnis\PHPStan\Rules\Expressions\NoErrorSuppressionRuleErgebnis\PHPStan\Rules\Expressions\NoEvalRuleErgebnis\PHPStan\Rules\Expressions\NoIssetRuleErgebnis\PHPStan\Rules\Files\DeclareStrictTypesRuleErgebnis\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRuleErgebnis\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclarationErgebnis\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRuleErgebnis\PHPStan\Rules\Methods\FinalInAbstractClassRuleErgebnis\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRuleErgebnis\PHPStan\Rules\Methods\NoNullableReturnTypeDeclarationRuleErgebnis\PHPStan\Rules\Methods\NoParameterWithContainerTypeDeclarationRuleErgebnis\PHPStan\Rules\Methods\NoParameterWithNullableTypeDeclarationRuleErgebnis\PHPStan\Rules\Methods\NoParameterWithNullDefaultValueRuleErgebnis\PHPStan\Rules\Methods\PrivateInFinalClassRuleErgebnis\PHPStan\Rules\Statements\NoSwitchRule
类
Classes\FinalRule
此规则在非匿名类不是 final 时报告错误。
💡 此规则忽略以下类
- 使用
@Entity、@ORM\Entity或@ORM\Mapping\Entity注解的类 - 使用
Doctrine\ORM\Mapping\Entity属性的类
在类级别上。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: final: enabled: false
不允许 abstract 类
默认情况下,此规则允许声明 abstract 类。
您可以将 allowAbstractClasses 参数设置为 false 来不允许抽象类。
parameters: ergebnis: final: allowAbstractClasses: false
排除类检查
您可以将 classesNotRequiredToBeAbstractOrFinal 参数设置为要排除检查的类名列表。
parameters: ergebnis: final: classesNotRequiredToBeAbstractOrFinal: - Foo\Bar\NeitherAbstractNorFinal - Bar\Baz\NeitherAbstractNorFinal
Classes\NoExtendsRule
此规则在类扩展另一个类时报告错误。
默认值
默认情况下,此规则允许以下类被扩展
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noExtends: enabled: false
允许类扩展
您可以将 classesAllowedToBeExtended 参数设置为允许扩展的类名列表。
parameters: ergebnis: noExtends: classesAllowedToBeExtended: - Ergebnis\PHPStan\Rules\Test\Integration\AbstractTestCase - Ergebnis\PHPStan\Rules\Test\Integration\AbstractTestCase
类\PHPUnit\Framework\TestCaseWithSuffixRule
此规则会在一个具体类是PHPUnit\Framework\TestCase的子类但未包含Test后缀时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: testCaseWithSuffix: enabled: false
闭包
闭包\NoNullableReturnTypeDeclarationRule
此规则会在闭包使用可空返回类型声明时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noNullableReturnTypeDeclaration: enabled: false
闭包\NoParameterWithNullableTypeDeclarationRule
此规则会在闭包有一个参数带有可空类型声明时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noParameterWithNullableTypeDeclaration: enabled: false
闭包\NoParameterWithNullDefaultValueRule
此规则会在闭包有一个参数以null作为默认值时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noParameterWithNullDefaultValue: enabled: false
表达式
表达式\NoCompactRule
此规则会在使用函数compact()时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noCompact: enabled: false
表达式\NoEvalRule
此规则会在使用语言构造eval()时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noEval: enabled: false
表达式\NoErrorSuppressionRule
此规则会在使用@来抑制错误时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noErrorSuppression: enabled: false
表达式\NoIssetRule
此规则会在使用语言构造isset()时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noIsset: enabled: false
文件
文件\DeclareStrictTypesRule
此规则会在一个非空文件不包含declare(strict_types=1)声明时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: declareStrictTypes: enabled: false
函数
函数\NoNullableReturnTypeDeclarationRule
此规则会在函数使用可空返回类型声明时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noNullableReturnTypeDeclaration: enabled: false
函数\NoParameterWithNullableTypeDeclarationRule
此规则会在函数有一个参数带有可空类型声明时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noParameterWithNullableTypeDeclaration: enabled: false
函数\NoParameterWithNullDefaultValueRule
此规则会在函数有一个参数以null作为默认值时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noParameterWithNullDefaultValue: enabled: false
方法
方法\FinalInAbstractClassRule
此规则会在一个抽象类中的具体public或protected方法不是final时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: finalInAbstractClass: enabled: false
方法\NoConstructorParameterWithDefaultValueRule
此规则会在在匿名类、类中声明的构造函数
- 匿名类
- 类
有默认值时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noConstructorParameterWithDefaultValue: enabled: false
方法\NoNullableReturnTypeDeclarationRule
此规则会在接口中声明的
- 匿名类
- 类
- 接口
方法使用可空返回类型声明时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noNullableReturnTypeDeclaration: enabled: false
方法\NoParameterWithContainerTypeDeclarationRule
此规则会在方法有一个已知依赖注入容器或服务定位器的类型声明时报告错误。
默认值
默认情况下,此规则禁止使用表示实现
预期的接口将被注入到方法中的类型声明。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noParameterWithContainerTypeDeclaration: enabled: false
配置容器接口
您可以将interfacesImplementedByContainers参数设置为附加容器和服务定位器的接口名称列表。
parameters: ergebnis: noParameterWithContainerTypeDeclaration: interfacesImplementedByContainers: - Fancy\DependencyInjection\ContainerInterface - Other\ServiceLocatorInterface
配置允许使用具有容器类型声明的参数的方法
您可以将methodsAllowedToUseContainerTypeDeclarations参数设置为允许使用具有容器类型声明的参数的方法名称列表。
parameters: ergebnis: noParameterWithContainerTypeDeclaration: methodsAllowedToUseContainerTypeDeclarations: - loadExtension
方法\NoParameterWithNullableTypeDeclarationRule
此规则会在接口中声明的
- 匿名类
- 类
- 接口
有一个参数带有可空类型声明。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noParameterWithNullableTypeDeclaration: enabled: false
方法\NoParameterWithNullDefaultValueRule
此规则会在接口中声明的
- 匿名类
- 类
- 接口
有一个参数以null作为默认值。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noParameterWithNullDefaultValue: enabled: false
方法\PrivateInFinalClassRule
此规则会在一个final类中的方法为protected但可以是private时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: privateInFinalClass: enabled: false
语句
语句\NoSwitchRule
此规则会在使用语句switch()时报告错误。
禁用规则
您可以将 enabled 参数设置为 false 来禁用此规则。
parameters: ergebnis: noSwitch: enabled: false
变更日志
此项目的维护者将本项目的重要变更记录在变更日志中。
贡献
此项目的维护者建议遵循贡献指南。
行为准则
本项目维护者要求贡献者遵循行为准则。
一般支持策略
本项目提供有限的支持。
您可以通过赞助 @localheinz或申请与本项目管理相关的服务发票来支持本项目的维护。
PHP 版本支持策略
本项目支持具有有效和安全支持的 PHP 版本。
本项目维护者在其初始发布后添加对 PHP 版本的支持,并在其达到安全支持结束时停止对 PHP 版本的支持。
安全策略
本项目有一个安全策略。
许可证
本项目使用MIT 许可证。
致谢
方法FinalRule::isWhitelistedClass()受到了FinalClassFixer和FinalInternalClassFixer的工作的启发,这些工作由Dariusz Rumiński、Filippo Tessarotto和Spacepossum为friendsofphp/php-cs-fixer(最初许可下为 MIT)贡献。
社交
关注Twitter上的@localheinz和@ergebnis。