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

TestAnnotation::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 2
rs 9.6666

1 Method

Rating   Name   Duplication   Size   Complexity  
A TestAnnotation::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