5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP静的解析でのエラーの抑制

Posted at

静的解析でのエラーの抑制方法をすぐに忘れてしまうので、まとめておきます。

PHP_CodeSniffer

複数行

// phpcs:disable Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed
...
...
// phpcs:enable

1行

// phpcs:ignore Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed
$foo = [1,2,3];
$foo = [1,2,3]; // phpcs:ignore Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed

PHPMD

/**
 * @SuppressWarnings(PHPMD.UnusedLocalVariable)
 */

PHPStan

1行

// @phpstan-ignore-next-line
echo $foo;
echo $foo; // @phpstan-ignore-line

Psalm

/**
 * @psalm-suppress InvalidReturnType
 */

PHPUnit

静的解析ではありませんが、カバレッジ対象から除外する場合。

ブロック

/**
 * @codeCoverageIgnore
 */

複数行

// @codeCoverageIgnoreStart
print '*';
// @codeCoverageIgnoreEnd

1行

exit; // @codeCoverageIgnore

クリエイティブ・コモンズ・ライセンス
この記事はCC BY-SA 4.0(クリエイティブ・コモンズ 表示 4.0 継承 国際 ライセンス)の元で公開します。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?