ZF2-110: Zend\Code\DocBlockScanner doesn't recognize anymore tags without values

Description

Component: Zend\Code (not listed)

The DocBlockScanner doesn't parse anymore tagnames wihout values such as this:

/** * @mytag */

They could be useful to tag code elements with custom tags as I was doing in zf 2.0 dev2

Comments

I believe this issue has been rectified already. I ran this unit test against Zend\Code\Scanner\DocBlockScanner:


/**
 * @group ZF2-110
 */
public function testDocBlockScannerParsesTagsWithNoValuesProperly()
{
    $docComment = <<getTags();
    $this->assertCount(1, $tags);
    $this->assertArrayHasKey('name', $tags[0]);
    $this->assertEquals('@mytag', $tags[0]['name']);
    $this->assertArrayHasKey('value', $tags[0]);
    $this->assertEquals('', $tags[0]['value']);
}

And it passed. I've issued a PR (https://github.com/zendframework/zf2/pull/820) to get this test added to the ZF2 test suite.

It seems I was wrong thinking that the problem was simply about tags without values. I still couldn't get my tags recognized with latest master and I found out that the issue was caused by a bug in the docblock cleaning function.

The regular expression used with single quotes failed to recognize tabs (\t) and also the cleaned docblock was not passed to the scanner.

Here is the fix:

diff --git a/library/Zend/Code/Reflection/DocBlockReflection.php b/library/Zend/Code/Reflection/DocBlockReflection.php
index 564ce62..63c35d4 100644
--- a/library/Zend/Code/Reflection/DocBlockReflection.php
+++ b/library/Zend/Code/Reflection/DocBlockReflection.php
@@ -259,10 +259,10 @@ class DocBlockReflection implements Reflection
         $docComment = $this->docComment; // localize variable
 
         // create a clean docComment
-        $this->cleanDocComment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ ]{0,1}(.*)?#', '$1', $docComment);
+        $this->cleanDocComment = preg_replace("#[ \t]*(?:\/\*\*|\*\/|\*)?[ ]{0,1}(.*)?#", '$1', $docComment);
         $this->cleanDocComment = ltrim($this->cleanDocComment, "\r\n"); // @todo should be changed to remove first and last empty line
 
-        $scanner = new DocBlockScanner($docComment);
+        $scanner = new DocBlockScanner($this->cleanDocComment);
         $this->shortDescription = ltrim($scanner->getShortDescription());
         $this->longDescription  = ltrim($scanner->getLongDescription());
         foreach ($scanner->getTags() as $tag) {

Hi Massimiliano,

You can send a Pull Request in Github with your patch. Anyway I tried to proposal but break some tests.

Regards.

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2445