From 183824db76118b9dddffc7e522b91fa175f75119 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 4 Aug 2017 22:16:41 +0200 Subject: [PATCH] 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 [. --- src/DocBlock/StandardTagFactory.php | 8 ++++- .../DocblocksWithAnnotationsTest.php | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/integration/DocblocksWithAnnotationsTest.php diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index a438d7d..786caef 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -113,6 +113,12 @@ final class StandardTagFactory implements TagFactory list($tagName, $tagBody) = $this->extractTagParts($tagLine); + if ($tagBody[0] === '[') { + throw new \InvalidArgumentException( + 'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors' + ); + } + return $this->createTag($tagBody, $tagName, $context); } @@ -161,7 +167,7 @@ final class StandardTagFactory implements TagFactory private function extractTagParts($tagLine) { $matches = array(); - if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s+([^\s].*)|$)/us', $tagLine, $matches)) { + if (! preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\s*([^\s].*)|$)/us', $tagLine, $matches)) { throw new \InvalidArgumentException( 'The tag "' . $tagLine . '" does not seem to be wellformed, please check it for errors' ); diff --git a/tests/integration/DocblocksWithAnnotationsTest.php b/tests/integration/DocblocksWithAnnotationsTest.php new file mode 100644 index 0000000..3c40f4f --- /dev/null +++ b/tests/integration/DocblocksWithAnnotationsTest.php @@ -0,0 +1,35 @@ + + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link http://phpdoc.org + */ + +namespace phpDocumentor\Reflection; + +/** + * @coversNothing + */ +final class DocblocksWithAnnotationsTest extends \PHPUnit_Framework_TestCase +{ + public function testDocblockWithAnnotations() + { + $docComment = <<create($docComment); + + $this->assertCount(2, $docblock->getTags()); + } +}