Add support for the mixed type

This commit is contained in:
Máté Kocsis 2020-05-28 22:50:32 +02:00 committed by Nikita Popov
parent f33f081c8f
commit 32f89662f3
5 changed files with 24 additions and 5 deletions

View File

@ -1,7 +1,9 @@
Version 4.4.1-dev
-----------------
Nothing yet.
### Added
* Added support for the mixed type
Version 4.4.0 (2020-04-10)
--------------------------

View File

@ -183,7 +183,7 @@ final class BuilderHelpers
}
$builtinTypes = [
'array', 'callable', 'string', 'int', 'float', 'bool', 'iterable', 'void', 'object'
'array', 'callable', 'string', 'int', 'float', 'bool', 'iterable', 'void', 'object', 'mixed'
];
$lowerType = strtolower($type);
@ -197,6 +197,10 @@ final class BuilderHelpers
throw new \LogicException('void type cannot be nullable');
}
if ($nullable && (string) $type === 'mixed') {
throw new \LogicException('mixed type cannot be nullable');
}
return $nullable ? new NullableType($type) : $type;
}

View File

@ -648,7 +648,7 @@ abstract class ParserAbstract implements Parser
}
protected function handleBuiltinTypes(Name $name) {
$scalarTypes = [
$builtinTypes = [
'bool' => true,
'int' => true,
'float' => true,
@ -658,6 +658,7 @@ abstract class ParserAbstract implements Parser
'object' => true,
'null' => true,
'false' => true,
'mixed' => true,
];
if (!$name->isUnqualified()) {
@ -665,7 +666,7 @@ abstract class ParserAbstract implements Parser
}
$lowerName = $name->toLowerString();
if (!isset($scalarTypes[$lowerName])) {
if (!isset($builtinTypes[$lowerName])) {
return $name;
}

View File

@ -113,6 +113,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase
['object', new Node\Identifier('object')],
['Array', new Node\Identifier('array')],
['CALLABLE', new Node\Identifier('callable')],
['mixed', new Node\Identifier('mixed')],
['Some\Class', new Node\Name('Some\Class')],
['\Foo', new Node\Name\FullyQualified('Foo')],
['self', new Node\Name('self')],

View File

@ -1,7 +1,7 @@
Scalar type declarations
-----
<?php
function test(bool $a, Int $b, FLOAT $c, StRiNg $d, iterable $e, object $f) : void {}
function test(bool $a, Int $b, FLOAT $c, StRiNg $d, iterable $e, object $f, mixed $g) : void {}
-----
!!php7
array(
@ -77,6 +77,17 @@ array(
)
default: null
)
6: Param(
type: Identifier(
name: mixed
)
byRef: false
variadic: false
var: Expr_Variable(
name: g
)
default: null
)
)
returnType: Identifier(
name: void