voku/phpstan-rules
Composer 安装命令:
composer require voku/phpstan-rules
包简介
Provides additional rules for phpstan/phpstan.
README 文档
README
phpstan-rules
Provides additional rules for phpstan/phpstan.
Installation
Run
$ composer require --dev voku/phpstan-rules
Usage
All the rules provided (and used) by this library are included in rules.neon.
When you are using phpstan/extension-installer, rules.neon will be automatically included.
Otherwise, you need to include rules.neon in your phpstan.neon:
includes: - vendor/voku/phpstan-rules/rules.neon
Rules
IfConditionHelper
This helper is used by different "condition"-rules: if - and - or - not - ternary
💡 We use this "hack" (helper) to run the check for all kind of conditions.
- double negative string conditions. e.g.
(string)$foo != ''is the same as(string)$foo - double negative integer conditions. e.g.
(int)$foo != 0is the same as(int)$foo - double negative boolean conditions. e.g.
(bool)$foo != falseis the same as(bool)$foo - double negative null conditions. Use "!==" instead if needed
- check 0 vs '' conditions, the behavior was changed in PHP 8
- check possible insane comparisons. e.g.
0 == '0foo', the behavior was changed in PHP 8 - check insane comparisons. e.g.
0 === '0'orfalse && true - check non-empty string is never empty
- check non-empty string is always empty
- check non-empty array is never empty
- do not compare objects with another type
- do not use magic string-concat for objects with "__toString()"
- do not allow assignments. e.g.
if ($a = 0)(see "checkForAssignments") - do not allow Yoda conditions. e.g.
ìf (0 == $a)(see "checkYodaConditions")
Configuration
If you want to configure a list of classes / subclasses that can NOT be used in conditions directly:
e.g.:
- ok:
if ($emailValueObject->isValid()) - error:
if ($emailValueObject != '')
parameters: voku: classesNotInIfConditions: [ AbstractValueObject ]
If you want to check assignments e.g. in "if"-conditions you can use this:
parameters: voku: checkForAssignments: true
If you want to check Yoda conditions can use this:
parameters: voku: checkYodaConditions: true
ExtendedBinaryOpRule
This rule will check "+", "*", "/", "-", ... (operators) and "." (concatenation) for compatible types.
It's included in the default rules.neon so that you don't need to add it manually.
DisallowedCallMethodOnNull
This code is copy&pasted from [phpstan/phpstan-src] and I used it to prevent Call to a member function on null errors while I wasn't already on level 8 where all kind of "NULL" checks are already covered by default.
e.g.
rules: - voku\PHPStan\Rules\DisallowedCallMethodOnNullRule
Support
For support and donations please visit Github | Issues | PayPal | Patreon.
For status updates and release announcements please visit Releases | Twitter | Patreon.
For professional support please contact me.
Thanks
- Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
- Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
- Thanks to StyleCI for the simple but powerfull code style check.
- Thanks to PHPStan && Psalm for relly great Static analysis tools and for discover bugs in the code!
voku/phpstan-rules 适用场景与选型建议
voku/phpstan-rules 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 94.31k 次下载、GitHub Stars 达 33, 最近一次更新时间为 2022 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「PHPStan」 「phpstan-rules」 「phpstan-extreme-rules」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 voku/phpstan-rules 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 voku/phpstan-rules 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 voku/phpstan-rules 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Set of PHPStan rules
Provides rules for phpstan/phpstan.
Services to aid phpstan analysis on CakePHP projects
Doctrine Criteria extensions for PHPStan
PHPStan for Silverstripe
PHPStan extensions for Containers
统计信息
- 总下载量: 94.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 33
- 点击次数: 16
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-17