Skip to content

Commit 0380fd0

Browse files
committed
handle spaces within docblock tag content
1 parent be571e8 commit 0380fd0

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/DoctrineAnnotationCodingStandard/Helper/DocBlockHelper.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,13 @@ private static function fetchTagContent(array $tokens, int $tagPos): string
9797
$tagName = substr($tokens[$tagPos]['content'], 1);
9898

9999
$parenPos = strpos($tagName, '(');
100-
if ($parenPos !== false) {
101-
return substr($tagName, $parenPos);
102-
}
100+
$content = ($parenPos !== false) ? substr($tagName, $parenPos) : '';
103101

104-
if ($tokens[$tagPos + 1]['type'] !== 'T_DOC_COMMENT_WHITESPACE') {
105-
throw new ParseErrorException('Token after @tag not T_DOC_COMMENT_WHITESPACE');
106-
}
107-
108-
if ($tokens[$tagPos + 2]['type'] !== 'T_DOC_COMMENT_STRING') {
109-
throw new ParseErrorException('T_DOC_COMMENT_STRING expected after @tag');
102+
while (in_array($tokens[++$tagPos]['type'], ['T_DOC_COMMENT_WHITESPACE', 'T_DOC_COMMENT_STRING'])) {
103+
$content .= $tokens[$tagPos]['content'];
110104
}
111105

112-
return trim($tokens[$tagPos + 2]['content']);
106+
return trim($content);
113107
}
114108

115109
/**

tests/DoctrineAnnotationCodingStandard/Helper/DocBlockHelperTest.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,16 @@ public function testGetVarTagContentPlain()
3434
$this->assertSame('foo', DocBlockHelper::getVarTagContent($file, 1));
3535
}
3636

37-
/**
38-
* @expectedException \DoctrineAnnotationCodingStandard\Exception\ParseErrorException
39-
*/
4037
public function testGetVarTagNoContent()
4138
{
4239
$file = $this->checkString('/** @var*/', DummySniff::class);
43-
DocBlockHelper::getVarTagContent($file, 1);
40+
$this->assertSame('', DocBlockHelper::getVarTagContent($file, 1));
4441
}
4542

46-
/**
47-
* @expectedException \DoctrineAnnotationCodingStandard\Exception\ParseErrorException
48-
*/
4943
public function testGetVarTagWithJustSpaces()
5044
{
5145
$file = $this->checkString('/** @var */', DummySniff::class);
52-
DocBlockHelper::getVarTagContent($file, 1);
46+
$this->assertSame('', DocBlockHelper::getVarTagContent($file, 1));
5347
}
5448

5549
/**
@@ -96,6 +90,17 @@ public function testFindTagByClassWithSpaces()
9690
$this->assertSame('()', $tag);
9791
}
9892

93+
public function testFindTagByClassWithSpacesWithinContent()
94+
{
95+
$file = $this->checkString('/** @ORM\JoinColumn(onDelete="CASCADE", nullable=true) */', DummySniff::class);
96+
97+
$classMap = new ImportClassMap();
98+
$classMap->add('ORM', 'Doctrine\\ORM\\Mapping');
99+
100+
$tag = DocBlockHelper::findTagByClass($file, 1, $classMap, ORM\JoinColumn::class);
101+
$this->assertSame('(onDelete="CASCADE", nullable=true)', $tag);
102+
}
103+
99104
public function testFindTagMissing()
100105
{
101106
$file = $this->checkString('/** @ORM\Column() */', DummySniff::class);

0 commit comments

Comments
 (0)