|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ClassGeneration package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Antonio Spinelli <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ClassGeneration; |
|
13
|
|
|
|
|
14
|
|
|
use ClassGeneration\DocBlock\TagCollection; |
|
15
|
|
|
use ClassGeneration\DocBlock\TagCollectionInterface; |
|
16
|
|
|
use ClassGeneration\DocBlock\TagInterface; |
|
17
|
|
|
use ClassGeneration\Element\ElementAbstract; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* DocBlock ClassGeneration |
|
21
|
|
|
* @author Antonio Spinelli <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class DocBlock extends ElementAbstract implements DocBlockInterface |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* DockBlock description. |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $description; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* List of allowed tags. |
|
34
|
|
|
* @var TagCollectionInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $tagCollection; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
99 |
|
public function init() |
|
42
|
|
|
{ |
|
43
|
99 |
|
$this->setTagCollection(new TagCollection()); |
|
44
|
99 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
36 |
|
public function getDescription() |
|
50
|
|
|
{ |
|
51
|
36 |
|
return $this->description; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
32 |
|
public function setDescription($description) |
|
58
|
|
|
{ |
|
59
|
32 |
|
$this->description = $description; |
|
60
|
|
|
|
|
61
|
32 |
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritdoc} |
|
66
|
|
|
*/ |
|
67
|
31 |
|
public function getTagCollection() |
|
68
|
|
|
{ |
|
69
|
31 |
|
return $this->tagCollection; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
*/ |
|
75
|
99 |
|
public function setTagCollection(TagCollectionInterface $tagCollection) |
|
76
|
|
|
{ |
|
77
|
99 |
|
$this->tagCollection = $tagCollection; |
|
78
|
|
|
|
|
79
|
99 |
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Add a docblock tag. |
|
84
|
|
|
* |
|
85
|
|
|
* @param TagInterface $tag |
|
86
|
|
|
* |
|
87
|
|
|
* @return DocBlock |
|
88
|
|
|
*/ |
|
89
|
14 |
|
public function addTag(TagInterface $tag) |
|
90
|
|
|
{ |
|
91
|
14 |
|
$this->getTagCollection()->add($tag); |
|
92
|
|
|
|
|
93
|
14 |
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Removes tags by name. |
|
98
|
|
|
* |
|
99
|
|
|
* @param string|array $tagName |
|
100
|
|
|
* |
|
101
|
|
|
* @return TagCollection |
|
102
|
|
|
*/ |
|
103
|
1 |
|
public function removeTagsByName($tagName) |
|
104
|
1 |
|
{ |
|
105
|
1 |
|
return $this->getTagCollection()->removeByName($tagName); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Removes tags by reference. |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $reference |
|
112
|
|
|
* |
|
113
|
|
|
* @return TagCollection |
|
114
|
|
|
*/ |
|
115
|
1 |
|
public function removeTagsByReference($reference) |
|
116
|
|
|
{ |
|
117
|
1 |
|
return $this->getTagCollection()->removeByReferece($reference); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Gets tags by name. |
|
122
|
|
|
* |
|
123
|
|
|
* @param string $tagName |
|
124
|
|
|
* |
|
125
|
|
|
* @return TagCollectionInterface |
|
126
|
|
|
*/ |
|
127
|
2 |
|
public function getTagsByName($tagName) |
|
128
|
|
|
{ |
|
129
|
2 |
|
$foundList = $this->getTagCollection()->getByName($tagName); |
|
130
|
|
|
|
|
131
|
2 |
|
return $foundList; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @{inheritdoc} |
|
136
|
|
|
*/ |
|
137
|
24 |
|
public function toString() |
|
138
|
|
|
{ |
|
139
|
24 |
|
if ($this->getTagCollection()->count() == 0 |
|
140
|
24 |
|
&& ($this->getDescription() === null || $this->getDescription() === '') |
|
141
|
24 |
|
) { |
|
142
|
13 |
|
return PHP_EOL; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
20 |
|
$spaces = $this->getTabulationFormatted(); |
|
146
|
|
|
$block = PHP_EOL |
|
147
|
20 |
|
. $spaces . '/**' . PHP_EOL |
|
148
|
20 |
|
. $spaces . ' * ' . $this->getDescription() . PHP_EOL |
|
149
|
20 |
|
. preg_replace('/\s\*\s/i', $spaces . ' * ', $this->getTagCollection()->toString()); |
|
150
|
|
|
|
|
151
|
20 |
|
return $block . $spaces . ' */' . PHP_EOL; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: