1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Prevent Psalm-specific types leaking into PHPDoc

This commit is contained in:
Brown 2018-11-27 12:20:06 -05:00
parent a83387b187
commit 2e7a75ba0a
3 changed files with 31 additions and 1 deletions

View File

@ -58,6 +58,10 @@ trait GenericTrait
? parent::toNamespacedString($namespace, $aliased_classes, $this_class, $use_phpdoc_format)
: $this->value;
if ($base_value === 'non-empty-string') {
$base_value = 'array';
}
if ($use_phpdoc_format) {
if ($this instanceof TNamedObject) {
return $base_value;
@ -66,7 +70,7 @@ trait GenericTrait
$value_type = $this->type_params[1];
if ($value_type->isMixed()) {
return $this->value;
return $base_value;
}
$value_type_string = $value_type->toNamespacedString($namespace, $aliased_classes, $this_class, true);

View File

@ -31,4 +31,17 @@ class TLiteralFloat extends TFloat
{
return 'float(' . $this->value . ')';
}
/**
* @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)
{
return 'float';
}
}

View File

@ -31,4 +31,17 @@ class TLiteralInt extends TInt
{
return 'int(' . $this->value . ')';
}
/**
* @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)
{
return 'int';
}
}