Skip to content

Commit 8b9591a

Browse files
committed
Made the Tag::createInstance() create generic tag objects when there are uppercase letters in the tag name
(this fixes phpDocumentor/phpDocumentor#672).
1 parent 082c935 commit 8b9591a

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/phpDocumentor/Reflection/DocBlock/Tag.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public static function createInstance($tag_line)
6868
).'Tag';
6969
$class_name = 'phpDocumentor\\Reflection\\DocBlock\\Tag\\' . $tag_name;
7070

71-
return (@class_exists($class_name))
71+
return ($matches[1] === strtolower($matches[1])
72+
&& @class_exists($class_name))
7273
? new $class_name($matches[1], isset($matches[2]) ? $matches[2] : '')
7374
: new self($matches[1], isset($matches[2]) ? $matches[2] : '');
7475
}

tests/phpDocumentor/Reflection/DocBlockTest.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testConstructFromReflector()
6464
$this->assertTrue($object->hasTag('link'));
6565
$this->assertFalse($object->hasTag('category'));
6666
}
67-
67+
6868
/**
6969
* @expectedException \InvalidArgumentException
7070
*/
@@ -93,6 +93,45 @@ public function testDotSeperation()
9393
);
9494
}
9595

96+
public function testTagCaseSensitivity()
97+
{
98+
$fixture = <<<DOCBLOCK
99+
/**
100+
* This is a short description.
101+
*
102+
* This is a long description.
103+
*
104+
* @method null something()
105+
* @Method({"GET", "POST"})
106+
*/
107+
DOCBLOCK;
108+
$object = new DocBlock($fixture);
109+
$this->assertEquals(
110+
'This is a short description.',
111+
$object->getShortDescription()
112+
);
113+
$this->assertEquals(
114+
'This is a long description.',
115+
$object->getLongDescription()->getContents()
116+
);
117+
$tags = $object->getTags();
118+
$this->assertEquals(2, count($tags));
119+
$this->assertTrue($object->hasTag('method'));
120+
$this->assertTrue($object->hasTag('Method'));
121+
$this->assertInstanceOf(
122+
__NAMESPACE__ . '\DocBlock\Tag\MethodTag',
123+
$tags[0]
124+
);
125+
$this->assertInstanceOf(
126+
__NAMESPACE__ . '\DocBlock\Tag',
127+
$tags[1]
128+
);
129+
$this->assertNotInstanceOf(
130+
__NAMESPACE__ . '\DocBlock\Tag\MethodTag',
131+
$tags[1]
132+
);
133+
}
134+
96135
/**
97136
* Tests whether a type is expanded with the given namespace and that a
98137
* keyword is not expanded.

0 commit comments

Comments
 (0)