From 45cf35350c190373711cd3d9e980fcbb9923befb Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 27 Jan 2019 17:26:32 -0500 Subject: [PATCH] Add non-internal endpoint for parsing types --- src/Psalm/Codebase.php | 5 +++++ tests/TypeParseTest.php | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index e782f1b44..33a6b1264 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -416,6 +416,11 @@ class Codebase } } + public static function getPsalmTypeFromReflection(?\ReflectionType $type) : Type\Union + { + return \Psalm\Internal\Codebase\Reflection::getPsalmTypeFromReflectionType($type); + } + /** * @param string $file_path * diff --git a/tests/TypeParseTest.php b/tests/TypeParseTest.php index 044d36e06..8ca6e6b6a 100644 --- a/tests/TypeParseTest.php +++ b/tests/TypeParseTest.php @@ -717,7 +717,7 @@ class TypeParseTest extends TestCase public function testReflectionTypeParse() { /** @psalm-suppress UnusedParam */ - function someFunction(string $param, array $param2, \stdClass $param3 = null) : string + function someFunction(string $param, array $param2, int $param3 = null) : string { return "hello"; } @@ -727,22 +727,22 @@ class TypeParseTest extends TestCase $this->assertSame( 'string', - (string) Reflection::getPsalmTypeFromReflectionType($reflectionParams[0]->getType()) + (string) \Psalm\Codebase::getPsalmTypeFromReflection($reflectionParams[0]->getType()) ); $this->assertSame( 'array', - (string) Reflection::getPsalmTypeFromReflectionType($reflectionParams[1]->getType()) + (string) \Psalm\Codebase::getPsalmTypeFromReflection($reflectionParams[1]->getType()) ); $this->assertSame( - 'null|stdClass', - (string) Reflection::getPsalmTypeFromReflectionType($reflectionParams[2]->getType()) + 'null|int', + (string) \Psalm\Codebase::getPsalmTypeFromReflection($reflectionParams[2]->getType()) ); $this->assertSame( 'string', - (string) Reflection::getPsalmTypeFromReflectionType($reflectionFunc->getReturnType()) + (string) \Psalm\Codebase::getPsalmTypeFromReflection($reflectionFunc->getReturnType()) ); }