From 2e7a75ba0aeec966ee10fc89ef0c6805b5fbec67 Mon Sep 17 00:00:00 2001 From: Brown Date: Tue, 27 Nov 2018 12:20:06 -0500 Subject: [PATCH] Prevent Psalm-specific types leaking into PHPDoc --- src/Psalm/Type/Atomic/GenericTrait.php | 6 +++++- src/Psalm/Type/Atomic/TLiteralFloat.php | 13 +++++++++++++ src/Psalm/Type/Atomic/TLiteralInt.php | 13 +++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Type/Atomic/GenericTrait.php b/src/Psalm/Type/Atomic/GenericTrait.php index be6429dfe..431a585ad 100644 --- a/src/Psalm/Type/Atomic/GenericTrait.php +++ b/src/Psalm/Type/Atomic/GenericTrait.php @@ -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); diff --git a/src/Psalm/Type/Atomic/TLiteralFloat.php b/src/Psalm/Type/Atomic/TLiteralFloat.php index 121c59ade..13e8cd40c 100644 --- a/src/Psalm/Type/Atomic/TLiteralFloat.php +++ b/src/Psalm/Type/Atomic/TLiteralFloat.php @@ -31,4 +31,17 @@ class TLiteralFloat extends TFloat { return 'float(' . $this->value . ')'; } + + /** + * @param string|null $namespace + * @param array $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'; + } } diff --git a/src/Psalm/Type/Atomic/TLiteralInt.php b/src/Psalm/Type/Atomic/TLiteralInt.php index 3a03cd82f..a5d737c3d 100644 --- a/src/Psalm/Type/Atomic/TLiteralInt.php +++ b/src/Psalm/Type/Atomic/TLiteralInt.php @@ -31,4 +31,17 @@ class TLiteralInt extends TInt { return 'int(' . $this->value . ')'; } + + /** + * @param string|null $namespace + * @param array $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'; + } }