Skip to content

Commit

Permalink
Handle true/false/null types in builder APIs
Browse files Browse the repository at this point in the history
(cherry picked from commit 71ed641)
  • Loading branch information
nikic committed Sep 3, 2022
1 parent 3fe2422 commit 3ee592b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/PhpParser/BuilderHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,20 @@ public static function normalizeType($type) {
}

$builtinTypes = [
'array', 'callable', 'string', 'int', 'float', 'bool', 'iterable', 'void', 'object', 'mixed', 'never',
'array',
'callable',
'bool',
'int',
'float',
'string',
'iterable',
'void',
'object',
'null',
'false',
'mixed',
'never',
'true',
];

$lowerType = strtolower($type);
Expand Down
3 changes: 3 additions & 0 deletions test/PhpParser/BuilderHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ public function testNormalizeType() {
$this->assertEquals(new Node\Identifier('iterable'), BuilderHelpers::normalizeType('iterable'));
$this->assertEquals(new Node\Identifier('void'), BuilderHelpers::normalizeType('void'));
$this->assertEquals(new Node\Identifier('object'), BuilderHelpers::normalizeType('object'));
$this->assertEquals(new Node\Identifier('null'), BuilderHelpers::normalizeType('null'));
$this->assertEquals(new Node\Identifier('false'), BuilderHelpers::normalizeType('false'));
$this->assertEquals(new Node\Identifier('mixed'), BuilderHelpers::normalizeType('mixed'));
$this->assertEquals(new Node\Identifier('never'), BuilderHelpers::normalizeType('never'));
$this->assertEquals(new Node\Identifier('true'), BuilderHelpers::normalizeType('true'));

$intIdentifier = new Node\Identifier('int');
$this->assertSame($intIdentifier, BuilderHelpers::normalizeType($intIdentifier));
Expand Down

0 comments on commit 3ee592b

Please sign in to comment.