Index: library/Zend/Reflection/Method.php =================================================================== --- library/Zend/Reflection/Method.php (revision 21744) +++ library/Zend/Reflection/Method.php (working copy) @@ -143,13 +143,33 @@ */ public function getBody() { - $lines = array_slice( - file($this->getDeclaringClass()->getFileName(), FILE_IGNORE_NEW_LINES), - $this->getStartLine(), - ($this->getEndLine() - $this->getStartLine()), - true - ); + $startLine = $this->getStartLine(); + $endLine = $this->getEndLine(); + $fileLines = file($this->getDeclaringClass()->getFileName(), FILE_IGNORE_NEW_LINES); + if ($startLine == $endLine) { + $lines = array(substr( + $line = $fileLines[$startLine - 1], + $firstPosition = strpos($line, '{') + 1, + strrpos($line, '}') - $firstPosition + )); + } else { + $lines = array_slice( + $fileLines, + $this->getStartLine(), + ($this->getEndLine() - $this->getStartLine()), + true + ); + foreach ($lines as $index => $line) { + $trimmedLine = trim($line); + if (!empty($trimmedLine)) { + break; + } + unset($lines[$index]); + } + } + + $bodyLines = $lines; $firstLine = array_shift($lines); if (trim($firstLine) !== '{') { @@ -159,10 +179,17 @@ $lastLine = array_pop($lines); if (trim($lastLine) !== '}') { + if (count($lines) == 0) { + $tmpBody = implode('', $bodyLines); + $opener = substr_count($tmpBody, '{'); + $closer = substr_count($tmpBody, '}'); + if ($opener != $closer) { + $lastLine = rtrim(substr($lastLine, 0, strrpos($lastLine, '}'))); + } + } array_push($lines, $lastLine); } - // just in case we had code on the bracket lines - return rtrim(ltrim(implode("\n", $lines), '{'), '}'); + return implode("\n", $lines); } -} +} \ No newline at end of file