phpstan deprecation rules
2.0.1
この拡張機能を使用するには、作曲家でそれを必要とします。
composer require --dev phpstan/phpstan-deprecation-rules
PHPSTAN/Extension-Installerもインストールする場合は、すべて設定されています。
phpstan/extension-installer使用したくない場合は、プロジェクトのphpstan configにルールを含めます。
includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
この拡張機能は、 @deprecatedとして注釈が付けられたプロパティ/関数/メソッド/クラスを使用するコードの非推奨警告を発します。
非推奨と見なされるコードを所有していない場合は、phpstanスタブファイルを使用して、次のようなベンダーファイルの非推奨を宣言します。
/** @deprecated */
class ThirdPartyClass {}
非推奨コードの使用は、廃止されたコードでは報告されていません。
/** @deprecated */
function doFoo (): void
{
// not reported:
anotherDeprecatedFunction ();
}意図的に非推奨シンボルを呼び出すコードをマークする別の方法があり、これらの呼び出しを報告することも望まない場合は、 DeprecatedScopeResolverインターフェイスを実装して拡張機能を記述できます。
たとえば、 @group legacyで非推奨コードをテストするPHPunitテストをマークすると、この方法で拡張機能を実装できます。
class GroupLegacyScopeResolver implements DeprecatedScopeResolver
{
public function isScopeDeprecated ( Scope $ scope ): bool
{
$ function = $ scope -> getFunction ();
return $ function !== null
&& $ function -> getDocComment () !== null
&& strpos ( $ function -> getDocComment (), ' @group legacy ' ) !== false ;
}
}構成ファイルに登録してください。
services :
-
class : GroupLegacyScopeResolver
tags :
- phpstan.deprecations.deprecatedScopeResolverカスタムPHPSTAN拡張機能を実装するためのコアコンセプトであるScopeの詳細をご覧ください。