mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +01:00
Add support for "never" type in the BuilderHelpers::normalizeType()
This commit is contained in:
parent
e69ebbbfd9
commit
c35cc4b2cb
@ -189,7 +189,7 @@ final class BuilderHelpers
|
||||
}
|
||||
|
||||
$builtinTypes = [
|
||||
'array', 'callable', 'string', 'int', 'float', 'bool', 'iterable', 'void', 'object', 'mixed'
|
||||
'array', 'callable', 'string', 'int', 'float', 'bool', 'iterable', 'void', 'object', 'mixed', 'never',
|
||||
];
|
||||
|
||||
$lowerType = strtolower($type);
|
||||
@ -199,12 +199,11 @@ final class BuilderHelpers
|
||||
$type = self::normalizeName($type);
|
||||
}
|
||||
|
||||
if ($nullable && (string) $type === 'void') {
|
||||
throw new \LogicException('void type cannot be nullable');
|
||||
}
|
||||
|
||||
if ($nullable && (string) $type === 'mixed') {
|
||||
throw new \LogicException('mixed type cannot be nullable');
|
||||
$notNullableTypes = [
|
||||
'void', 'mixed', 'never',
|
||||
];
|
||||
if ($nullable && in_array((string) $type, $notNullableTypes)) {
|
||||
throw new \LogicException(sprintf('%s type cannot be nullable', $type));
|
||||
}
|
||||
|
||||
return $nullable ? new NullableType($type) : $type;
|
||||
|
@ -126,6 +126,7 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEquals(new Node\Identifier('void'), BuilderHelpers::normalizeType('void'));
|
||||
$this->assertEquals(new Node\Identifier('object'), BuilderHelpers::normalizeType('object'));
|
||||
$this->assertEquals(new Node\Identifier('mixed'), BuilderHelpers::normalizeType('mixed'));
|
||||
$this->assertEquals(new Node\Identifier('never'), BuilderHelpers::normalizeType('never'));
|
||||
|
||||
$intIdentifier = new Node\Identifier('int');
|
||||
$this->assertSame($intIdentifier, BuilderHelpers::normalizeType($intIdentifier));
|
||||
@ -161,6 +162,12 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase
|
||||
BuilderHelpers::normalizeType('?mixed');
|
||||
}
|
||||
|
||||
public function testNormalizeTypeNullableNever() {
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->expectExceptionMessage('never type cannot be nullable');
|
||||
BuilderHelpers::normalizeType('?never');
|
||||
}
|
||||
|
||||
public function testNormalizeValue() {
|
||||
$expression = new Scalar\LNumber(1);
|
||||
$this->assertSame($expression, BuilderHelpers::normalizeValue($expression));
|
||||
|
Loading…
Reference in New Issue
Block a user