mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +01:00
Add support for the mixed type
This commit is contained in:
parent
f33f081c8f
commit
32f89662f3
@ -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)
|
||||
--------------------------
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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')],
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user