Removed DocBlock::expandType() and associated tests, as previously advised by @mvriel;

Added tests for generic Tag objects, and a few others;
Increased total coverage by more appropriate use of @covers annotations.
This commit is contained in:
Vasil Rangelov
2012-11-10 23:19:36 +02:00
parent 6e1bb192b3
commit f11936eaae
13 changed files with 231 additions and 182 deletions
+1 -80
View File
@@ -66,7 +66,7 @@ class DocBlock implements \Reflector
public function __construct(
$docblock,
$namespace = '\\',
$namespace_aliases = array()
array $namespace_aliases = array()
) {
if (is_object($docblock)) {
if (!method_exists($docblock, 'getDocComment')) {
@@ -304,85 +304,6 @@ class DocBlock implements \Reflector
return false;
}
/**
* Tries to expand a type to it's full namespaced equivalent (FQCN).
*
* This method will take the given type and examine the current namespace
* and namespace aliases to see whether it should expand it into a FQCN
* as defined by the rules in PHP.
*
* @param string $type Type to expand into full namespaced
* equivalent.
* @param string[] $ignore_keywords Whether to ignore given keywords, when
* null it will use the default keywords:
* 'string', 'int', 'integer', 'bool', 'boolean', 'float', 'double',
* 'object', 'mixed', 'array', 'resource', 'void', 'null', 'callback',
* 'false', 'true', 'self', '$this', 'callable'.
* Default value for this parameter is null.
*
* @return string
*/
public function expandType($type, $ignore_keywords = null)
{
if ($type === null) {
return null;
}
if ($ignore_keywords === null) {
$ignore_keywords = array(
'string', 'int', 'integer', 'bool', 'boolean', 'float',
'double', 'object', 'mixed', 'array', 'resource', 'void',
'null', 'callback', 'false', 'true', 'self', '$this', 'callable'
);
}
$namespace = '\\';
if ($this->namespace != 'default' && $this->namespace != 'global') {
$namespace = rtrim($this->namespace, '\\') . '\\';
}
$type = explode('|', $type);
foreach ($type as &$item) {
$item = trim($item);
// add support for array notation
$is_array = false;
if (substr($item, -2) == '[]') {
$item = substr($item, 0, -2);
$is_array = true;
}
if ((substr($item, 0, 1) != '\\')
&& (!in_array(strtolower($item), $ignore_keywords))
) {
$type_parts = explode('\\', $item);
// if the first segment is an alias; replace with full name
if (isset($this->namespace_aliases[$type_parts[0]])) {
$type_parts[0] = $this->namespace_aliases[$type_parts[0]];
$item = implode('\\', $type_parts);
} else {
// otherwise prepend the current namespace
$item = $namespace . $item;
}
}
// full paths always start with a slash
if (isset($item[0]) && ($item[0] !== '\\')
&& (!in_array(strtolower($item), $ignore_keywords))
) {
$item = '\\' . $item;
}
// re-add the array notation markers
if ($is_array) {
$item .= '[]';
}
}
return implode('|', $type);
}
/**
* Builds a string representation of this object.
*