h4ck3r31 / psalm-issue-filter-plugin
允许基于 PsalmPHP 中的代码片段过滤/跳过代码问题
v0.3.0
2022-09-10 11:41 UTC
Requires
- ext-simplexml: *
- vimeo/psalm: dev-master
README
允许基于代码片段过滤/跳过代码问题。以下配置示例跳过了可能在项目场景中出现的 PossiblyUndefinedStringArrayOffset
或 PossiblyUndefinedIntArrayOffset
class Subject { /** * @return SomeService */ protected function getSomeService() { // there's no guarantee this service instance is given // however, it particular frameworks it might be like that // -> this plugin helps to skip these boilerplate issues return $GLOBALS['SOME_SERVICE']; } }
配置指令
section
用于逻辑分组issue
和filter
项目issue
选择问题类名,filter
项将应用于class
必须使用 Psalm 的问题类名
filter
定义有关过滤的匹配策略type
匹配策略 - 要么str_starts_with
或preg_match
value
要匹配的相应负载(根据实际策略进行调整)result
(默认false
)与 Psalm 的BeforeAddIssueInterface::beforeAddIssue
中相同true
停止事件处理并保留问题false
停止事件处理并忽略问题
示例
在 psalm.xml
的 plugin
部分
<psalm> <!-- ... --> <plugins> <!-- ... --> <pluginClass class="H4ck3r31\PsalmIssueFilterPlugin\Plugin"> <section> <issue class="Psalm\Issue\PossiblyUndefinedStringArrayOffset" /> <issue class="Psalm\Issue\PossiblyUndefinedIntArrayOffset" /> <filter type="str_starts_with" value="$GLOBALS" result="false" /> <!-- same impact, using `preg_match` instead of `str_starts_with` --> <filter type="preg_match" value="/^\$GLOBALS/" result="true" /> </section> <section> <!-- ... --> </section> </pluginClass> </plugins> <!-- ... --> </psalm>