Zend\Code\DocBlockScanner doesn't recognize anymore tags without values #2445

Closed
zfbot opened this Issue Sep 28, 2012 · 4 comments

Comments

Projects
None yet
3 participants

zfbot commented Sep 28, 2012

Jira Information

Original Issue:ZF2-110
Issue Type:Bug
Reporter:mtorromeo
Created:12/05/11
Assignee:maks3w
Components:Zend\Code\Scanner

Description

Component: Zend\Code (not listed)

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

/**

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

zfbot commented Sep 28, 2012

(Originally posted by: adamlundrigan on 02/23/12)

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 = <<<EOB
/**
 * @mytag
 */
EOB;
    $tokenScanner = new DocBlockScanner($docComment);
    $tags = $tokenScanner->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 (zendframework#820) to get this test added to the ZF2 test suite.

zfbot commented Sep 28, 2012

(Originally posted by: mtorromeo on 02/23/12)

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) {

zfbot commented Sep 28, 2012

(Originally posted by: maks3w on 05/14/12)

Hi Massimiliano,

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

Regards.

zfbot commented Sep 28, 2012

This issue was ported from the ZF2 Jira Issue Tracker at
http://framework.zend.com/issues/browse/ZF2-110

Known GitHub users mentioned in the original message or comment:
@mtorromeo, @Maks3w, @adamlundrigan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment