ParsedObject   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 59
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A getDocBlock() 0 4 1
A hasAnnotation() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ParaTest\Parser;
6
7
abstract class ParsedObject
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $docBlock;
13
14
    /**
15
     * @var string
16
     */
17
    protected $name;
18
19 72
    public function __construct(string $doc, string $name)
20
    {
21 72
        $this->docBlock = $doc;
22 72
        $this->name = $name;
23 72
    }
24
25
    /**
26
     * Get the name of a parsed object.
27
     *
28
     * @return string
29
     */
30 24
    public function getName(): string
31
    {
32 24
        return $this->name;
33
    }
34
35
    /**
36
     * Get the doc block comments of a parsed object.
37
     *
38
     * @return string
39
     */
40 20
    public function getDocBlock()
41
    {
42 20
        return $this->docBlock;
43
    }
44
45
    /**
46
     * Returns whether or not the parsed object
47
     * has an annotation matching the name and value
48
     * if provided.
49
     *
50
     * @param string $anno
0 ignored issues
show
Bug introduced by
There is no parameter named $anno. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
51
     * @param mixed  $value
52
     *
53
     * @return bool
54
     */
55 7
    public function hasAnnotation(string $annotation, string $value = null): bool
56
    {
57 7
        $pattern = sprintf(
58 7
            '/@%s%s/',
59 7
            $annotation,
60 7
            null !== $value ? "[\s]+$value" : '\b'
61
        );
62
63 7
        return 1 === preg_match($pattern, $this->docBlock);
64
    }
65
}
66