2

PHP用の静的コード分析ツールはかなりたくさんあるようですが、PHPコードでスローされたがキャッチされない例外を検出できるツールを提案していただけますか?(理論的にはPHPスクリプトでの実行を停止できるもの)。

のようなものだけを見ることができればthrow new SomeException()幸いSomeExceptionですException

私はあまり洗練されたものを探していません-私が(あなたがポイントを得る)から(あなたがポイントを得る)から走るとsomeFunctionThatCanThrow('throw内部にステートメントがあるindex.phpので)私がトラブルに巻き込まれる可能性があることを警告するためだけに。ランタイムであっても、それは決して起こりません。

ありがとう。

4

2 に答える 2

3

PHPLintがその答えのようです。たとえば、解析します

<?php

function some()
{
    if (time() == 123) {
        throw new Exception("I can't happen");
    }
}

some();

、(過去にいない限り)例外をスローすることはありません。

BEGIN parsing of test-cSdHoW
1:      <?php
2:      
3:      function some()
4:      {
5:       if (time() == 123) {
6:        throw new Exception("I can't happen");

          throw new Exception("I can't happen");
                                                \_ HERE
==== 6: notice: here generating exception(s) Exception

          throw new Exception("I can't happen");
                                                \_ HERE
==== 6: ERROR: exception(s) must be caught or declared to be thrown: Exception
7:       }
8:      }
9:      
10:     some();
==== 3: notice: guessed signature of the function `some()' as void()

        some();
             \_ HERE
==== 10: notice: here generating exception(s) Exception

        some();
             \_ HERE
==== 10: Warning: uncaught exception(s): Exception
END parsing of test-cSdHoW
==== ?: notice: unused package `dummy.php'
==== ?: notice: required module `standard'
Overall test results: 1 errors, 1 warnings.

だから、まさにそれが私が求めていたものです:) docblockを追加して例外をキャッチしても、PHPLintからのエラーや警告は発生しなくなります。

于 2011-11-25T12:04:29.087 に答える
2

2015年に関しては、PhpStormには、プラグインPhp Inspections(EA Extended)として利用可能なSCAツールが存在します。これは、ネストされた呼び出しを含む、この種の分析を行います。さらに、コンテキストを考慮に入れます。たとえば、致命的な結果につながる__toStringの手渡しされていない例外内で、プラグインがこれを報告します。

于 2015-06-13T17:02:44.367 に答える