| 1 | <?php |
||
| 11 | class TestAnnotation implements AnalyzerPassInterface |
||
| 12 | { |
||
| 13 | use DefaultMetadataPassTrait; |
||
| 14 | |||
| 15 | const DESCRIPTION = 'Checks for use of `@test` when methods name begins with test, since it is unnecessary.'; |
||
| 16 | |||
| 17 | /** @var DocBlockFactory */ |
||
| 18 | protected $docBlockFactory; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Creates a DocBlockFactory |
||
| 22 | */ |
||
| 23 | 2 | public function __construct() |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @param ClassMethod $methodStmt |
||
| 30 | * @param Context $context |
||
| 31 | * @return bool |
||
| 32 | */ |
||
| 33 | 5 | public function pass(ClassMethod $methodStmt, Context $context) |
|
| 34 | { |
||
| 35 | 5 | $functionName = $methodStmt->name; |
|
| 36 | 5 | if (!$functionName) { |
|
| 37 | return false; |
||
| 38 | } |
||
| 39 | |||
| 40 | 5 | if (substr($functionName, 0, 4) !== 'test') { |
|
| 41 | 2 | return false; |
|
| 42 | } |
||
| 43 | |||
| 44 | 4 | if ($methodStmt->getDocComment()) { |
|
| 45 | 1 | $phpdoc = $this->docBlockFactory->create($methodStmt->getDocComment()->getText()); |
|
| 46 | |||
| 47 | 1 | if ($phpdoc->hasTag('test')) { |
|
| 48 | 1 | $context->notice( |
|
| 49 | 1 | 'test.annotation', |
|
| 50 | 1 | 'Annotation @test is not needed when the method is prefixed with test.', |
|
| 51 | 1 | $methodStmt |
|
| 52 | ); |
||
| 53 | 1 | return true; |
|
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | 4 | return false; |
|
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @return array |
||
| 62 | */ |
||
| 63 | 2 | public function getRegister() |
|
| 69 | } |
||
| 70 |