mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Reverted the move of explode() into Return, and moved the implode() into Collection's new __toString() method instead;
Also had to made type resolution lazy, as a pleasant side effect.
This reverts commit db20ae39fb.
This commit is contained in:
@@ -14,6 +14,7 @@ namespace phpDocumentor\Reflection\DocBlock\Tag;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\Type\Collection;
|
||||
|
||||
/**
|
||||
* Reflection class for a @return tag in a Docblock.
|
||||
@@ -24,8 +25,11 @@ use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
*/
|
||||
class ReturnTag extends Tag
|
||||
{
|
||||
/** @var string */
|
||||
/** @var string The raw type component. */
|
||||
protected $type = '';
|
||||
|
||||
/** @var Collection The parsed type component. */
|
||||
protected $types = null;
|
||||
|
||||
/**
|
||||
* Parses a tag and populates the member variables.
|
||||
@@ -52,13 +56,8 @@ class ReturnTag extends Tag
|
||||
*/
|
||||
public function getTypes()
|
||||
{
|
||||
$types = new \phpDocumentor\Reflection\DocBlock\Type\Collection(
|
||||
explode('|', $this->type),
|
||||
$this->docblock ? $this->docblock->getNamespace() : null,
|
||||
$this->docblock ? $this->docblock->getNamespaceAliases() : array()
|
||||
);
|
||||
|
||||
return $types->getArrayCopy();
|
||||
$this->refreshTypes();
|
||||
return $this->types->getArrayCopy();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,6 +67,23 @@ class ReturnTag extends Tag
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return implode('|', $this->getTypes());
|
||||
$this->refreshTypes();
|
||||
return (string) $this->types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the type, if needed.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function refreshTypes()
|
||||
{
|
||||
if (null === $this->types) {
|
||||
$this->types = new Collection(
|
||||
array($this->type),
|
||||
$this->docblock ? $this->docblock->getNamespace() : null,
|
||||
$this->docblock ? $this->docblock->getNamespaceAliases() : array()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ namespace phpDocumentor\Reflection\DocBlock\Type;
|
||||
*/
|
||||
class Collection extends \ArrayObject
|
||||
{
|
||||
/** @var string Definition of the OR operator for types */
|
||||
const OPERATOR_OR = '|';
|
||||
|
||||
/** @var string Definition of the ARRAY operator for types */
|
||||
const OPERATOR_ARRAY = '[]';
|
||||
|
||||
@@ -164,11 +167,27 @@ class Collection extends \ArrayObject
|
||||
.var_export($type, true)
|
||||
);
|
||||
}
|
||||
$expanded_type = $this->expand($type);
|
||||
if ($expanded_type) {
|
||||
$this[] = $expanded_type;
|
||||
|
||||
// separate the type by the OR operator
|
||||
$type_parts = explode(self::OPERATOR_OR, $type);
|
||||
foreach ($type_parts as $part) {
|
||||
$expanded_type = $this->expand($part);
|
||||
if ($expanded_type) {
|
||||
$this[] = $expanded_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the collection.
|
||||
*
|
||||
* @return string The resolved types across the collection, separated with
|
||||
* {@link self::OPERATOR_OR}.
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return implode(self::OPERATOR_OR, $this->getArrayCopy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyzes the given type and returns the FQCN variant.
|
||||
|
||||
Reference in New Issue
Block a user