Completed
Pull Request — master (#139)
by Kévin
04:02 queued 01:07
created

TestAnnotation::getRegister()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
c 2
b 0
f 0
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Statement;
4
5
use PhpParser\Node\Stmt\ClassMethod;
6
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
7
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
8
use PHPSA\Context;
9
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
10
use phpDocumentor\Reflection\DocBlock;
11
12
class TestAnnotation implements AnalyzerPassInterface
13
{
14
    use DefaultMetadataPassTrait;
15
16
    /**
17
     * @param ClassMethod $methodStmt
18
     * @param Context $context
19
     * @return bool
20
     */
21 23
    public function pass(ClassMethod $methodStmt, Context $context)
22
    {
23 23
        $functionName = $methodStmt->name;
24 23
        if (!$functionName) {
25
            return false;
26
        }
27
28 23
        if (substr($functionName, 0, 4) !== 'test') {
29 10
            return false;
30
        }
31
32 15
        if ($methodStmt->getDocComment()) {
33 11
            $phpdoc = new DocBlock($methodStmt->getDocComment()->getText());
34
35 11
            if ($phpdoc->hasTag('test')) {
36 1
                $context->notice(
37 1
                    'test.annotation',
38 1
                    'Annotation @test is not needed when the method is prefixed with test.',
39
                    $methodStmt
40 1
                );
41 1
                return true;
42
            }
43 11
        }
44 15
        return false;
45
    }
46
47
    /**
48
     * @return array
49
     */
50 1
    public function getRegister()
51
    {
52
        return [
53
            ClassMethod::class
54 1
        ];
55
    }
56
}
57