From 6e1bb192b360666334b6062ba959cc1d0ba37cc5 Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sat, 10 Nov 2012 20:27:57 +0200 Subject: [PATCH 01/10] Inverted @param and @return hierarchy; More fixes to tests and code coverage increase. --- .../Reflection/DocBlock/Tag/MethodTag.php | 2 +- .../Reflection/DocBlock/Tag/ParamTag.php | 33 +------------------ .../Reflection/DocBlock/Tag/ReturnTag.php | 32 ++++++++++++++++-- .../Reflection/DocBlock/Tag/CoversTagTest.php | 25 +++++--------- .../Reflection/DocBlock/Tag/LinkTagTest.php | 18 +++------- .../Reflection/DocBlock/Tag/MethodTagTest.php | 3 ++ .../Reflection/DocBlock/Tag/ParamTagTest.php | 16 +++++---- .../Reflection/DocBlock/Tag/ReturnTagTest.php | 22 ++++++++++--- .../Reflection/DocBlock/Tag/SeeTagTest.php | 26 +++++---------- .../Reflection/DocBlock/Tag/UsesTagTest.php | 17 +++------- .../Reflection/DocBlock/Tag/VarTagTest.php | 8 +++++ .../phpDocumentor/Reflection/DocBlockTest.php | 5 ++- 12 files changed, 100 insertions(+), 107 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php index 23f8dc1..fba1070 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php @@ -19,7 +19,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ -class MethodTag extends ParamTag +class MethodTag extends ReturnTag { /** @var string */ diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php index ade3c05..8688766 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php @@ -12,8 +12,6 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; -use phpDocumentor\Reflection\DocBlock\Tag; - /** * Reflection class for a @param tag in a Docblock. * @@ -21,11 +19,8 @@ use phpDocumentor\Reflection\DocBlock\Tag; * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ -class ParamTag extends Tag +class ParamTag extends ReturnTag { - /** @var string */ - protected $type = ''; - /** * @var string */ @@ -62,32 +57,6 @@ class ParamTag extends Tag $this->description = implode(' ', $content); } - /** - * Returns the unique types of the variable. - * - * @return string[] - */ - public function getTypes() - { - $types = new \phpDocumentor\Reflection\DocBlock\Type\Collection( - array($this->type), - $this->docblock ? $this->docblock->getNamespace() : null, - $this->docblock ? $this->docblock->getNamespaceAliases() : array() - ); - - return $types->getArrayCopy(); - } - - /** - * Returns the type section of the variable. - * - * @return string - */ - public function getType() - { - return implode('|', $this->getTypes()); - } - /** * Returns the variable's name. * diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php index 60d4d74..2d83b63 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php @@ -12,6 +12,8 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tag; + /** * Reflection class for a @return tag in a Docblock. * @@ -19,10 +21,10 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ -class ReturnTag extends ParamTag +class ReturnTag extends Tag { /** @var string */ - protected $type = null; + protected $type = ''; /** * Parses a tag and populates the member variables. @@ -42,4 +44,30 @@ class ReturnTag extends ParamTag $this->description = implode(' ', $content); } + + /** + * Returns the unique types of the variable. + * + * @return string[] + */ + public function getTypes() + { + $types = new \phpDocumentor\Reflection\DocBlock\Type\Collection( + array($this->type), + $this->docblock ? $this->docblock->getNamespace() : null, + $this->docblock ? $this->docblock->getNamespaceAliases() : array() + ); + + return $types->getArrayCopy(); + } + + /** + * Returns the type section of the variable. + * + * @return string + */ + public function getType() + { + return implode('|', $this->getTypes()); + } } diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php index dbbb350..06dac8e 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php @@ -32,7 +32,7 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase * @param string $exContent * @param string $exReference * - * @covers \phpDocumentor\Reflection\DocBlock\Tag\CoversTag::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tag\CoversTag * @dataProvider provideDataForConstuctor * * @return void @@ -40,22 +40,16 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase public function testConstructorParesInputsIntoCorrectFields( $type, $content, - $exName, $exContent, $exDescription, $exReference ) { $tag = new CoversTag($type, $content); - $actualName = $tag->getName(); - $actualContent = $tag->getContent(); - $actualDescription = $tag->getDescription(); - $actualReference = $tag->getReference(); - - $this->assertEquals($exName, $actualName); - $this->assertEquals($exContent, $actualContent); - $this->assertEquals($exDescription, $actualDescription); - $this->assertEquals($exReference, $actualReference); + $this->assertEquals($type, $tag->getName()); + $this->assertEquals($exContent, $tag->getContent()); + $this->assertEquals($exDescription, $tag->getDescription()); + $this->assertEquals($exReference, $tag->getReference()); } /** @@ -68,25 +62,22 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase // $type, $content, $exName, $exContent, $exDescription, $exReference return array( array( - 'uses', + 'covers', 'Foo::bar()', - 'uses', 'Foo::bar()', '', 'Foo::bar()' ), array( - 'uses', + 'covers', 'Foo::bar() Testing', - 'uses', 'Foo::bar() Testing', 'Testing', 'Foo::bar()', ), array( - 'uses', + 'covers', 'Foo::bar() Testing comments', - 'uses', 'Foo::bar() Testing comments', 'Testing comments', 'Foo::bar()', diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php index 0d9abbe..571c671 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php @@ -34,6 +34,7 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase * @param string $exLink * * @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tag\LinkTag::getLink * @dataProvider provideDataForConstuctor * * @return void @@ -41,22 +42,16 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase public function testConstructorParesInputsIntoCorrectFields( $type, $content, - $exName, $exContent, $exDescription, $exLink ) { $tag = new LinkTag($type, $content); - $actualName = $tag->getName(); - $actualContent = $tag->getContent(); - $actualDescription = $tag->getDescription(); - $actualLink = $tag->getLink(); - - $this->assertEquals($exName, $actualName); - $this->assertEquals($exContent, $actualContent); - $this->assertEquals($exDescription, $actualDescription); - $this->assertEquals($exLink, $actualLink); + $this->assertEquals($type, $tag->getName()); + $this->assertEquals($exContent, $tag->getContent()); + $this->assertEquals($exDescription, $tag->getDescription()); + $this->assertEquals($exLink, $tag->getLink()); } /** @@ -71,7 +66,6 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase array( 'link', 'http://www.phpdoc.org/', - 'link', 'http://www.phpdoc.org/', 'http://www.phpdoc.org/', 'http://www.phpdoc.org/' @@ -79,7 +73,6 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase array( 'link', 'http://www.phpdoc.org/ Testing', - 'link', 'http://www.phpdoc.org/ Testing', 'Testing', 'http://www.phpdoc.org/' @@ -87,7 +80,6 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase array( 'link', 'http://www.phpdoc.org/ Testing comments', - 'link', 'http://www.phpdoc.org/ Testing comments', 'Testing comments', 'http://www.phpdoc.org/' diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php index 08d5957..4bef7dc 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php @@ -34,6 +34,9 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase * @param string $description The short description mentioned in the * signature. * + * @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::getMethodName + * * @dataProvider getTestSignatures * * @return void diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php index 5fae81d..b3c2503 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php @@ -33,6 +33,7 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase * @param string $extractedDescription * * @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getVariableName * * @dataProvider provideDataForConstructor * @@ -42,12 +43,15 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase $type, $content, $extractedType, + $extractedTypes, $extractedVarName, $extractedDescription ) { $tag = new ParamTag($type, $content); - $this->assertEquals($extractedType, $tag->getTypes()); + $this->assertEquals($type, $tag->getName()); + $this->assertEquals($extractedType, $tag->getType()); + $this->assertEquals($extractedTypes, $tag->getTypes()); $this->assertEquals($extractedVarName, $tag->getVariableName()); $this->assertEquals($extractedDescription, $tag->getDescription()); } @@ -60,15 +64,15 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase public function provideDataForConstructor() { return array( - array('param', 'int', array('int'), '', ''), - array('param', '$bob', array(), '$bob', ''), + array('param', 'int', 'int', array('int'), '', ''), + array('param', '$bob', '', array(), '$bob', ''), array( - 'param', 'int Number of bobs', array('int'), '', + 'param', 'int Number of bobs', 'int', array('int'), '', 'Number of bobs' ), - array('param', 'int $bob', array('int'), '$bob', ''), + array('param', 'int $bob', 'int', array('int'), '$bob', ''), array( - 'param', 'int $bob Number of bobs', array('int'), '$bob', + 'param', 'int $bob Number of bobs', 'int', array('int'), '$bob', 'Number of bobs' ), ); diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php index bdef29a..7fc5855 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php @@ -31,19 +31,25 @@ class ReturnTagTest extends ParamTagTest * @param string $extractedDescription * * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getType + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getTypes * * @dataProvider provideDataForConstructor * * @return void */ public function testConstructorParsesInputsIntoCorrectFields( + $type, $content, $extractedType, + $extractedTypes, $extractedDescription ) { - $tag = new ReturnTag('return', $content); + $tag = new ReturnTag($type, $content); - $this->assertEquals($extractedType, $tag->getTypes()); + $this->assertEquals($type, $tag->getName()); + $this->assertEquals($extractedType, $tag->getType()); + $this->assertEquals($extractedTypes, $tag->getTypes()); $this->assertEquals($extractedDescription, $tag->getDescription()); } @@ -55,9 +61,15 @@ class ReturnTagTest extends ParamTagTest public function provideDataForConstructor() { return array( - array('', array(), ''), - array('int', array('int'), ''), - array('int Number of Bobs', array('int'), 'Number of Bobs'), + array('return', '', '', array(), ''), + array('return', 'int', 'int', array('int'), ''), + array( + 'return', + 'int Number of Bobs', + 'int', + array('int'), + 'Number of Bobs' + ), ); } } diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php index a74cac5..f789a65 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php @@ -33,6 +33,7 @@ class SeeTagTest extends \PHPUnit_Framework_TestCase * @param string $exReference * * @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tag\SeeTag::getReference * @dataProvider provideDataForConstuctor * * @return void @@ -40,22 +41,16 @@ class SeeTagTest extends \PHPUnit_Framework_TestCase public function testConstructorParesInputsIntoCorrectFields( $type, $content, - $exName, $exContent, $exDescription, $exReference ) { $tag = new SeeTag($type, $content); - $actualName = $tag->getName(); - $actualContent = $tag->getContent(); - $actualDescription = $tag->getDescription(); - $actualReference = $tag->getReference(); - - $this->assertEquals($exName, $actualName); - $this->assertEquals($exContent, $actualContent); - $this->assertEquals($exDescription, $actualDescription); - $this->assertEquals($exReference, $actualReference); + $this->assertEquals($type, $tag->getName()); + $this->assertEquals($exContent, $tag->getContent()); + $this->assertEquals($exDescription, $tag->getDescription()); + $this->assertEquals($exReference, $tag->getReference()); } /** @@ -65,28 +60,25 @@ class SeeTagTest extends \PHPUnit_Framework_TestCase */ public function provideDataForConstuctor() { - // $type, $content, $exName, $exContent, $exDescription, $exReference + // $type, $content, $exContent, $exDescription, $exReference return array( array( - 'uses', + 'see', 'Foo::bar()', - 'uses', 'Foo::bar()', '', 'Foo::bar()' ), array( - 'uses', + 'see', 'Foo::bar() Testing', - 'uses', 'Foo::bar() Testing', 'Testing', 'Foo::bar()', ), array( - 'uses', + 'see', 'Foo::bar() Testing comments', - 'uses', 'Foo::bar() Testing comments', 'Testing comments', 'Foo::bar()', diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php index 0e61cbd..c059818 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php @@ -40,22 +40,16 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase public function testConstructorParesInputsIntoCorrectFields( $type, $content, - $exName, $exContent, $exDescription, $exReference ) { $tag = new UsesTag($type, $content); - $actualName = $tag->getName(); - $actualContent = $tag->getContent(); - $actualDescription = $tag->getDescription(); - $actualReference = $tag->getReference(); - - $this->assertEquals($exName, $actualName); - $this->assertEquals($exContent, $actualContent); - $this->assertEquals($exDescription, $actualDescription); - $this->assertEquals($exReference, $actualReference); + $this->assertEquals($type, $tag->getName()); + $this->assertEquals($exContent, $tag->getContent()); + $this->assertEquals($exDescription, $tag->getDescription()); + $this->assertEquals($exReference, $tag->getReference()); } /** @@ -70,7 +64,6 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase array( 'uses', 'Foo::bar()', - 'uses', 'Foo::bar()', '', 'Foo::bar()' @@ -78,7 +71,6 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase array( 'uses', 'Foo::bar() Testing', - 'uses', 'Foo::bar() Testing', 'Testing', 'Foo::bar()', @@ -86,7 +78,6 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase array( 'uses', 'Foo::bar() Testing comments', - 'uses', 'Foo::bar() Testing comments', 'Testing comments', 'Foo::bar()', diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php index 2c53b56..603ef96 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php @@ -46,6 +46,7 @@ class VarTagTest extends \PHPUnit_Framework_TestCase ) { $tag = new VarTag($type, $content); + $this->assertEquals($type, $tag->getName()); $this->assertEquals($exType, $tag->getType()); $this->assertEquals($exVariable, $tag->getVariableName()); $this->assertEquals($exDescription, $tag->getDescription()); @@ -81,6 +82,13 @@ class VarTagTest extends \PHPUnit_Framework_TestCase '$bob', 'Number of bobs' ), + array( + 'var', + '', + '', + '', + '' + ), ); } } diff --git a/tests/phpDocumentor/Reflection/DocBlockTest.php b/tests/phpDocumentor/Reflection/DocBlockTest.php index 1b7652b..3015a25 100644 --- a/tests/phpDocumentor/Reflection/DocBlockTest.php +++ b/tests/phpDocumentor/Reflection/DocBlockTest.php @@ -49,6 +49,9 @@ DOCBLOCK; $this->assertFalse($object->hasTag('category')); } + /** + * @covers \phpDocumentor\Reflection\DocBlock::__construct + */ public function testConstructFromReflector() { $object = new DocBlock(new \ReflectionClass($this)); @@ -70,7 +73,7 @@ DOCBLOCK; */ public function testExceptionOnInvalidObject() { - $object = new DocBlock($this); + new DocBlock($this); } public function testDotSeperation() From f11936eaaeb34da00abad902ea2ba3a7a7031457 Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sat, 10 Nov 2012 23:19:36 +0200 Subject: [PATCH 02/10] Removed DocBlock::expandType() and associated tests, as previously advised by @mvriel; Added tests for generic Tag objects, and a few others; Increased total coverage by more appropriate use of @covers annotations. --- src/phpDocumentor/Reflection/DocBlock.php | 81 +-------- .../Reflection/DocBlock/LongDescription.php | 3 + .../Reflection/DocBlock/Tag/CoversTagTest.php | 3 +- .../Reflection/DocBlock/Tag/LinkTagTest.php | 3 +- .../Reflection/DocBlock/Tag/MethodTagTest.php | 43 +++-- .../Reflection/DocBlock/Tag/ParamTagTest.php | 1 + .../Reflection/DocBlock/Tag/ReturnTagTest.php | 3 +- .../Reflection/DocBlock/Tag/SeeTagTest.php | 1 - .../Reflection/DocBlock/Tag/UsesTagTest.php | 3 +- .../Reflection/DocBlock/Tag/VarTagTest.php | 2 +- .../Reflection/DocBlock/TagTest.php | 86 +++++++++ .../DocBlock/Type/CollectionTest.php | 17 ++ .../phpDocumentor/Reflection/DocBlockTest.php | 167 ++++++++++-------- 13 files changed, 231 insertions(+), 182 deletions(-) create mode 100644 tests/phpDocumentor/Reflection/DocBlock/TagTest.php diff --git a/src/phpDocumentor/Reflection/DocBlock.php b/src/phpDocumentor/Reflection/DocBlock.php index dff4008..921e829 100644 --- a/src/phpDocumentor/Reflection/DocBlock.php +++ b/src/phpDocumentor/Reflection/DocBlock.php @@ -66,7 +66,7 @@ class DocBlock implements \Reflector public function __construct( $docblock, $namespace = '\\', - $namespace_aliases = array() + array $namespace_aliases = array() ) { if (is_object($docblock)) { if (!method_exists($docblock, 'getDocComment')) { @@ -304,85 +304,6 @@ class DocBlock implements \Reflector return false; } - /** - * Tries to expand a type to it's full namespaced equivalent (FQCN). - * - * This method will take the given type and examine the current namespace - * and namespace aliases to see whether it should expand it into a FQCN - * as defined by the rules in PHP. - * - * @param string $type Type to expand into full namespaced - * equivalent. - * @param string[] $ignore_keywords Whether to ignore given keywords, when - * null it will use the default keywords: - * 'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double', - * 'object', 'mixed', 'array', 'resource', 'void', 'null', 'callback', - * 'false', 'true', 'self', '$this', 'callable'. - * Default value for this parameter is null. - * - * @return string - */ - public function expandType($type, $ignore_keywords = null) - { - if ($type === null) { - return null; - } - - if ($ignore_keywords === null) { - $ignore_keywords = array( - 'string', 'int', 'integer', 'bool', 'boolean', 'float', - 'double', 'object', 'mixed', 'array', 'resource', 'void', - 'null', 'callback', 'false', 'true', 'self', '$this', 'callable' - ); - } - - $namespace = '\\'; - if ($this->namespace != 'default' && $this->namespace != 'global') { - $namespace = rtrim($this->namespace, '\\') . '\\'; - } - - $type = explode('|', $type); - foreach ($type as &$item) { - $item = trim($item); - - // add support for array notation - $is_array = false; - if (substr($item, -2) == '[]') { - $item = substr($item, 0, -2); - $is_array = true; - } - - if ((substr($item, 0, 1) != '\\') - && (!in_array(strtolower($item), $ignore_keywords)) - ) { - $type_parts = explode('\\', $item); - - // if the first segment is an alias; replace with full name - if (isset($this->namespace_aliases[$type_parts[0]])) { - $type_parts[0] = $this->namespace_aliases[$type_parts[0]]; - $item = implode('\\', $type_parts); - } else { - // otherwise prepend the current namespace - $item = $namespace . $item; - } - } - - // full paths always start with a slash - if (isset($item[0]) && ($item[0] !== '\\') - && (!in_array(strtolower($item), $ignore_keywords)) - ) { - $item = '\\' . $item; - } - - // re-add the array notation markers - if ($is_array) { - $item .= '[]'; - } - } - - return implode('|', $type); - } - /** * Builds a string representation of this object. * diff --git a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php index 4ec7b11..3c26035 100644 --- a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php +++ b/src/phpDocumentor/Reflection/DocBlock/LongDescription.php @@ -120,6 +120,9 @@ class LongDescription implements \Reflector * * @todo this should become a more intelligent piece of code where the * configuration contains a setting what format long descriptions are. + * + * @codeCoverageIgnore Will be removed soon, in favor of adapters at + * PhpDocumentor itself that will process text in various formats. * * @return string */ diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php index 06dac8e..ff257aa 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/CoversTagTest.php @@ -28,7 +28,6 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase * * @param string $type * @param string $content - * @param string $exName * @param string $exContent * @param string $exReference * @@ -59,7 +58,7 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase */ public function provideDataForConstuctor() { - // $type, $content, $exName, $exContent, $exDescription, $exReference + // $type, $content, $exContent, $exDescription, $exReference return array( array( 'covers', diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php index 571c671..0578e1a 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/LinkTagTest.php @@ -28,7 +28,6 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase * * @param string $type * @param string $content - * @param string $exName * @param string $exContent * @param string $exDescription * @param string $exLink @@ -61,7 +60,7 @@ class LinkTagTest extends \PHPUnit_Framework_TestCase */ public function provideDataForConstuctor() { - // $type, $content, $exName, $exContent, $exDescription, $exLink + // $type, $content, $exContent, $exDescription, $exLink return array( array( 'link', diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php index 4bef7dc..56fb162 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/MethodTagTest.php @@ -23,19 +23,20 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; class MethodTagTest extends \PHPUnit_Framework_TestCase { /** - * @param string $signature The signature to test + * @param string $signature The signature to test. * @param bool $valid Whether the given signature is expected to * be valid. * @param string $expected_name The method name that is expected from this - * signature + * signature. * @param string $expected_return The return type that is expected from this - * signature - * @param bool $has_params whether this signature features parameters. + * signature. + * @param bool $paramCount Number of parameters in the signature. * @param string $description The short description mentioned in the * signature. * * @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::getMethodName + * @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag::getArguments * * @dataProvider getTestSignatures * @@ -46,7 +47,7 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase $valid, $expected_name, $expected_return, - $has_params, + $paramCount, $description ) { ob_start(); @@ -66,11 +67,7 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected_name, $tag->getMethodName()); $this->assertEquals($expected_return, $tag->getType()); $this->assertEquals($description, $tag->getDescription()); - $this->assertSame( - $has_params, - (bool)(count($tag->getArguments()) > 0), - 'Number of found arguments should exceed 0' - ); + $this->assertCount($paramCount, $tag->getArguments()); } public function getTestSignatures() @@ -78,55 +75,55 @@ class MethodTagTest extends \PHPUnit_Framework_TestCase return array( array( 'foo', - false, 'foo', '', false, '' + false, 'foo', '', 0, '' ), array( 'foo()', - true, 'foo', 'void', false, '' + true, 'foo', 'void', 0, '' ), array( 'foo() description', - true, 'foo', 'void', false, 'description' + true, 'foo', 'void', 0, 'description' ), array( 'int foo()', - true, 'foo', 'int', false, '' + true, 'foo', 'int', 0, '' ), array( 'int foo() description', - true, 'foo', 'int', false, 'description' + true, 'foo', 'int', 0, 'description' ), array( 'int foo($a, $b)', - true, 'foo', 'int', true, '' + true, 'foo', 'int', 2, '' ), array( 'int foo() foo(int $a, int $b)', - true, 'foo', 'int', true, '' + true, 'foo', 'int', 2, '' ), array( 'int foo(int $a, int $b)', - true, 'foo', 'int', true, '' + true, 'foo', 'int', 2, '' ), array( 'null|int foo(int $a, int $b)', - true, 'foo', 'null|int', true, '' + true, 'foo', 'null|int', 2, '' ), array( 'int foo(null|int $a, int $b)', - true, 'foo', 'int', true, '' + true, 'foo', 'int', 2, '' ), array( '\Exception foo() foo(Exception $a, Exception $b)', - true, 'foo', '\Exception', true, '' + true, 'foo', '\Exception', 2, '' ), array( 'int foo() foo(Exception $a, Exception $b) description', - true, 'foo', 'int', true, 'description' + true, 'foo', 'int', 2, 'description' ), array( 'int foo() foo(\Exception $a, \Exception $b) description', - true, 'foo', 'int', true, 'description' + true, 'foo', 'int', 2, 'description' ), ); } diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php index b3c2503..8db7e46 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php @@ -29,6 +29,7 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase * @param string $type * @param string $content * @param string $extractedType + * @param string $extractedTypes * @param string $extractedVarName * @param string $extractedDescription * diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php index 7fc5855..a84e333 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php @@ -20,7 +20,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ -class ReturnTagTest extends ParamTagTest +class ReturnTagTest extends \PHPUnit_Framework_TestCase { /** * Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can @@ -28,6 +28,7 @@ class ReturnTagTest extends ParamTagTest * * @param string $content * @param string $extractedType + * @param string $extractedTypes * @param string $extractedDescription * * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php index f789a65..c61fc4b 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/SeeTagTest.php @@ -28,7 +28,6 @@ class SeeTagTest extends \PHPUnit_Framework_TestCase * * @param string $type * @param string $content - * @param string $exName * @param string $exContent * @param string $exReference * diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php index c059818..5f79d91 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php @@ -28,7 +28,6 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase * * @param string $type * @param string $content - * @param string $exName * @param string $exContent * @param string $exReference * @@ -59,7 +58,7 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase */ public function provideDataForConstuctor() { - // $type, $content, $exName, $exContent, $exDescription, $exReference + // $type, $content, $exContent, $exDescription, $exReference return array( array( 'uses', diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php index 603ef96..1847215 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/VarTagTest.php @@ -59,7 +59,7 @@ class VarTagTest extends \PHPUnit_Framework_TestCase */ public function provideDataForConstuctor() { - // $type, $content + // $type, $content, $exType, $exVariable, $exDescription return array( array( 'var', diff --git a/tests/phpDocumentor/Reflection/DocBlock/TagTest.php b/tests/phpDocumentor/Reflection/DocBlock/TagTest.php new file mode 100644 index 0000000..f50c6c7 --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlock/TagTest.php @@ -0,0 +1,86 @@ + + * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock; + +/** + * Test class for \phpDocumentor\Reflection\DocBlock\Tag\VarTag + * + * @author Daniel O'Connor + * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class TagTest extends \PHPUnit_Framework_TestCase +{ + + /** + * @expectedException \InvalidArgumentException + */ + public function testInvalidTagLine() + { + Tag::createInstance('Invalid tag line'); + } + /** + * Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can + * understand the @var doc block. + * + * @param string $type + * @param string $content + * @param string $exDescription + * + * @covers \phpDocumentor\Reflection\DocBlock\Tag::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tag::getDescription + * @covers \phpDocumentor\Reflection\DocBlock\Tag::getContent + * @dataProvider provideDataForConstuctor + * + * @return void + */ + public function testConstructorParesInputsIntoCorrectFields( + $type, + $content, + $exDescription + ) { + $tag = new Tag($type, $content); + + $this->assertEquals($type, $tag->getName()); + $this->assertEquals($content, $tag->getContent()); + $this->assertEquals($exDescription, $tag->getDescription()); + } + + /** + * Data provider for testConstructorParesInputsIntoCorrectFields + * + * @return array + */ + public function provideDataForConstuctor() + { + // $type, $content, $exDescription + return array( + array( + 'unknown', + 'some content', + 'some content', + ), + array( + 'unknown', + '', + '', + ), + array( + '', + 'unknown', + 'unknown', + ) + ); + } +} diff --git a/tests/phpDocumentor/Reflection/DocBlock/Type/CollectionTest.php b/tests/phpDocumentor/Reflection/DocBlock/Type/CollectionTest.php index 2c13337..ffce80d 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Type/CollectionTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Type/CollectionTest.php @@ -39,6 +39,23 @@ class CollectionTest extends \PHPUnit_Framework_TestCase $this->assertCount(0, $collection->getNamespaceAliases()); } + /** + * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct + * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::setNamespace + * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespace + * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::getNamespaceAliases + * + * @return void + */ + public function testGlobalIgnore() + { + $collection = new Collection(); + $collection->setNamespace('global'); + $this->assertCount(0, $collection); + $this->assertEquals('\\', $collection->getNamespace()); + $this->assertCount(0, $collection->getNamespaceAliases()); + } + /** * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::__construct * diff --git a/tests/phpDocumentor/Reflection/DocBlockTest.php b/tests/phpDocumentor/Reflection/DocBlockTest.php index 3015a25..b6179a2 100644 --- a/tests/phpDocumentor/Reflection/DocBlockTest.php +++ b/tests/phpDocumentor/Reflection/DocBlockTest.php @@ -34,7 +34,11 @@ class DocBlockTest extends \PHPUnit_Framework_TestCase * @return void */ DOCBLOCK; - $object = new DocBlock($fixture); + $object = new DocBlock( + $fixture, + '\MyNamespace', + array('PHPDoc' => '\phpDocumentor') + ); $this->assertEquals( 'This is a short description.', $object->getShortDescription() @@ -43,10 +47,55 @@ DOCBLOCK; 'This is a long description.', $object->getLongDescription()->getContents() ); - $this->assertEquals(2, count($object->getTags())); + $this->assertCount(2, $object->getTags()); $this->assertTrue($object->hasTag('see')); $this->assertTrue($object->hasTag('return')); $this->assertFalse($object->hasTag('category')); + + $this->assertSame('\MyNamespace', $object->getNamespace()); + $this->assertSame( + array('PHPDoc' => '\phpDocumentor'), + $object->getNamespaceAliases() + ); + } + + /** + * @covers \phpDocumentor\Reflection\DocBlock::splitDocBlock + * + * @return void + */ + public function testConstructWithTagsOnly() + { + $fixture = <<assertEquals('', $object->getShortDescription()); + $this->assertEquals('', $object->getLongDescription()->getContents()); + $this->assertCount(2, $object->getTags()); + $this->assertTrue($object->hasTag('see')); + $this->assertTrue($object->hasTag('return')); + $this->assertFalse($object->hasTag('category')); + } + + /** + * @covers \phpDocumentor\Reflection\DocBlock::cleanInput + * + * @return void + */ + public function testConstructOneLiner() + { + $fixture = '/** Short description and nothing more. */'; + $object = new DocBlock($fixture); + $this->assertEquals( + 'Short description and nothing more.', + $object->getShortDescription() + ); + $this->assertEquals('', $object->getLongDescription()->getContents()); + $this->assertCount(0, $object->getTags()); } /** @@ -60,7 +109,7 @@ DOCBLOCK; $object->getShortDescription() ); $this->assertEquals('', $object->getLongDescription()->getContents()); - $this->assertEquals(4, count($object->getTags())); + $this->assertCount(4, $object->getTags()); $this->assertTrue($object->hasTag('author')); $this->assertTrue($object->hasTag('copyright')); $this->assertTrue($object->hasTag('license')); @@ -118,7 +167,7 @@ DOCBLOCK; $object->getLongDescription()->getContents() ); $tags = $object->getTags(); - $this->assertEquals(2, count($tags)); + $this->assertCount(2, $tags); $this->assertTrue($object->hasTag('method')); $this->assertTrue($object->hasTag('Method')); $this->assertInstanceOf( @@ -136,88 +185,66 @@ DOCBLOCK; } /** - * Tests whether a type is expanded with the given namespace and that a - * keyword is not expanded. - * - * @covers \phpDocumentor\Reflection\DocBlock::expandType() - * - * @return void + * @depends testConstructFromReflector + * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName */ - public function testExpandTypeUsingNamespace() + public function testGetTagsByNameZeroAndOneMatch() { - $docblock = new DocBlock('', '\My\Namespace'); - $this->assertEquals('\My\Namespace\Mine', $docblock->expandType('Mine')); + $object = new DocBlock(new \ReflectionClass($this)); + $this->assertEmpty($object->getTagsByName('category')); + $this->assertCount(1, $object->getTagsByName('author')); } /** - * Tests whether a type is expanded when no namespace is given. - * - * @covers \phpDocumentor\Reflection\DocBlock::expandType() - * - * @return void + * @depends testConstructWithTagsOnly + * @covers \phpDocumentor\Reflection\DocBlock::parseTags */ - public function testExpandTypeWithoutNamespace() + public function testParseMultilineTag() { - $docblock = new DocBlock(''); - $this->assertEquals('\Mine', $docblock->expandType('Mine')); + $fixture = <<assertCount(1, $object->getTags()); } /** - * Tests whether a type is expanded with the given namespace when an alias - * is provided. - * - * @covers \phpDocumentor\Reflection\DocBlock::expandType() - * - * @return void + * @depends testConstructWithTagsOnly + * @covers \phpDocumentor\Reflection\DocBlock::parseTags */ - public function testExpandTypeUsingNamespaceAlias() + public function testParseMultilineTagWithLineBreaks() { - $docblock = new DocBlock( - '', - '\My\Namespace', - array('Alias' => '\My\Namespace\Alias') - ); - - // first try a normal resolution without alias - $this->assertEquals( - '\My\Namespace\Al', - $docblock->expandType('Al') - ); - - // try to use the alias - $this->assertEquals( - '\My\Namespace\Alias\Al', - $docblock->expandType('Alias\Al') - ); + $fixture = <<assertCount(1, $object->getTags()); } /** - * Tests whether the keywords that should not be converted are not converted. - * - * @param string $keyword The keyword that is to be tested; this is provided - * by the dataprovider. - * - * @covers \phpDocumentor\Reflection\DocBlock::expandType() - * - * @dataProvider getNonExpandableKeywordsForExpandType - * - * @return void + * @depends testConstructWithTagsOnly + * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName */ - public function testThatExpandTypeDoesNotExpandAllKeywords($keyword) + public function testGetTagsByNameMultipleMatch() { - $docblock = new DocBlock('', '\My\Namespace'); - $this->assertSame($keyword, $docblock->expandType($keyword)); - } - - public function getNonExpandableKeywordsForExpandType() - { - return array( - array(null), - array('string'), array('int'), array('integer'), array('bool'), - array('boolean'), array('float'), array('double'), array('object'), - array('mixed'), array('array'), array('resource'), array('void'), - array('null'), array('callback'), array('false'), array('true'), - array('self'), array('$this'), array('callable') - ); + $fixture = <<assertEmpty($object->getTagsByName('category')); + $this->assertCount(1, $object->getTagsByName('return')); + $this->assertCount(2, $object->getTagsByName('param')); } } From d73444f859f901800292ee8363ad41c40be7a8e7 Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sat, 10 Nov 2012 23:45:28 +0200 Subject: [PATCH 03/10] Minor doc fixes. --- src/phpDocumentor/Reflection/DocBlock.php | 9 ++++++--- tests/phpDocumentor/Reflection/DocBlock/TagTest.php | 2 ++ .../Reflection/DocBlock/Type/CollectionTest.php | 8 ++++---- tests/phpDocumentor/Reflection/DocBlockTest.php | 12 ++++++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock.php b/src/phpDocumentor/Reflection/DocBlock.php index 921e829..fa2a4cb 100644 --- a/src/phpDocumentor/Reflection/DocBlock.php +++ b/src/phpDocumentor/Reflection/DocBlock.php @@ -39,7 +39,7 @@ class DocBlock implements \Reflector /** @var string the current namespace */ protected $namespace = '\\'; - /** @var string[] List of namespace aliases => Fully Qualified Namespace */ + /** @var array List of namespace aliases => Fully Qualified Namespace */ protected $namespace_aliases = array(); /** @@ -56,7 +56,7 @@ class DocBlock implements \Reflector * asterisks) or reflector supporting the getDocComment method. * @param string $namespace The namespace where this * DocBlock resides in; defaults to `\`. - * @param string[] $namespace_aliases A list of namespace aliases + * @param array $namespace_aliases A list of namespace aliases * as provided by the `use` keyword; the key of the array is the alias * name or last part of the alias array if no alias name is provided. * @@ -331,13 +331,16 @@ class DocBlock implements \Reflector } /** - * @return string + * @return string The namespace where this DocBlock resides in. */ public function getNamespace() { return $this->namespace; } + /** + * @return array List of namespace aliases => Fully Qualified Namespace. + */ public function getNamespaceAliases() { return $this->namespace_aliases; diff --git a/tests/phpDocumentor/Reflection/DocBlock/TagTest.php b/tests/phpDocumentor/Reflection/DocBlock/TagTest.php index f50c6c7..31a3fa9 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/TagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/TagTest.php @@ -25,6 +25,8 @@ class TagTest extends \PHPUnit_Framework_TestCase /** * @expectedException \InvalidArgumentException + * + * @return void */ public function testInvalidTagLine() { diff --git a/tests/phpDocumentor/Reflection/DocBlock/Type/CollectionTest.php b/tests/phpDocumentor/Reflection/DocBlock/Type/CollectionTest.php index ffce80d..0b6fa91 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Type/CollectionTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Type/CollectionTest.php @@ -135,8 +135,8 @@ class CollectionTest extends \PHPUnit_Framework_TestCase } /** - * @param $fixture - * @param $expected + * @param string $fixture + * @param array $expected * * @dataProvider provideTypesToExpand * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add @@ -154,8 +154,8 @@ class CollectionTest extends \PHPUnit_Framework_TestCase } /** - * @param $fixture - * @param $expected + * @param string $fixture + * @param array $expected * * @dataProvider provideTypesToExpandWithoutNamespace * @covers phpDocumentor\Reflection\DocBlock\Type\Collection::add diff --git a/tests/phpDocumentor/Reflection/DocBlockTest.php b/tests/phpDocumentor/Reflection/DocBlockTest.php index b6179a2..c0a1df6 100644 --- a/tests/phpDocumentor/Reflection/DocBlockTest.php +++ b/tests/phpDocumentor/Reflection/DocBlockTest.php @@ -100,6 +100,8 @@ DOCBLOCK; /** * @covers \phpDocumentor\Reflection\DocBlock::__construct + * + * @return void */ public function testConstructFromReflector() { @@ -119,6 +121,8 @@ DOCBLOCK; /** * @expectedException \InvalidArgumentException + * + * @return void */ public function testExceptionOnInvalidObject() { @@ -187,6 +191,8 @@ DOCBLOCK; /** * @depends testConstructFromReflector * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName + * + * @return void */ public function testGetTagsByNameZeroAndOneMatch() { @@ -198,6 +204,8 @@ DOCBLOCK; /** * @depends testConstructWithTagsOnly * @covers \phpDocumentor\Reflection\DocBlock::parseTags + * + * @return void */ public function testParseMultilineTag() { @@ -214,6 +222,8 @@ DOCBLOCK; /** * @depends testConstructWithTagsOnly * @covers \phpDocumentor\Reflection\DocBlock::parseTags + * + * @return void */ public function testParseMultilineTagWithLineBreaks() { @@ -232,6 +242,8 @@ DOCBLOCK; /** * @depends testConstructWithTagsOnly * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName + * + * @return void */ public function testGetTagsByNameMultipleMatch() { From 08dc71ba37c26bd338949b3d197a3752b6c4017f Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sun, 11 Nov 2012 00:54:51 +0200 Subject: [PATCH 04/10] Refactored Tag::createInstance() to use a simple tag-to-class map, that has the default tag handlers pre-registered. --- src/phpDocumentor/Reflection/DocBlock/Tag.php | 74 +++++++++++++++--- .../Reflection/DocBlock/TagTest.php | 75 +++++++++++++++++++ 2 files changed, 137 insertions(+), 12 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag.php b/src/phpDocumentor/Reflection/DocBlock/Tag.php index 2cdb680..4496904 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag.php @@ -38,6 +38,30 @@ class Tag implements \Reflector /** @var \phpDocumentor\Reflection\DocBlock docblock class */ protected $docblock; + + /** + * @var array An array with a tag as a key, and an FQCN to a class that + * handles it as an array value. The class is expected to inherit this + * class. + */ + private static $tagHandlerMappings = array( + 'author' => '\phpDocumentor\Reflection\DocBlock\Tag\AuthorTag', + 'covers' => '\phpDocumentor\Reflection\DocBlock\Tag\CoversTag', + 'link' => '\phpDocumentor\Reflection\DocBlock\Tag\LinkTag', + 'method' => '\phpDocumentor\Reflection\DocBlock\Tag\MethodTag', + 'param' => '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag', + 'property-read' + => '\phpDocumentor\Reflection\DocBlock\Tag\PropertyReadTag', + 'property' => '\phpDocumentor\Reflection\DocBlock\Tag\PropertyTag', + 'property-write' + => '\phpDocumentor\Reflection\DocBlock\Tag\PropertyWriteTag', + 'return' => '\phpDocumentor\Reflection\DocBlock\Tag\ReturnTag', + 'see' => '\phpDocumentor\Reflection\DocBlock\Tag\SeeTag', + 'throw' => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag', + 'throws' => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag', + 'uses' => '\phpDocumentor\Reflection\DocBlock\Tag\UsesTag', + 'var' => '\phpDocumentor\Reflection\DocBlock\Tag\VarTag' + ); /** * Factory method responsible for instantiating the correct sub type. @@ -48,7 +72,7 @@ class Tag implements \Reflector * * @return \phpDocumentor\Reflection\DocBlock\Tag */ - public static function createInstance($tag_line) + final public static function createInstance($tag_line) { if (!preg_match( '/^@([\w\-\_\\\\]+)(?:\s*([^\s].*)|$)?/us', @@ -60,18 +84,44 @@ class Tag implements \Reflector ); } - // support hypphen separated tag names - $tag_name = str_replace( - ' ', - '', - ucwords(str_replace('-', ' ', $matches[1])) - ).'Tag'; - $class_name = 'phpDocumentor\\Reflection\\DocBlock\\Tag\\' . $tag_name; + if (isset(self::$tagHandlerMappings[$matches[1]])) { + $handler = self::$tagHandlerMappings[$matches[1]]; + return new $handler( + $matches[1], + isset($matches[2]) ? $matches[2] : '' + ); + } + return new self($matches[1], isset($matches[2]) ? $matches[2] : ''); + } - return ($matches[1] === strtolower($matches[1]) - && @class_exists($class_name)) - ? new $class_name($matches[1], isset($matches[2]) ? $matches[2] : '') - : new self($matches[1], isset($matches[2]) ? $matches[2] : ''); + /** + * Registers a handler for tags. + * + * 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 $handler FQCN of handler. Specifing NULL removes the + * handler for the specified tag, if any. + * + * @return bool TRUE on success, FALSE on failure. + */ + final public static function registerTagHandler($tag, $handler) + { + $tag = trim((string)$tag); + if (null === $handler) { + unset(self::$tagHandlerMappings[$tag]); + return true; + } + if ('' !== $tag + && class_exists($handler, true) + && is_subclass_of($handler, '\\' . __CLASS__) + ) { + self::$tagHandlerMappings[$tag] = $handler; + return true; + } else { + return false; + } } /** diff --git a/tests/phpDocumentor/Reflection/DocBlock/TagTest.php b/tests/phpDocumentor/Reflection/DocBlock/TagTest.php index 31a3fa9..9b5ee11 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/TagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/TagTest.php @@ -32,6 +32,81 @@ class TagTest extends \PHPUnit_Framework_TestCase { Tag::createInstance('Invalid tag line'); } + + public function testTagHandlerUnregistration() + { + $currentHandler = __NAMESPACE__ . '\Tag\VarTag'; + $tagPreUnreg = Tag::createInstance('@var mixed'); + $this->assertInstanceOf( + $currentHandler, + $tagPreUnreg + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPreUnreg + ); + + Tag::registerTagHandler('var', null); + + $tagPostUnreg = Tag::createInstance('@var mixed'); + $this->assertNotInstanceOf( + $currentHandler, + $tagPostUnreg + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPostUnreg + ); + + Tag::registerTagHandler('var', $currentHandler); + } + + public function testTagHandlerRegistration() + { + if (0 == ini_get('allow_url_include')) { + $this->markTestSkipped('"data" URIs for includes are required.'); + } + $currentHandler = __NAMESPACE__ . '\Tag\VarTag'; + $tagPreUnreg = Tag::createInstance('@var mixed'); + $this->assertInstanceOf( + $currentHandler, + $tagPreUnreg + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPreUnreg + ); + + require 'data:text/plain;base64,'. base64_encode(<<assertFalse(Tag::registerTagHandler('var', 'Non existent')); + $this->assertTrue(Tag::registerTagHandler('var', '\MyVarHandler')); + $this->assertFalse( + Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest') + ); + + $tagPostUnreg = Tag::createInstance('@var mixed'); + $this->assertNotInstanceOf( + $currentHandler, + $tagPostUnreg + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPostUnreg + ); + $this->assertInstanceOf( + '\MyVarHandler', + $tagPostUnreg + ); + + $this->assertTrue(Tag::registerTagHandler('var', $currentHandler)); + } + /** * Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can * understand the @var doc block. From b80272767614cef46741d61b7514889df9b4d2af Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sun, 11 Nov 2012 15:20:59 +0200 Subject: [PATCH 05/10] Minor syntax and doc fixes at Tag::registerTagHandler(); Split the "testTagHandlerRegistration" test into several new ones, with appropriate @covers annotations added; Although not required for single liners, class names at the built in tag handlers map are indented on a separate line for readability. --- src/phpDocumentor/Reflection/DocBlock/Tag.php | 48 +++++++---- .../Reflection/DocBlock/TagTest.php | 84 +++++++++++++++++-- 2 files changed, 108 insertions(+), 24 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag.php b/src/phpDocumentor/Reflection/DocBlock/Tag.php index 4496904..1c8be4a 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag.php @@ -45,22 +45,34 @@ class Tag implements \Reflector * class. */ private static $tagHandlerMappings = array( - 'author' => '\phpDocumentor\Reflection\DocBlock\Tag\AuthorTag', - 'covers' => '\phpDocumentor\Reflection\DocBlock\Tag\CoversTag', - 'link' => '\phpDocumentor\Reflection\DocBlock\Tag\LinkTag', - 'method' => '\phpDocumentor\Reflection\DocBlock\Tag\MethodTag', - 'param' => '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag', + 'author' + => '\phpDocumentor\Reflection\DocBlock\Tag\AuthorTag', + 'covers' + => '\phpDocumentor\Reflection\DocBlock\Tag\CoversTag', + 'link' + => '\phpDocumentor\Reflection\DocBlock\Tag\LinkTag', + 'method' + => '\phpDocumentor\Reflection\DocBlock\Tag\MethodTag', + 'param' + => '\phpDocumentor\Reflection\DocBlock\Tag\ParamTag', 'property-read' => '\phpDocumentor\Reflection\DocBlock\Tag\PropertyReadTag', - 'property' => '\phpDocumentor\Reflection\DocBlock\Tag\PropertyTag', + 'property' + => '\phpDocumentor\Reflection\DocBlock\Tag\PropertyTag', 'property-write' => '\phpDocumentor\Reflection\DocBlock\Tag\PropertyWriteTag', - 'return' => '\phpDocumentor\Reflection\DocBlock\Tag\ReturnTag', - 'see' => '\phpDocumentor\Reflection\DocBlock\Tag\SeeTag', - 'throw' => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag', - 'throws' => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag', - 'uses' => '\phpDocumentor\Reflection\DocBlock\Tag\UsesTag', - 'var' => '\phpDocumentor\Reflection\DocBlock\Tag\VarTag' + 'return' + => '\phpDocumentor\Reflection\DocBlock\Tag\ReturnTag', + 'see' + => '\phpDocumentor\Reflection\DocBlock\Tag\SeeTag', + 'throw' + => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag', + 'throws' + => '\phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag', + 'uses' + => '\phpDocumentor\Reflection\DocBlock\Tag\UsesTag', + 'var' + => '\phpDocumentor\Reflection\DocBlock\Tag\VarTag' ); /** @@ -100,8 +112,8 @@ 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 $handler FQCN of handler. Specifing NULL removes the + * @param string $tag Name of tag to regiser a handler for. + * @param string|null $handler FQCN of handler. Specifing NULL removes the * handler for the specified tag, if any. * * @return bool TRUE on success, FALSE on failure. @@ -109,19 +121,21 @@ class Tag implements \Reflector final public static function registerTagHandler($tag, $handler) { $tag = trim((string)$tag); + if (null === $handler) { unset(self::$tagHandlerMappings[$tag]); return true; } + if ('' !== $tag && class_exists($handler, true) - && is_subclass_of($handler, '\\' . __CLASS__) + && is_subclass_of($handler, __CLASS__) ) { self::$tagHandlerMappings[$tag] = $handler; return true; - } else { - return false; } + + return false; } /** diff --git a/tests/phpDocumentor/Reflection/DocBlock/TagTest.php b/tests/phpDocumentor/Reflection/DocBlock/TagTest.php index 9b5ee11..cd77acf 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/TagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/TagTest.php @@ -33,6 +33,11 @@ class TagTest extends \PHPUnit_Framework_TestCase Tag::createInstance('Invalid tag line'); } + /** + * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler + * + * @return void + */ public function testTagHandlerUnregistration() { $currentHandler = __NAMESPACE__ . '\Tag\VarTag'; @@ -61,7 +66,12 @@ class TagTest extends \PHPUnit_Framework_TestCase Tag::registerTagHandler('var', $currentHandler); } - public function testTagHandlerRegistration() + /** + * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler + * + * @return void + */ + public function testTagHandlerCorrectRegistration() { if (0 == ini_get('allow_url_include')) { $this->markTestSkipped('"data" URIs for includes are required.'); @@ -77,18 +87,14 @@ class TagTest extends \PHPUnit_Framework_TestCase $tagPreUnreg ); - require 'data:text/plain;base64,'. base64_encode(<<assertFalse(Tag::registerTagHandler('var', 'Non existent')); $this->assertTrue(Tag::registerTagHandler('var', '\MyVarHandler')); - $this->assertFalse( - Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest') - ); $tagPostUnreg = Tag::createInstance('@var mixed'); $this->assertNotInstanceOf( @@ -107,6 +113,70 @@ TAG_HANDLER $this->assertTrue(Tag::registerTagHandler('var', $currentHandler)); } + /** + * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler + * + * @return void + */ + public function testNonExistentTagHandlerRegistration() + { + $currentHandler = __NAMESPACE__ . '\Tag\VarTag'; + $tagPreReg = Tag::createInstance('@var mixed'); + $this->assertInstanceOf( + $currentHandler, + $tagPreReg + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPreReg + ); + + $this->assertFalse(Tag::registerTagHandler('var', 'Non existent')); + + $tagPostReg = Tag::createInstance('@var mixed'); + $this->assertInstanceOf( + $currentHandler, + $tagPostReg + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPostReg + ); + } + + /** + * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler + * + * @return void + */ + public function testIncompatibleTagHandlerRegistration() + { + $currentHandler = __NAMESPACE__ . '\Tag\VarTag'; + $tagPreReg = Tag::createInstance('@var mixed'); + $this->assertInstanceOf( + $currentHandler, + $tagPreReg + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPreReg + ); + + $this->assertFalse( + Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest') + ); + + $tagPostReg = Tag::createInstance('@var mixed'); + $this->assertInstanceOf( + $currentHandler, + $tagPostReg + ); + $this->assertInstanceOf( + __NAMESPACE__ . '\Tag', + $tagPostReg + ); + } + /** * Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can * understand the @var doc block. From 2348c16485ca798a6c9a6f2a4c4d950201bfb9ea Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sun, 11 Nov 2012 17:45:16 +0200 Subject: [PATCH 06/10] Applied multi line fixes to @param, analogous to those in @return. --- .../Reflection/DocBlock/Tag/ParamTag.php | 11 +++++++++-- .../Reflection/DocBlock/Tag/ParamTagTest.php | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php index 8688766..12edd11 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php @@ -36,7 +36,12 @@ class ParamTag extends ReturnTag { $this->tag = $type; $this->content = $content; - $content = preg_split('/\s+/u', $content); + $content = preg_split( + '/(\s+)/u', + trim($content), + 3, + PREG_SPLIT_DELIM_CAPTURE + ); // if the first item that is encountered is not a variable; it is a type if (isset($content[0]) @@ -44,6 +49,7 @@ class ParamTag extends ReturnTag && ($content[0][0] !== '$') ) { $this->type = array_shift($content); + array_shift($content); } // if the next item starts with a $ it must be the variable name @@ -52,9 +58,10 @@ class ParamTag extends ReturnTag && ($content[0][0] == '$') ) { $this->variableName = array_shift($content); + array_shift($content); } - $this->description = implode(' ', $content); + $this->description = implode('', $content); } /** diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php index 8db7e46..5f1051d 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php @@ -76,6 +76,15 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase 'param', 'int $bob Number of bobs', 'int', array('int'), '$bob', 'Number of bobs' ), + array('param', "int Description \n on multiple lines", 'int', + array('int'), '', "Description \n on multiple lines" + ), + array('param', "int \n\$bob Variable name on a new line", 'int', + array('int'), '$bob', "Variable name on a new line" + ), + array('param', "\nint \$bob Type on a new line", 'int', + array('int'), '$bob', "Type on a new line" + ) ); } } From 6602ce0375474a22d090a00fcf3294904f7d708e Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Sun, 11 Nov 2012 19:51:04 +0200 Subject: [PATCH 07/10] @return now trims the content before splitting it; Removed ThrowTag.php (unnecessary, given the map, which aliases "throw" to ThrowsTag.php); Added tests for ThrowsTag, along with a few other minor test additions and fixes; --- .../Reflection/DocBlock/Tag/ReturnTag.php | 2 +- .../Reflection/DocBlock/Tag/ThrowTag.php | 43 --------- .../Reflection/DocBlock/Tag/ParamTagTest.php | 48 ++++++++-- .../Reflection/DocBlock/Tag/ReturnTagTest.php | 26 ++++- .../Reflection/DocBlock/Tag/ThrowsTagTest.php | 96 +++++++++++++++++++ .../Reflection/DocBlock/Tag/UsesTagTest.php | 2 +- .../phpDocumentor/Reflection/DocBlockTest.php | 26 +++++ 7 files changed, 187 insertions(+), 56 deletions(-) delete mode 100644 src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php create mode 100644 tests/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTagTest.php diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php index 2d83b63..da22677 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php @@ -37,7 +37,7 @@ class ReturnTag extends Tag $this->tag = $type; $this->content = $content; - $content = preg_split('/[\ \t]+/u', $content, 2); + $content = preg_split('/[\ \t]+/u', trim($content), 2); // any output is considered a type $this->type = array_shift($content); diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php deleted file mode 100644 index 63e7a9a..0000000 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com) - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org - */ - -namespace phpDocumentor\Reflection\DocBlock\Tag; - -/** - * Reflection class for a mistyped @throws tag called @throw in a Docblock. - * - * This is a very common error, so @throw is aliased to be @throws - * - * @author Mike van Riel - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @link http://phpdoc.org - */ -class ThrowTag extends ThrowsTag -{ - /** - * Sets the type to @throws and lets parent parse the tag and populates the - * member variables. - * - * @param string $type Tag identifier for this tag (should be 'throw'). - * @param string $content Contents for this tag. - */ - public function __construct($type, $content) - { - if ('throw' !== $type) { - throw new \InvalidArgumentException( - 'Internal error, ' . __CLASS__ . ' was called with ' . $type - ); - } - - parent::__construct('throws', $content); - } -} diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php index 5f1051d..c0a370c 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php @@ -68,22 +68,52 @@ class ParamTagTest extends \PHPUnit_Framework_TestCase array('param', 'int', 'int', array('int'), '', ''), array('param', '$bob', '', array(), '$bob', ''), array( - 'param', 'int Number of bobs', 'int', array('int'), '', + 'param', + 'int Number of bobs', + 'int', + array('int'), + '', 'Number of bobs' ), - array('param', 'int $bob', 'int', array('int'), '$bob', ''), array( - 'param', 'int $bob Number of bobs', 'int', array('int'), '$bob', + 'param', + 'int $bob', + 'int', + array('int'), + '$bob', + '' + ), + array( + 'param', + 'int $bob Number of bobs', + 'int', + array('int'), + '$bob', 'Number of bobs' ), - array('param', "int Description \n on multiple lines", 'int', - array('int'), '', "Description \n on multiple lines" + array( + 'param', + "int Description \n on multiple lines", + 'int', + array('int'), + '', + "Description \n on multiple lines" ), - array('param', "int \n\$bob Variable name on a new line", 'int', - array('int'), '$bob', "Variable name on a new line" + array( + 'param', + "int \n\$bob Variable name on a new line", + 'int', + array('int'), + '$bob', + "Variable name on a new line" ), - array('param', "\nint \$bob Type on a new line", 'int', - array('int'), '$bob', "Type on a new line" + array( + 'param', + "\nint \$bob Type on a new line", + 'int', + array('int'), + '$bob', + "Type on a new line" ) ); } diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php index a84e333..5eef162 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php @@ -26,14 +26,15 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase * Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can * understand the @return DocBlock. * + * @param string $type * @param string $content * @param string $extractedType * @param string $extractedTypes * @param string $extractedDescription * * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct - * @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getType - * @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getTypes + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getType + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getTypes * * @dataProvider provideDataForConstructor * @@ -71,6 +72,27 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase array('int'), 'Number of Bobs' ), + array( + 'return', + 'int|double Number of Bobs', + 'int|double', + array('int', 'double'), + 'Number of Bobs' + ), + array( + 'return', + "int Number of \n Bobs", + 'int', + array('int'), + "Number of \n Bobs" + ), + array( + 'return', + " int Number 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 new file mode 100644 index 0000000..124c469 --- /dev/null +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/ThrowsTagTest.php @@ -0,0 +1,96 @@ + + * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection\DocBlock\Tag; + +/** + * Test class for \phpDocumentor\Reflection\DocBlock\ReturnTag. + * + * @author Mike van Riel + * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ +class ThrowsTagTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can + * understand the @return DocBlock. + * + * @param string $type + * @param string $content + * @param string $extractedType + * @param string $extractedTypes + * @param string $extractedDescription + * + * @covers \phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag + * + * @dataProvider provideDataForConstructor + * + * @return void + */ + public function testConstructorParsesInputsIntoCorrectFields( + $type, + $content, + $extractedType, + $extractedTypes, + $extractedDescription + ) { + $tag = new ThrowsTag($type, $content); + + $this->assertEquals($type, $tag->getName()); + $this->assertEquals($extractedType, $tag->getType()); + $this->assertEquals($extractedTypes, $tag->getTypes()); + $this->assertEquals($extractedDescription, $tag->getDescription()); + } + + /** + * Data provider for testConstructorParsesInputsIntoCorrectFields() + * + * @return array + */ + public function provideDataForConstructor() + { + return array( + array('throws', '', '', array(), ''), + array('throws', 'int', 'int', array('int'), ''), + array( + 'throws', + 'int Number of Bobs', + 'int', + array('int'), + 'Number of Bobs' + ), + array( + 'throws', + 'int|double Number of Bobs', + 'int|double', + array('int', 'double'), + 'Number of Bobs' + ), + array( + 'throws', + "int Number of \n Bobs", + 'int', + array('int'), + "Number of \n Bobs" + ), + array( + 'throws', + " int Number of Bobs", + 'int', + array('int'), + "Number of Bobs" + ) + ); + } +} diff --git a/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php b/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php index 5f79d91..45868d7 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php @@ -31,7 +31,7 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase * @param string $exContent * @param string $exReference * - * @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag * @dataProvider provideDataForConstuctor * * @return void diff --git a/tests/phpDocumentor/Reflection/DocBlockTest.php b/tests/phpDocumentor/Reflection/DocBlockTest.php index c0a1df6..ce471bf 100644 --- a/tests/phpDocumentor/Reflection/DocBlockTest.php +++ b/tests/phpDocumentor/Reflection/DocBlockTest.php @@ -149,6 +149,32 @@ DOCBLOCK; ); } + /** + * @covers \phpDocumentor\Reflection\DocBlock::parseTags + * @expectedException \LogicException + * + * @return void + */ + public function testInvalidTagBlock() + { + if (0 == ini_get('allow_url_include')) { + $this->markTestSkipped('"data" URIs for includes are required.'); + } + + require 'data:text/plain;base64,'. base64_encode( +<<<'TAG_HANDLER' + Date: Tue, 13 Nov 2012 16:43:36 +0200 Subject: [PATCH 08/10] Tweaked the "testInvalidTagBlock" test to appease PHPCS (though strictly speaking, this is a bug with PHPCS "NEWDOC" handling). --- tests/phpDocumentor/Reflection/DocBlockTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpDocumentor/Reflection/DocBlockTest.php b/tests/phpDocumentor/Reflection/DocBlockTest.php index ce471bf..625faf0 100644 --- a/tests/phpDocumentor/Reflection/DocBlockTest.php +++ b/tests/phpDocumentor/Reflection/DocBlockTest.php @@ -162,14 +162,14 @@ DOCBLOCK; } require 'data:text/plain;base64,'. base64_encode( -<<<'TAG_HANDLER' + << Date: Tue, 13 Nov 2012 17:09:05 +0200 Subject: [PATCH 09/10] Renamed LongDescription to Description, to better serve its new dual role as "holder for a place where inline tags can occur"; Removed Tag::setDocblock() in favor of an additional constructor argument that defaults to NULL; Tag::createInstance() and Description's constructor now have a second argument, allowing the specification of an owning DocBlock; Description::getParsedContents() assigns the Description's owning DocBlock object when creating tags. --- src/phpDocumentor/Reflection/DocBlock.php | 6 +-- .../{LongDescription.php => Description.php} | 16 ++++-- src/phpDocumentor/Reflection/DocBlock/Tag.php | 50 +++++++++---------- ...escriptionTest.php => DescriptionTest.php} | 26 +++++----- 4 files changed, 50 insertions(+), 48 deletions(-) rename src/phpDocumentor/Reflection/DocBlock/{LongDescription.php => Description.php} (91%) rename tests/phpDocumentor/Reflection/DocBlock/{LongDescriptionTest.php => DescriptionTest.php} (91%) diff --git a/src/phpDocumentor/Reflection/DocBlock.php b/src/phpDocumentor/Reflection/DocBlock.php index fa2a4cb..b55b470 100644 --- a/src/phpDocumentor/Reflection/DocBlock.php +++ b/src/phpDocumentor/Reflection/DocBlock.php @@ -83,7 +83,7 @@ class DocBlock implements \Reflector list($short, $long, $tags) = $this->splitDocBlock($docblock); $this->short_description = $short; - $this->long_description = new DocBlock\LongDescription($long); + $this->long_description = new DocBlock\Description($long); $this->parseTags($tags); $this->namespace = $namespace; @@ -222,9 +222,7 @@ class DocBlock implements \Reflector // create proper Tag objects foreach ($result as $key => $tag_line) { - $tag = DocBlock\Tag::createInstance($tag_line); - $tag->setDocBlock($this); - $result[$key] = $tag; + $result[$key] = DocBlock\Tag::createInstance($tag_line, $this); } } diff --git a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php b/src/phpDocumentor/Reflection/DocBlock/Description.php similarity index 91% rename from src/phpDocumentor/Reflection/DocBlock/LongDescription.php rename to src/phpDocumentor/Reflection/DocBlock/Description.php index 3c26035..b9cad7d 100644 --- a/src/phpDocumentor/Reflection/DocBlock/LongDescription.php +++ b/src/phpDocumentor/Reflection/DocBlock/Description.php @@ -13,13 +13,13 @@ namespace phpDocumentor\Reflection\DocBlock; /** - * Parses a Long Description of a DocBlock. + * Parses a Description of a DocBlock or tag. * * @author Mike van Riel * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ -class LongDescription implements \Reflector +class Description implements \Reflector { /** @var string */ protected $contents = ''; @@ -30,15 +30,20 @@ class LongDescription implements \Reflector /** @var \phpDocumentor\Reflection\DocBlock\Tags[] */ protected $tags = array(); + /** @var DocBlock The DocBlock which this description belongs to. */ + protected $docblock = null; + /** * Parses the string for inline tags and if the Markdown class is included; * format the found text. * - * @param string $content the DocBlock contents without asterisks. + * @param string $content The DocBlock contents without asterisks. + * @param DocBlock $docblock The DocBlock which this description belongs to. */ - public function __construct($content) + public function __construct($content, DocBlock $docblock = null) { $this->contents = trim($content); + $this->docblock = $docblock; } /** @@ -97,7 +102,8 @@ class LongDescription implements \Reflector ); for ($i=1, $l = count($this->parsedContents); $i<$l; $i += 2) { $this->parsedContents[$i] = Tag::createInstance( - $this->parsedContents[$i] + $this->parsedContents[$i], + $this->docblock ); } diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag.php b/src/phpDocumentor/Reflection/DocBlock/Tag.php index 1c8be4a..4f0e26e 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag.php @@ -12,6 +12,8 @@ namespace phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock; + /** * Parses a tag definition for a DocBlock. * @@ -36,8 +38,8 @@ class Tag implements \Reflector /** @var int Line number of the tag */ protected $line_number = 0; - /** @var \phpDocumentor\Reflection\DocBlock docblock class */ - protected $docblock; + /** @var DocBlock The DocBlock which this tag belongs to. */ + protected $docblock = null; /** * @var array An array with a tag as a key, and an FQCN to a class that @@ -78,14 +80,17 @@ class Tag implements \Reflector /** * Factory method responsible for instantiating the correct sub type. * - * @param string $tag_line The text for this tag, including description. + * @param string $tag_line The text for this tag, including description. + * @param DocBlock $docblock The DocBlock which this tag belongs to. * * @throws \InvalidArgumentException if an invalid tag line was presented. * - * @return \phpDocumentor\Reflection\DocBlock\Tag + * @return static A new tag object. */ - final public static function createInstance($tag_line) - { + final public static function createInstance( + $tag_line, + DocBlock $docblock = null + ) { if (!preg_match( '/^@([\w\-\_\\\\]+)(?:\s*([^\s].*)|$)?/us', $tag_line, @@ -100,10 +105,15 @@ class Tag implements \Reflector $handler = self::$tagHandlerMappings[$matches[1]]; return new $handler( $matches[1], - isset($matches[2]) ? $matches[2] : '' + isset($matches[2]) ? $matches[2] : '', + $docblock ); } - return new self($matches[1], isset($matches[2]) ? $matches[2] : ''); + return new self( + $matches[1], + isset($matches[2]) ? $matches[2] : '', + $docblock + ); } /** @@ -141,14 +151,16 @@ class Tag implements \Reflector /** * Parses a tag and populates the member variables. * - * @param string $type Name of the tag. - * @param string $content The contents of the given tag. + * @param string $type Name of the tag. + * @param string $content The contents of the given tag. + * @param DocBlock $docblock The DocBlock which this tag belongs to. */ - public function __construct($type, $content) + public function __construct($type, $content, DocBlock $docblock = null) { $this->tag = $type; $this->content = $content; $this->description = $content; + $this->docblock = $docblock; } /** @@ -190,7 +202,7 @@ class Tag implements \Reflector public function getParsedDescription() { if (null === $this->parsedDescription) { - $description = new LongDescription($this->description); + $description = new Description($this->description, $this->docblock); $this->parsedDescription = $description->getParsedContents(); } return $this->parsedDescription; @@ -218,20 +230,6 @@ class Tag implements \Reflector return $this->line_number; } - /** - * Inject the docblock class - * - * This exposes some common functionality contained in the docblock abstract. - * - * @param object $docblock Object containing the DocBlock. - * - * @return void - */ - public function setDocBlock($docblock) - { - $this->docblock = $docblock; - } - /** * Builds a string representation of this object. * diff --git a/tests/phpDocumentor/Reflection/DocBlock/LongDescriptionTest.php b/tests/phpDocumentor/Reflection/DocBlock/DescriptionTest.php similarity index 91% rename from tests/phpDocumentor/Reflection/DocBlock/LongDescriptionTest.php rename to tests/phpDocumentor/Reflection/DocBlock/DescriptionTest.php index b262403..8b48060 100644 --- a/tests/phpDocumentor/Reflection/DocBlock/LongDescriptionTest.php +++ b/tests/phpDocumentor/Reflection/DocBlock/DescriptionTest.php @@ -1,6 +1,6 @@ * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com) * @license http://www.opensource.org/licenses/mit-license.php MIT * @link http://phpdoc.org */ -class LongDescriptionTest extends \PHPUnit_Framework_TestCase +class DescriptionTest extends \PHPUnit_Framework_TestCase { public function testConstruct() { $fixture = <<assertSame($fixture, $object->getContents()); $parsedContents = $object->getParsedContents(); @@ -41,7 +41,7 @@ LONGDESC; This is text for a {@link http://phpdoc.org/ description} that uses inline tags. LONGDESC; - $object = new LongDescription($fixture); + $object = new Description($fixture); $this->assertSame($fixture, $object->getContents()); $parsedContents = $object->getParsedContents(); @@ -64,7 +64,7 @@ tags.', {@link http://phpdoc.org/ This} is text for a description that uses inline tags. LONGDESC; - $object = new LongDescription($fixture); + $object = new Description($fixture); $this->assertSame($fixture, $object->getContents()); $parsedContents = $object->getParsedContents(); @@ -88,7 +88,7 @@ tags.', This is text for a description with {@internal inline tag with {@link http://phpdoc.org another inline tag} in it}. LONGDESC; - $object = new LongDescription($fixture); + $object = new Description($fixture); $this->assertSame($fixture, $object->getContents()); $parsedContents = $object->getParsedContents(); @@ -119,7 +119,7 @@ LONGDESC; $fixture = <<assertSame($fixture, $object->getContents()); $parsedContents = $object->getParsedContents(); @@ -133,7 +133,7 @@ LONGDESC; This is text for a description containing {@internal inline tag that has { that is literal}. LONGDESC; - $object = new LongDescription($fixture); + $object = new Description($fixture); $this->assertSame($fixture, $object->getContents()); $parsedContents = $object->getParsedContents(); @@ -160,7 +160,7 @@ is literal'), $fixture = <<assertSame($fixture, $object->getContents()); $parsedContents = $object->getParsedContents(); @@ -177,7 +177,7 @@ LONGDESC; This is text for a description with {@internal inline tag with {} that is not an inline tag}. LONGDESC; - $object = new LongDescription($fixture); + $object = new Description($fixture); $this->assertSame($fixture, $object->getContents()); $parsedContents = $object->getParsedContents(); @@ -204,7 +204,7 @@ inline tag'), $fixture = <<assertSame($fixture, $object->getContents()); $parsedContents = $object->getParsedContents(); @@ -221,7 +221,7 @@ LONGDESC; This is text for a description with an {@internal inline tag with literal {{@}link{} in it}. LONGDESC; - $object = new LongDescription($fixture); + $object = new Description($fixture); $this->assertSame($fixture, $object->getContents()); $parsedContents = $object->getParsedContents(); From 878e24d40dcddfdb1f2b0749d6225e1cdaec649b Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Tue, 13 Nov 2012 19:00:49 +0200 Subject: [PATCH 10/10] Made all tag handlers call Tag::__construct() rather than "manually" duplicating it; Tag::__construct() trims the description (as is common for most tag handlers), while the original contents is still in the $content property; Added the DocBlock argument to all tag handlers. --- src/phpDocumentor/Reflection/DocBlock/Tag.php | 2 +- .../Reflection/DocBlock/Tag/AuthorTag.php | 16 +++++++++++----- .../Reflection/DocBlock/Tag/LinkTag.php | 12 +++++++----- .../Reflection/DocBlock/Tag/MethodTag.php | 15 +++++++++------ .../Reflection/DocBlock/Tag/ParamTag.php | 15 +++++++++------ .../Reflection/DocBlock/Tag/ReturnTag.php | 14 +++++++------- .../Reflection/DocBlock/Tag/SeeTag.php | 11 ++++++----- .../Reflection/DocBlock/Tag/VarTag.php | 15 +++++++++------ 8 files changed, 59 insertions(+), 41 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag.php b/src/phpDocumentor/Reflection/DocBlock/Tag.php index 4f0e26e..272132a 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag.php @@ -159,7 +159,7 @@ class Tag implements \Reflector { $this->tag = $type; $this->content = $content; - $this->description = $content; + $this->description = trim($content); $this->docblock = $docblock; } diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/AuthorTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/AuthorTag.php index a1ebc99..5819e55 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/AuthorTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/AuthorTag.php @@ -12,6 +12,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlock\Tag; /** @@ -32,13 +33,18 @@ class AuthorTag extends Tag /** * Parses a tag and populates the member variables. * - * @param string $type Tag identifier for this tag (should be 'author'). - * @param string $content The contents of the given tag. + * @param string $type Tag identifier for this tag (should be 'author'). + * @param string $content Contents for this tag. + * @param DocBlock $docblock The DocBlock which this tag belongs to. */ - public function __construct($type, $content) + public function __construct($type, $content, DocBlock $docblock = null) { - parent::__construct($type, $content); - if (preg_match('/^([^\<]*)(\<([^\>]*)\>)?$/', $content, $matches)) { + parent::__construct($type, $content, $docblock); + if (preg_match( + '/^([^\<]*)(\<([^\>]*)\>)?$/', + $this->description, + $matches + )) { $this->name = trim($matches[1]); if (isset($matches[3])) { $this->email = trim($matches[3]); diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php index 04d64fc..ce41ce4 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/LinkTag.php @@ -12,6 +12,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlock\Tag; /** @@ -29,13 +30,14 @@ class LinkTag extends Tag /** * Parses a tag and populates the member variables. * - * @param string $type Tag identifier for this tag (should be 'link'). - * @param string $content The contents of the given tag. + * @param string $type Tag identifier for this tag (should be 'link'). + * @param string $content Contents for this tag. + * @param DocBlock $docblock The DocBlock which this tag belongs to. */ - public function __construct($type, $content) + public function __construct($type, $content, DocBlock $docblock = null) { - $this->tag = $type; - $pieces = explode(' ', $content); + parent::__construct($type, $content, $docblock); + $pieces = explode(' ', $this->description); if (count($pieces) > 1) { $this->link = array_shift($pieces); diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php index fba1070..e659977 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/MethodTag.php @@ -12,6 +12,9 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Tag; + /** * Reflection class for a @method in a Docblock. * @@ -31,13 +34,13 @@ class MethodTag extends ReturnTag /** * Parses a tag and populates the member variables. * - * @param string $type Tag identifier for this tag (should be 'method'). - * @param string $content The contents of the given tag. + * @param string $type Tag identifier for this tag (should be 'method'). + * @param string $content Contents for this tag. + * @param DocBlock $docblock The DocBlock which this tag belongs to. */ - public function __construct($type, $content) + public function __construct($type, $content, DocBlock $docblock = null) { - $this->tag = $type; - $this->content = $content; + Tag::__construct($type, $content, $docblock); $matches = array(); // 1. none or more whitespace @@ -51,7 +54,7 @@ class MethodTag extends ReturnTag if (preg_match( '/^[\s]*(?:([\w\|_\\\\]+)[\s]+)?(?:[\w_]+\(\)[\s]+)?([\w\|_\\\\]+)' .'\(([^\)]*)\)[\s]*(.*)/u', - $content, + $this->description, $matches )) { list( diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php index 12edd11..ec1ac5c 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php @@ -12,6 +12,9 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Tag; + /** * Reflection class for a @param tag in a Docblock. * @@ -29,16 +32,16 @@ class ParamTag extends ReturnTag /** * Parses a tag and populates the member variables. * - * @param string $type Tag identifier for this tag (should be 'param'). - * @param string $content Contents for this tag. + * @param string $type Tag identifier for this tag (should be 'param'). + * @param string $content Contents for this tag. + * @param DocBlock $docblock The DocBlock which this tag belongs to. */ - public function __construct($type, $content) + public function __construct($type, $content, DocBlock $docblock = null) { - $this->tag = $type; - $this->content = $content; + Tag::__construct($type, $content, $docblock); $content = preg_split( '/(\s+)/u', - trim($content), + $this->description, 3, PREG_SPLIT_DELIM_CAPTURE ); diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php index da22677..df169fa 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php @@ -12,6 +12,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlock\Tag; /** @@ -29,15 +30,14 @@ class ReturnTag extends Tag /** * Parses a tag and populates the member variables. * - * @param string $type Tag identifier for this tag (should be 'return'). - * @param string $content Contents for this tag. + * @param string $type Tag identifier for this tag (should be 'return'). + * @param string $content Contents for this tag. + * @param DocBlock $docblock The DocBlock which this tag belongs to. */ - public function __construct($type, $content) + public function __construct($type, $content, DocBlock $docblock = null) { - $this->tag = $type; - $this->content = $content; - - $content = preg_split('/[\ \t]+/u', trim($content), 2); + parent::__construct($type, $content, $docblock); + $content = preg_split('/[\ \t]+/u', $this->description, 2); // any output is considered a type $this->type = array_shift($content); diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php index 6c89947..f73c3bb 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/SeeTag.php @@ -12,6 +12,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock; use phpDocumentor\Reflection\DocBlock\Tag; /** @@ -29,13 +30,13 @@ class SeeTag extends Tag /** * Parses a tag and populates the member variables. * - * @param string $type Tag identifier for this tag (should be 'see'). - * @param string $content Contents for this tag. + * @param string $type Tag identifier for this tag (should be 'see'). + * @param string $content Contents for this tag. + * @param DocBlock $docblock The DocBlock which this tag belongs to. */ - public function __construct($type, $content) + public function __construct($type, $content, DocBlock $docblock = null) { - $this->tag = $type; - $this->content = $content; + parent::__construct($type, $content, $docblock); $content = preg_split('/\s+/u', $content); // any output is considered a type diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php index f7e2493..d64cfa0 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/VarTag.php @@ -12,6 +12,9 @@ namespace phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Tag; + /** * Reflection class for a @var tag in a Docblock. * @@ -24,14 +27,14 @@ class VarTag extends ParamTag /** * Parses a tag and populates the member variables. * - * @param string $type Tag identifier for this tag (should be 'var'). - * @param string $content Contents for this tag. + * @param string $type Tag identifier for this tag (should be 'var'). + * @param string $content Contents for this tag. + * @param DocBlock $docblock The DocBlock which this tag belongs to. */ - public function __construct($type, $content) + public function __construct($type, $content, DocBlock $docblock = null) { - $this->tag = $type; - $this->content = $content; - $content = preg_split('/\s+/u', $content); + Tag::__construct($type, $content, $docblock); + $content = preg_split('/\s+/u', $this->description); if (count($content) == 0) { return;