1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Properly namespace TClassString output

This commit is contained in:
Matthew Brown 2019-01-02 20:25:42 -05:00
parent 53749bd5c5
commit bfb1eb9be2

View File

@ -56,6 +56,39 @@ class TClassString extends TString
return 'string';
}
/**
* @param string|null $namespace
* @param array<string> $aliased_classes
* @param string|null $this_class
* @param bool $use_phpdoc_format
*
* @return string
*/
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
{
if ($this->extends === 'object') {
return 'class-string';
}
if ($namespace && stripos($this->extends, $namespace . '\\') === 0) {
return 'class-string<' . preg_replace(
'/^' . preg_quote($namespace . '\\') . '/i',
'',
$this->extends
) . '>';
}
if (!$namespace && stripos($this->extends, '\\') === false) {
return 'class-string<' . $this->extends . '>';
}
if (isset($aliased_classes[strtolower($this->extends)])) {
return 'class-string<' . $aliased_classes[strtolower($this->extends)] . '>';
}
return 'class-string<\\' . $this->extends . '>';
}
/**
* @return bool
*/