예제 #1
0
    /**
     * @covers \phpDocumentor\Reflection\DocBlock
     * 
     * @return void
     */
    public function testConstruct()
    {
        $fixture = <<<DOCBLOCK
/**
 * This is a short description
 *
 * This is a long description
 *
 * @see \\MyClass
 * @return void
 */
DOCBLOCK;
        $object = new DocBlock($fixture, new Context('\\MyNamespace', array('PHPDoc' => '\\phpDocumentor')), new Location(2));
        $this->assertEquals('This is a short description', $object->getShortDescription());
        $this->assertEquals('This is a long description', $object->getLongDescription()->getContents());
        $this->assertCount(2, $object->getTags());
        $this->assertTrue($object->hasTag('see'));
        $this->assertTrue($object->hasTag('return'));
        $this->assertFalse($object->hasTag('category'));
        $this->assertSame('MyNamespace', $object->getContext()->getNamespace());
        $this->assertSame(array('PHPDoc' => '\\phpDocumentor'), $object->getContext()->getNamespaceAliases());
        $this->assertSame(2, $object->getLocation()->getLineNumber());
    }
예제 #2
0
 /**
  * Factory method responsible for instantiating the correct sub type.
  *
  * @param string   $tag_line The text for this tag, including description.
  * @param DocBlock $docblock The DocBlock which this tag belongs to.
  * @param Location $location Location of the tag.
  *
  * @throws \InvalidArgumentException if an invalid tag line was presented.
  *
  * @return static A new tag object.
  */
 public static final function createInstance($tag_line, DocBlock $docblock = null, Location $location = null)
 {
     if (!preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\\s*([^\\s].*)|$)?/us', $tag_line, $matches)) {
         throw new \InvalidArgumentException('Invalid tag_line detected: ' . $tag_line);
     }
     $handler = __CLASS__;
     if (isset(self::$tagHandlerMappings[$matches[1]])) {
         $handler = self::$tagHandlerMappings[$matches[1]];
     } elseif (isset($docblock)) {
         $tagName = (string) new Type\Collection(array($matches[1]), $docblock->getContext());
         if (isset(self::$tagHandlerMappings[$tagName])) {
             $handler = self::$tagHandlerMappings[$tagName];
         }
     }
     return new $handler($matches[1], isset($matches[2]) ? $matches[2] : '', $docblock, $location);
 }