Last active
October 5, 2023 14:09
-
-
Save o0h/bbdc1bea3746d5a58cb7bb4d0a88aaa9 to your computer and use it in GitHub Desktop.
PHPStanを利用してエラー制御演算子の利用を検出する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace O0h\PhpstanErrorControlOp\Rules; | |
use PhpParser\Node; | |
use PHPStan\Analyser\Scope; | |
use PHPStan\Rules\Rule; | |
use PHPStan\Rules\RuleErrorBuilder; | |
class ErrorControlRule implements Rule | |
{ | |
public function getNodeType(): string | |
{ | |
return \PhpParser\Node\Expr\ErrorSuppress::class; | |
} | |
public function processNode(Node $node, Scope $scope): array | |
{ | |
return [RuleErrorBuilder::message('Should not use error control operator(`@`).') | |
->line($node->getLine()) | |
->identifier('errorControlOp.notAllowed') | |
->build(), | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment