Completed
Push — master ( d75c1f...eed677 )
by Viacheslav
12s
created

PhpDoc   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
dl 0
loc 70
ccs 20
cts 26
cp 0.7692
rs 10
c 0
b 0
f 0
wmc 12

5 Methods

Rating   Name   Duplication   Size   Complexity  
A removeById() 0 6 2
A isEmpty() 0 3 1
B toString() 0 25 6
A add() 0 8 2
A prepend() 0 4 1
1
<?php
2
3
namespace Swaggest\PhpCodeBuilder;
4
5
6
class PhpDoc extends PhpTemplate
7
{
8
    const TAG_PARAM = 'param';
9
    const TAG_FILE = 'file';
10
    const TAG_VAR = 'var';
11
    const TAG_PROPERTY = 'property';
12
    const TAG_RETURN = 'return';
13
    const TAG_THROWS = 'throws';
14
    const TAG_METHOD = 'method';
15
    const TAG_SEE = 'see';
16
    const TAG_CODE_COVERAGE_IGNORE_START = 'codeCoverageIgnoreStart';
17
    const TAG_CODE_COVERAGE_IGNORE_END = 'codeCoverageIgnoreEnd';
18
19
    /** @var PhpDocTag[] */
20
    private $tags = array();
21
22 6
    public function add($name, $value = '', $id = null)
23
    {
24 6
        if ($id) {
25 2
            $this->tags[$id] = new PhpDocTag($name, $value);
26
        } else {
27 6
            $this->tags[] = new PhpDocTag($name, $value);
28
        }
29 6
        return $this;
30
    }
31
32
    public function removeById($id)
33
    {
34
        if (isset($this->tags[$id])) {
35
            unset($this->tags[$id]);
36
        }
37
        return $this;
38
    }
39
40 2
    public function prepend($name, $value = '')
41
    {
42 2
        array_unshift($this->tags, new PhpDocTag($name, $value));
43 2
        return $this;
44
    }
45
46
    public function isEmpty()
47
    {
48
        return empty($this->tags);
49
    }
50
51 7
    protected function toString()
52
    {
53 7
        $result = '';
54 7
        foreach ($this->tags as $tag) {
55 6
            if ($tag->name) {
56 6
                if ($tag->name === 'method') {
57 2
                    echo '.';
58
                }
59 6
                $value = $tag->value ? $this->padLines(' * ', ' ' . $tag->value, true, true) : '';
60
                $result .= <<<PHP
61 6
 * @{$tag->name}{$value}
62
63
PHP;
64
            } else {
65 6
                $result .= $this->padLines(' * ', $tag->value, false, true) . "\n";
66
            }
67
        }
68 7
        if ($result) {
69
            $result = <<<PHP
70
/**
71 6
$result */
72
73
PHP;
74
        }
75 7
        return $result;
76
    }
77
}