LoginSignup
18
8

More than 5 years have passed since last update.

Php Inspections EA Extended 3.0.11/Ultimate 2.0.13の新機能

Posted at

Php Inspections (EA Extended)Php Inspections (EA Ultimate)はPhpStormのInspection(コード検査)機能をさらに強力なものに拡張してくれるPHPerなら絶対に入れておきたいプラグインです。無償で使えるのがEA Extendedで、それに更に検査ルールを加えたハイエンドの有償版がEA Ultimateです。

本稿では、そのEA Extended 3.0.11(2019/2/23リリース)、EA Ultimate 2.0.13(2019/2/25リリース)に追加された新たなチェックツールを紹介します。

EA Extended/EA Ultimate共通の新機能

PHPUnitのバグとベストプラクティス

検査名: PhpUnit: bugs and best practices

PhpUnit関連のコードを分析してバグを報告し、ベストプラクティスを使用することを提案します。単体テストでの型安全性を強化するために、インスペクションの設定で「assertSameの使用を提案」を有効にすることができます。

php-playground___Volumes_dev_php-playground__-_____ExampleTest_php__php-playground_.png

assertEqualsよりassertSameのほうが良く、さらにこの場合、assertSameよりもassertTrueのほうが良いということを指摘してくれます。

2019-02-28 11.22.31.gif

array_pushの誤用

検査名: 'array_push(...)' misused

array_push(...) 呼び出しが $array[] = ... と同じ意味で使われている場合に、$array[] =に置き換えることを提案します。そのほうが関数を呼び出すより2倍高速なためです。

array_pushの誤用を検出する様子:

php-playground___Volumes_dev_php-playground__-_____ExampleTest_php__php-playground_.png

誤用は自動で修正してくれる:

php-playground___Volumes_dev_php-playground__-_____ExampleTest_php__php-playground_.png

EA Ultimate限定の新機能

if-return-returnの単純化

検査名: If-return-return could be simplified

条件に基づいてbool値を返すif()構造を分析し、代わりに条件を返すように単純化します。

    if ($conditions) {
        return true;
    }

    return false;

上のコードは下のように単純化できます:

    return $conditions;

繰り返しのメソッド呼び出し

検査名: Repetitive method calls

ループでの繰り返しメソッド呼び出しを報告します。 呼び出し量を減らすために、ローカル変数化を提案します。

疑わしいバイナリオペレーション

検査名: Suspicious binary operations

検査は、instanceof演算子など不明確で疑わしい演算子の優先順位、誤ったオペレータ、ハードコードされたブール値、その他のバグを含む可能性があるケースなど、さまざまなケースを報告します。

$a && $b || $c($a && $b) || $cと書いたほうがいいよと提案してくれる様子:

php-playground___Volumes_dev_php-playground__-_____ExampleTest_php__php-playground_.png

疑わしい変数宣言

検査名: Suspicious variable declaration

疑わしい変数の宣言を分析して報告します。

不要なcontinue

検査名: Unnecessary continue statements

削ってもいいcontinueがあれば教えてくれます。

php-playground___Volumes_dev_php-playground__-_____ExampleTest_php__php-playground_.png

関連

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