h4ck3r31/psalm-issue-filter-plugin

允许基于 PsalmPHP 中的代码片段过滤/跳过代码问题

v0.3.0 2022-09-10 11:41 UTC

This package is auto-updated.

Last update: 2024-09-10 16:07:08 UTC


README

允许基于代码片段过滤/跳过代码问题。以下配置示例跳过了可能在项目场景中出现的 PossiblyUndefinedStringArrayOffsetPossiblyUndefinedIntArrayOffset

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 用于逻辑分组 issuefilter 项目
  • issue 选择问题类名,filter 项将应用于
    • class 必须使用 Psalm 的问题类名
  • filter 定义有关过滤的匹配策略
    • type 匹配策略 - 要么 str_starts_withpreg_match
    • value 要匹配的相应负载(根据实际策略进行调整)
    • result(默认 false)与 Psalm 的 BeforeAddIssueInterface::beforeAddIssue 中相同
      • true 停止事件处理并保留问题
      • false 停止事件处理并忽略问题

示例

psalm.xmlplugin 部分

<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>