-
Notifications
You must be signed in to change notification settings - Fork 127
Closed
Description
<?php
require "vendor/autoload.php";
$comment = '/**
* @return (string|Apple)
*/';
$block = new \phpDocumentor\Reflection\DocBlock($comment);
var_dump($block->getTagsByName("return")[0]->getType()); // \(string|\Apple)
$block = new \phpDocumentor\Reflection\DocBlock($comment, new \phpDocumentor\Reflection\DocBlock\Context("A"));
var_dump($block->getTagsByName("return")[0]->getType()); // \A\(string|\A\Apple)
Generic types are parsed incorrectly as well; and there may be other issues. Since PSR-5 is still a draft, I didn't expect 100% compliance, but the values returned now are pretty useless. Not getting correctly parsed types blocks my project, so I'd gladly help out with this.
The current API for getting types is getType: string
and getTypes: Type\Collection
(the latter basically being string[]
). Unfortunately, PSR-5's types are more complicated... As a consumer I want an API that allows me to handle complex types. Something like:
interface TypeInterface
class ScalarType implements TypeInterface {
public function getType() // 'string', 'int', etc.
}
class ArrayOfType implements TypeInterface {
public function getItemType() // TypeInterface of the items
}
class GenericType implements TypeInterface {
public function getTemplateType()
public function getParameterTypes()
}
...
I think this belongs in the ReflectionDocBlock library, but I'd like some feedback before I implement this.
Metadata
Metadata
Assignees
Labels
No labels