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