Completed
Pull Request — master (#139)
by Kévin
03:44
created

TestAnnotation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 94.44%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 45
ccs 17
cts 18
cp 0.9444
rs 10
c 2
b 0
f 0
wmc 6
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
B pass() 0 25 5
A getRegister() 0 6 1
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