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
|
13 |
|
public function add($name, $value = '', $id = null) |
23
|
|
|
{ |
24
|
13 |
|
if ($id) { |
25
|
7 |
|
$this->tags[$id] = new PhpDocTag($name, $value); |
26
|
|
|
} else { |
27
|
13 |
|
$this->tags[] = new PhpDocTag($name, $value); |
28
|
|
|
} |
29
|
13 |
|
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 = '', $id = null) |
41
|
|
|
{ |
42
|
2 |
|
$tags = array(); |
43
|
2 |
|
if ($id) { |
44
|
|
|
$tags[$id] = new PhpDocTag($name, $value); |
45
|
|
|
foreach ($this->tags as $k => $tag) { |
46
|
|
|
if ($k === $id) { |
47
|
|
|
continue; |
48
|
|
|
} |
49
|
|
|
$tags[$k] = $tag; |
50
|
|
|
} |
51
|
14 |
|
$this->tags = $tags; |
52
|
|
|
return $this; |
53
|
14 |
|
} else { |
54
|
14 |
|
array_unshift($this->tags, new PhpDocTag($name, $value)); |
55
|
13 |
|
return $this; |
56
|
13 |
|
} |
57
|
7 |
|
} |
58
|
|
|
|
59
|
13 |
|
public function isEmpty() |
60
|
|
|
{ |
61
|
13 |
|
return empty($this->tags); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function toString() |
65
|
3 |
|
{ |
66
|
|
|
$result = ''; |
67
|
|
|
foreach ($this->tags as $tag) { |
68
|
14 |
|
if ($tag->name) { |
69
|
|
|
$value = $tag->value ? $this->padLines(' * ', ' ' . $tag->value, true, true) : ''; |
70
|
|
|
$result .= <<<PHP |
71
|
13 |
|
* @{$tag->name}{$value} |
72
|
|
|
|
73
|
|
|
PHP; |
74
|
|
|
} else { |
75
|
14 |
|
$result .= $this->padLines(' * ', $tag->value, false, true) . "\n"; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
if ($result) { |
79
|
|
|
$result = <<<PHP |
80
|
|
|
/** |
81
|
|
|
$result */ |
82
|
|
|
|
83
|
|
|
PHP; |
84
|
|
|
} |
85
|
|
|
return $result; |
86
|
|
|
} |
87
|
|
|
} |