diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag.php b/src/phpDocumentor/Reflection/DocBlock/Tag.php index 9a33897..f2b1c16 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag.php @@ -113,16 +113,21 @@ class Tag implements \Reflector ); } + $handler = __CLASS__; if (isset(self::$tagHandlerMappings[$matches[1]])) { $handler = self::$tagHandlerMappings[$matches[1]]; - return new $handler( - $matches[1], - isset($matches[2]) ? $matches[2] : '', - $docblock, - $location + } elseif (isset($docblock)) { + $tagName = (string)new Type\Collection( + array($matches[1]), + $docblock->getContext() ); + + if (isset(self::$tagHandlerMappings[$tagName])) { + $handler = self::$tagHandlerMappings[$tagName]; + } } - return new self( + + return new $handler( $matches[1], isset($matches[2]) ? $matches[2] : '', $docblock, @@ -136,7 +141,9 @@ class Tag implements \Reflector * Registers a handler for tags. The class specified is autoloaded if it's * not available. It must inherit from this class. * - * @param string $tag Name of tag to regiser a handler for. + * @param string $tag Name of tag to regiser a handler for. When + * registering a namespaced tag, the full name, along with a prefixing + * slash MUST be provided. * @param string|null $handler FQCN of handler. Specifing NULL removes the * handler for the specified tag, if any. * @@ -154,6 +161,7 @@ class Tag implements \Reflector if ('' !== $tag && class_exists($handler, true) && is_subclass_of($handler, __CLASS__) + && !strpos($tag, '\\') //Accept no slash, and 1st slash at offset 0. ) { self::$tagHandlerMappings[$tag] = $handler; return true; diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ExampleTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ExampleTag.php index 15b5f85..85f5c52 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ExampleTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ExampleTag.php @@ -43,7 +43,17 @@ class ExampleTag extends SourceTag ) { Tag::__construct($type, $content, $docblock, $location); if (preg_match( - '/^(?:\"([^\"]+)\"|(\S+))(?:\s+(.*))?$/su', + '/^ + (?: + # File path in quotes + \"([^\"]+)\" + | + # File URI + (\S+) + ) + # Remaining content (parsed by SourceTag) + (?:\s+(.*))? + $/sux', $this->description, $matches )) { diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php index 9f3b85c..d9af24d 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php @@ -42,17 +42,12 @@ class LinkTag extends Tag Location $location = null ) { parent::__construct($type, $content, $docblock, $location); - $pieces = explode(' ', $this->description); + $content = preg_split('/\s+/u', $this->description, 2); - if (count($pieces) > 1) { - $this->link = array_shift($pieces); - $this->description = implode(' ', $pieces); - } else { - $this->link = $content; - $this->description = $content; - } + // any output is considered a type + $this->link = $content[0]; - $this->content = $content; + $this->description = isset($content[1]) ? $content[1] : $content[0]; } /** diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php index bae0c44..69c9638 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php @@ -57,8 +57,24 @@ class MethodTag extends ReturnTag // until a ) and whitespace : as method name with signature // 5. any remaining text : as description if (preg_match( - '/^[\s]*(?:([\w\|_\\\\]+)[\s]+)?(?:[\w_]+\(\)[\s]+)?([\w\|_\\\\]+)' - .'\(([^\)]*)\)[\s]*(.*)/u', + '/^ + # Return type + (?: + ([\w\|_\\\\]+) + \s+ + )? + # Legacy method name (not captured) + (?: + [\w_]+\(\)\s+ + )? + # Method name + ([\w\|_\\\\]+) + # Arguments + \(([^\)]*)\) + \s* + # Description + (.*) + $/sux', $this->description, $matches )) { diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php index f0e478a..fdbb5c8 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php @@ -42,12 +42,12 @@ class SeeTag extends Tag Location $location = null ) { parent::__construct($type, $content, $docblock, $location); - $content = preg_split('/\s+/u', $content); + $content = preg_split('/\s+/u', $this->description, 2); // any output is considered a type - $this->refers = array_shift($content); + $this->refers = $content[0]; - $this->description = implode(' ', $content); + $this->description = isset($content[1]) ? $content[1] : ''; } /** diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/SourceTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/SourceTag.php index 7f14599..486c793 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/SourceTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/SourceTag.php @@ -51,7 +51,18 @@ class SourceTag extends Tag ) { parent::__construct($type, $content, $docblock, $location); if (preg_match( - '/^([1-9]\d*)\s*(?:([1-9]\d*)\s+)?(.*)$/su', + '/^ + # Starting line + ([1-9]\d*) + \s* + # Number of lines + (?: + ((?1)) + \s+ + )? + # Description + (.*) + $/sux', $this->description, $matches )) { diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php index 7e701f2..df43299 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php @@ -92,6 +92,13 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase 'int', array('int'), "Number of Bobs" + ), + array( + 'return', + "int\nNumber of Bobs", + 'int', + array('int'), + "Number of Bobs" ) ); } diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTagTest.php index aaed800..259384d 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTagTest.php @@ -90,6 +90,13 @@ class ThrowsTagTest extends \PHPUnit_Framework_TestCase 'int', array('int'), "Number of Bobs" + ), + array( + 'throws', + "int\nNumber of Bobs", + 'int', + array('int'), + "Number of Bobs" ) ); }