From ac6e37af9760fbfb8d8c1b771d4bb5b30a57031a Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Mon, 27 May 2013 02:04:23 +0300 Subject: [PATCH] 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. --- src/phpDocumentor/Reflection/DocBlock.php | 2 +- .../Reflection/DocBlock/Serializer.php | 31 ++++++------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock.php b/src/phpDocumentor/Reflection/DocBlock.php index a45c144..b5b165c 100644 --- a/src/phpDocumentor/Reflection/DocBlock.php +++ b/src/phpDocumentor/Reflection/DocBlock.php @@ -243,7 +243,7 @@ class DocBlock implements \Reflector $long = $this->getLongDescription()->getContents(); if ($long) { - return $short . "\n\n" . $long; + return "{$short}\n\n{$long}"; } else { return $short; } diff --git a/src/phpDocumentor/Reflection/DocBlock/Serializer.php b/src/phpDocumentor/Reflection/DocBlock/Serializer.php index 545c84e..ac92c09 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Serializer.php +++ b/src/phpDocumentor/Reflection/DocBlock/Serializer.php @@ -172,36 +172,23 @@ class Serializer $text = $docblock->getText(); if ($this->lineLength) { - $text = wordwrap( - $text, - $this->lineLength - strlen($indent) - 3/*strlen(' * ')*/ - ); + //3 === strlen(' * ') + $wrapLength = $this->lineLength - strlen($indent) - 3; + $text = wordwrap($text, $wrapLength); } - $text = str_replace("\n", "\n$indent * ", $text); + $text = str_replace("\n", "\n{$indent} * ", $text); - $comment = "$firstIndent/**\n$indent * $text\n$indent *\n"; + $comment = "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n"; /** @var Tag $tag */ foreach ($docblock->getTags() as $tag) { - $tagName = $tag->getName(); - $prefixLength = 1/*strlen('@')*/ + strlen($tagName); - - //Added to take the first line of the tag into account. - $tagContent = str_repeat(' ', $prefixLength) . $tag->getContent(); - + $tagText = "@{$tag->getName()} {$tag->getContent()}"; if ($this->lineLength) { - $tagContent = wordwrap( - $tagContent, - $this->lineLength - strlen($indent) - 3/*strlen(' * ')*/ - ); + $tagText = wordwrap($tagText, $wrapLength); } + $tagText = str_replace("\n", "\n{$indent} * ", $tagText); - //Clean up the prefix. - substr_replace($tagContent, '', 0, $prefixLength); - - $tagContent = str_replace("\n", "\n$indent * ", $tagContent); - - $comment .= "$indent * @{$tagName} {$tagContent}\n"; + $comment .= "{$indent} * {$tagText}\n"; } $comment .= $indent . ' */';