Skip to content

Commit ac6e37a

Browse files
committed
Added "{}" around all double quoted variables, for readability's sake;
Performance improvement in Serializer - wrap length is calculated once during the text portion only. Tags reuse the result. Also no "prefix" adding in tags - the name is simply added before wrapping.
1 parent 4a7affe commit ac6e37a

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

src/phpDocumentor/Reflection/DocBlock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function getText()
243243
$long = $this->getLongDescription()->getContents();
244244

245245
if ($long) {
246-
return $short . "\n\n" . $long;
246+
return "{$short}\n\n{$long}";
247247
} else {
248248
return $short;
249249
}

src/phpDocumentor/Reflection/DocBlock/Serializer.php

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -172,36 +172,23 @@ public function getDocComment(DocBlock $docblock)
172172

173173
$text = $docblock->getText();
174174
if ($this->lineLength) {
175-
$text = wordwrap(
176-
$text,
177-
$this->lineLength - strlen($indent) - 3/*strlen(' * ')*/
178-
);
175+
//3 === strlen(' * ')
176+
$wrapLength = $this->lineLength - strlen($indent) - 3;
177+
$text = wordwrap($text, $wrapLength);
179178
}
180-
$text = str_replace("\n", "\n$indent * ", $text);
179+
$text = str_replace("\n", "\n{$indent} * ", $text);
181180

182-
$comment = "$firstIndent/**\n$indent * $text\n$indent *\n";
181+
$comment = "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n";
183182

184183
/** @var Tag $tag */
185184
foreach ($docblock->getTags() as $tag) {
186-
$tagName = $tag->getName();
187-
$prefixLength = 1/*strlen('@')*/ + strlen($tagName);
188-
189-
//Added to take the first line of the tag into account.
190-
$tagContent = str_repeat(' ', $prefixLength) . $tag->getContent();
191-
185+
$tagText = "@{$tag->getName()} {$tag->getContent()}";
192186
if ($this->lineLength) {
193-
$tagContent = wordwrap(
194-
$tagContent,
195-
$this->lineLength - strlen($indent) - 3/*strlen(' * ')*/
196-
);
187+
$tagText = wordwrap($tagText, $wrapLength);
197188
}
189+
$tagText = str_replace("\n", "\n{$indent} * ", $tagText);
198190

199-
//Clean up the prefix.
200-
substr_replace($tagContent, '', 0, $prefixLength);
201-
202-
$tagContent = str_replace("\n", "\n$indent * ", $tagContent);
203-
204-
$comment .= "$indent * @{$tagName} {$tagContent}\n";
191+
$comment .= "{$indent} * {$tagText}\n";
205192
}
206193

207194
$comment .= $indent . ' */';

0 commit comments

Comments
 (0)