代码之家  ›  专栏  ›  技术社区  ›  Mantas

PHP混乱检测器可选参数

  •  1
  • Mantas  · 技术社区  · 11 年前

    我有接口X

    interface X
    {
        public function foo($x, $y = 0);
    }
    

    那么我有课

    class xx implements X
    {
        public function foo($x, $y = 0)
        {
            // use $x, but not $y
        }
    }
    

    这很正常,因为我不想使用可选 $y 在此实施中 X 。但PMD警告$y是未使用的参数。

    我可以做什么来轻松改变PMD的行为?我找到的唯一解决方案是用 @SuppressWarnings(unused) 注释,这肯定不是我真正喜欢的。

    1 回复  |  直到 11 年前
        1
  •  2
  •   Martin Trenker    10 年前

    您可以使用 {@inheritdoc} ,在中引入 this commit 跳过对已实现方法的检查。时至今日,我想这是解决这个问题的唯一办法。

    只需将其添加为已实现方法的DocBlock

    /**
     * {@inheritdoc}
     */