Completed
Push — master ( cd00cd...086849 )
by Julian
15s
created

ParsedObject::hasAnnotation()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 1
nop 2
crap 2
1
<?php
2
namespace ParaTest\Parser;
3
4
abstract class ParsedObject
5
{
6
    /**
7
     * @var string
8
     */
9
    protected $docBlock;
10
11
    /**
12
     * @var string
13
     */
14
    protected $name;
15
16 72
    public function __construct($doc, $name)
17
    {
18 72
        $this->docBlock = $doc;
19 72
        $this->name = $name;
20 72
    }
21
22
    /**
23
     * Get the name of a parsed object
24
     *
25
     * @return string
26
     */
27 24
    public function getName()
28
    {
29 24
        return $this->name;
30
    }
31
32
    /**
33
     * Get the doc block comments of a parsed object
34
     *
35
     * @return string
36
     */
37 20
    public function getDocBlock()
38
    {
39 20
        return $this->docBlock;
40
    }
41
42
    /**
43
     * Returns whether or not the parsed object
44
     * has an annotation matching the name and value
45
     * if provided
46
     *
47
     * @param string $anno
48
     * @param mixed $value
49
     * @return bool
50
     */
51 7
    public function hasAnnotation($anno, $value = null)
52
    {
53 7
        $pattern = sprintf(
54 7
            '/@%s%s/',
55
            $anno,
56 7
            !is_null($value) ? "[\s]+$value" : '\b'
57
        );
58 7
        return (bool) preg_match($pattern, $this->docBlock);
59
    }
60
}
61