【问题标题】:Suppress complexity warning in PHP抑制 PHP 中的复杂性警告
【发布时间】:2018-08-30 07:11:38
【问题描述】:

我有一个遗留代码,其代码复杂度高于 20。我的管道因此而失败。这是来自管道的确切错误消息:

Function's cyclomatic complexity (36) exceeds allowed  maximum of 20

我没有时间重构代码,所以我正在寻找一种临时解决方案,例如抑制/忽略我的文件:

我尝试使用这些:

 * @SuppressWarnings(PHPMD)
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
 * @SuppressWarnings(PHPMD.LongVariable)
 * @SuppressWarnings(PHPMD.UnusedLocalVariable)

// @codingStandardsIgnoreStart
my code here
// @codingStandardsIgnoreEnd

我也关注了这个article,但我的管道仍然失败。你以前遇到过这样的问题吗?您知道如何在更改我的管道设置/配置的情况下解决此问题吗?

【问题讨论】:

    标签: php bitbucket-pipelines


    【解决方案1】:

    OP 没有提到错误是来自 PHPCS 还是 PHPMD。如果它来自 PHPCS,那么这个文档注释行将抑制警告:

    * phpcs:disable Generic.Metrics.CyclomaticComplexity

    【讨论】:

      【解决方案2】:

      我收到与 OP 相同的警告,我确信它来自 PHPMD。 为了抑制它,我在方法之前使用了 PhpDoc 注释:

      /**
       * @SuppressWarnings(PHPMD.CyclomaticComplexity)
       * @SuppressWarnings(PHPMD.NPathComplexity)
       */
      public function myComplexMethod(...)
      

      【讨论】:

        猜你喜欢
        • 2018-01-14
        • 1970-01-01
        • 2017-06-10
        • 2015-08-03
        • 2012-07-13
        • 2011-04-03
        • 1970-01-01
        • 2020-02-15
        • 2014-01-20
        相关资源
        最近更新 更多