Skip to content

Commit 183824d

Browse files
committed
Restores future support for annotations
In #89 the regex to parse tags was to strict. The first character after a tag had to be a single string. Annotations typically start with a parentheses. Only character not allowed after a tag is a [.
1 parent 48d3720 commit 183824d

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/DocBlock/StandardTagFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ public function create($tagLine, TypeContext $context = null)
113113

114114
list($tagName, $tagBody) = $this->extractTagParts($tagLine);
115115

116+
if ($tagBody[0] === '[') {
117+
throw new \InvalidArgumentException(
118+
'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors'
119+
);
120+
}
121+
116122
return $this->createTag($tagBody, $tagName, $context);
117123
}
118124

@@ -161,7 +167,7 @@ public function registerTagHandler($tagName, $handler)
161167
private function extractTagParts($tagLine)
162168
{
163169
$matches = array();
164-
if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s+([^\s].*)|$)/us', $tagLine, $matches)) {
170+
if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) {
165171
throw new \InvalidArgumentException(
166172
'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors'
167173
);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @copyright 2010-2017 Mike van Riel<[email protected]>
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace phpDocumentor\Reflection;
14+
15+
/**
16+
* @coversNothing
17+
*/
18+
final class DocblocksWithAnnotationsTest extends \PHPUnit_Framework_TestCase
19+
{
20+
public function testDocblockWithAnnotations()
21+
{
22+
$docComment = <<<DOCCOMMENT
23+
/**
24+
* @var \DateTime[]
25+
* @Groups({"a", "b"})
26+
*/
27+
DOCCOMMENT;
28+
29+
30+
$factory = DocBlockFactory::createInstance();
31+
$docblock = $factory->create($docComment);
32+
33+
$this->assertCount(2, $docblock->getTags());
34+
}
35+
}

0 commit comments

Comments
 (0)