@@ -36,6 +36,9 @@ class Serializer
3636 /** @var int|null The max length of a line. */
3737 protected $ lineLength = null ;
3838
39+ /** @var bool Separate tag groups. */
40+ protected $ separateTags = false ;
41+
3942 /**
4043 * Create a Serializer instance.
4144 *
@@ -45,17 +48,20 @@ class Serializer
4548 * @param bool $indentFirstLine Whether to indent the first line.
4649 * @param int|null $lineLength The max length of a line or NULL to
4750 * disable line wrapping.
51+ * @param bool $separateTags Separate tag groups.
4852 */
4953 public function __construct (
5054 $ indent = 0 ,
5155 $ indentString = ' ' ,
5256 $ indentFirstLine = true ,
53- $ lineLength = null
57+ $ lineLength = null ,
58+ $ separateTags = false
5459 ) {
5560 $ this ->setIndentationString ($ indentString );
5661 $ this ->setIndent ($ indent );
5762 $ this ->setIsFirstLineIndented ($ indentFirstLine );
5863 $ this ->setLineLength ($ lineLength );
64+ $ this ->setSeparateTags ($ separateTags );
5965 }
6066
6167 /**
@@ -158,6 +164,29 @@ public function getLineLength()
158164 return $ this ->lineLength ;
159165 }
160166
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+
161190 /**
162191 * Generate a DocBlock comment.
163192 *
@@ -180,15 +209,23 @@ public function getDocComment(DocBlock $docblock)
180209
181210 $ comment = "{$ firstIndent }/** \n{$ indent } * {$ text }\n{$ indent } * \n" ;
182211
212+ $ tags = array_values ($ docblock ->getTags ());
213+
183214 /** @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+
185218 $ tagText = (string ) $ tag ;
186219 if ($ this ->lineLength ) {
187220 $ tagText = wordwrap ($ tagText , $ wrapLength );
188221 }
189222 $ tagText = str_replace ("\n" , "\n{$ indent } * " , $ tagText );
190223
191224 $ comment .= "{$ indent } * {$ tagText }\n" ;
225+
226+ if ($ this ->separateTags && $ nextTag !== null && ! $ tag ->inSameGroup ($ nextTag )) {
227+ $ comment .= "{$ indent } * \n" ;
228+ }
192229 }
193230
194231 $ comment .= $ indent . ' */ ' ;
0 commit comments