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

TestAnnotation::pass()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5.0061

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 15
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 25
ccs 15
cts 16
cp 0.9375
crap 5.0061
rs 8.439
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