@@ -36,6 +36,9 @@ class Serializer
36
36
/** @var int|null The max length of a line. */
37
37
protected $ lineLength = null ;
38
38
39
+ /** @var bool Separate tag groups. */
40
+ protected $ separateTags = false ;
41
+
39
42
/**
40
43
* Create a Serializer instance.
41
44
*
@@ -45,17 +48,20 @@ class Serializer
45
48
* @param bool $indentFirstLine Whether to indent the first line.
46
49
* @param int|null $lineLength The max length of a line or NULL to
47
50
* disable line wrapping.
51
+ * @param bool $separateTags Separate tag groups.
48
52
*/
49
53
public function __construct (
50
54
$ indent = 0 ,
51
55
$ indentString = ' ' ,
52
56
$ indentFirstLine = true ,
53
- $ lineLength = null
57
+ $ lineLength = null ,
58
+ $ separateTags = false
54
59
) {
55
60
$ this ->setIndentationString ($ indentString );
56
61
$ this ->setIndent ($ indent );
57
62
$ this ->setIsFirstLineIndented ($ indentFirstLine );
58
63
$ this ->setLineLength ($ lineLength );
64
+ $ this ->setSeparateTags ($ separateTags );
59
65
}
60
66
61
67
/**
@@ -158,6 +164,29 @@ public function getLineLength()
158
164
return $ this ->lineLength ;
159
165
}
160
166
167
+ /**
168
+ * Sets whether there should be an empty line between tag groups.
169
+ *
170
+ * @param bool $separateTags The new value for this setting.
171
+ *
172
+ * @return $this This serializer object.
173
+ */
174
+ public function setSeparateTags ($ separateTags )
175
+ {
176
+ $ this ->separateTags = (bool )$ separateTags ;
177
+ return $ this ;
178
+ }
179
+
180
+ /**
181
+ * Gets whether there should be an empty line between tag groups.
182
+ *
183
+ * @return bool Whether there should be an empty line between tag groups.
184
+ */
185
+ public function getSeparateTags ()
186
+ {
187
+ return $ this ->separateTags ;
188
+ }
189
+
161
190
/**
162
191
* Generate a DocBlock comment.
163
192
*
@@ -180,15 +209,23 @@ public function getDocComment(DocBlock $docblock)
180
209
181
210
$ comment = "{$ firstIndent }/** \n{$ indent } * {$ text }\n{$ indent } * \n" ;
182
211
212
+ $ tags = array_values ($ docblock ->getTags ());
213
+
183
214
/** @var Tag $tag */
184
- foreach ($ docblock ->getTags () as $ tag ) {
215
+ foreach ($ tags as $ key => $ tag ) {
216
+ $ nextTag = isset ($ tags [$ key + 1 ]) ? $ tags [$ key + 1 ] : null ;
217
+
185
218
$ tagText = (string ) $ tag ;
186
219
if ($ this ->lineLength ) {
187
220
$ tagText = wordwrap ($ tagText , $ wrapLength );
188
221
}
189
222
$ tagText = str_replace ("\n" , "\n{$ indent } * " , $ tagText );
190
223
191
224
$ comment .= "{$ indent } * {$ tagText }\n" ;
225
+
226
+ if ($ this ->separateTags && $ nextTag !== null && ! $ tag ->inSameGroup ($ nextTag )) {
227
+ $ comment .= "{$ indent } * \n" ;
228
+ }
192
229
}
193
230
194
231
$ comment .= $ indent . ' */ ' ;
0 commit comments