Index: library/Zend/Reflection/Method.php =================================================================== --- library/Zend/Reflection/Method.php (revision 24860) +++ library/Zend/Reflection/Method.php (working copy) @@ -145,21 +145,40 @@ { $lines = array_slice( file($this->getDeclaringClass()->getFileName(), FILE_IGNORE_NEW_LINES), - $this->getStartLine(), - ($this->getEndLine() - $this->getStartLine()), + $this->getStartLine()-1, + ($this->getEndLine() - $this->getStartLine()) + 1, true ); - $firstLine = array_shift($lines); + // Strip off lines until we come to a closing bracket + do { + if (count($lines) == 0) break; + $firstLine = array_shift($lines); + } while (strpos($firstLine, ')') === false); - if (trim($firstLine) !== '{') { - array_unshift($lines, $firstLine); + // If the opening brace isn't on the same line as method + // signature, then we should pop off more lines until we find it + if (strpos($firstLine,'{') === false) { + do { + if (count($lines) == 0) break; + $firstLine = array_shift($lines); + } while (strpos($firstLine, '{') === false); } + // If there are more characters on the line after the opening brace, + // push them back onto the lines stack as they are part of the body + $restOfFirstLine = trim(substr($firstLine, strpos($firstLine, '{')+1)); + if (!empty($restOfFirstLine)) { + array_unshift($lines, $restOfFirstLine); + } + $lastLine = array_pop($lines); - if (trim($lastLine) !== '}') { - array_push($lines, $lastLine); + // If there are more characters on the line before the closing brace, + // push them back onto the lines stack as they are part of the body + $restOfLastLine = trim(substr($lastLine, 0, strrpos($lastLine, '}')-1)); + if (!empty($restOfLastLine)) { + array_push($lines, $restOfLastLine); } // just in case we had code on the bracket lines Index: tests/Zend/Reflection/MethodTest.php =================================================================== --- tests/Zend/Reflection/MethodTest.php (revision 24860) +++ tests/Zend/Reflection/MethodTest.php (working copy) @@ -121,5 +121,25 @@ $this->assertEquals(" {\n\n return 'mixedValue';\n\n }\n", $reflectionMethod->getContents(false)); } + /** + * @group ZF-10870 + */ + public function testGetBodyReturnsCorrectBodyWhenMethodSignatureIsMultiline() + { + $body = ' // FUNKY SIGNATURE'; + $reflectionMethod = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass7', 'bigMethodSignature'); + $this->assertEquals($body, $reflectionMethod->getBody()); + } + + /** + * @group ZF-10870 + */ + public function testGetBodyReturnsCorrectBodyWhenMethodSignatureAndBodyAreOnSameLine() + { + $body = 'return true;'; + $reflectionMethod = new Zend_Reflection_Method('Zend_Reflection_TestSampleClass7', 'testInlineMethod'); + $this->assertEquals($body, $reflectionMethod->getBody()); + } + } Index: tests/Zend/Reflection/_files/TestSampleClass.php =================================================================== --- tests/Zend/Reflection/_files/TestSampleClass.php (revision 24859) +++ tests/Zend/Reflection/_files/TestSampleClass.php (working copy) @@ -182,3 +182,14 @@ } } + +class Zend_Reflection_TestSampleClass7 +{ + public function bigMethodSignature($arg1, $arg2, $arg3, + $arg4, $arg5, $arg6) + { + // FUNKY SIGNATURE + } + + public function testInlineMethod() { return true; } +} Index: tests/Zend/Reflection/FileTest.php =================================================================== --- tests/Zend/Reflection/FileTest.php (revision 24859) +++ tests/Zend/Reflection/FileTest.php (working copy) @@ -60,7 +60,7 @@ require_once $fileToRequire; $reflectionFile = new Zend_Reflection_File($fileToRequire); $this->assertEquals(get_class($reflectionFile), 'Zend_Reflection_File'); - $this->assertEquals(count($reflectionFile->getClasses()), 8); + $this->assertEquals(count($reflectionFile->getClasses()), 9); $this->assertEquals(get_class($reflectionFile->getClass('Zend_Reflection_TestSampleClass2')), 'Zend_Reflection_Class'); } @@ -110,7 +110,7 @@ require_once $fileToRequire; $reflectionFile = new Zend_Reflection_File($fileToRequire); $this->assertEquals(9, $reflectionFile->getStartLine()); - $this->assertEquals(185, $reflectionFile->getEndLine()); + $this->assertEquals(196, $reflectionFile->getEndLine()); } public function testFileGetDocblockReturnsFileDocblock()