Skip to content

Instantly share code, notes, and snippets.

@o0h
Last active October 5, 2023 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save o0h/bbdc1bea3746d5a58cb7bb4d0a88aaa9 to your computer and use it in GitHub Desktop.
Save o0h/bbdc1bea3746d5a58cb7bb4d0a88aaa9 to your computer and use it in GitHub Desktop.
PHPStanを利用してエラー制御演算子の利用を検出する
<?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