1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Add non-internal endpoint for parsing types

This commit is contained in:
Matthew Brown 2019-01-27 17:26:32 -05:00
parent d8783c277f
commit 45cf35350c
2 changed files with 11 additions and 6 deletions

View File

@ -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
*

View File

@ -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<array-key, mixed>',
(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())
);
}