Skip to content

Commit

Permalink
Merge pull request #2 from a-nakano/add-support-nullable
Browse files Browse the repository at this point in the history
Added support for nullable type.
  • Loading branch information
sj-i committed May 18, 2021
2 parents 54c77af + c43c6d7 commit 667e3af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/PhpDocTypeReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PhpDocTypeReader\Type\FloatType;
use PhpDocTypeReader\Type\GenericType;
use PhpDocTypeReader\Type\IntType;
use PhpDocTypeReader\Type\NullType;
use PhpDocTypeReader\Type\ObjectType;
use PhpDocTypeReader\Type\StringType;
use PhpDocTypeReader\Type\Type;
Expand Down Expand Up @@ -109,6 +110,8 @@ private function getTypeFromNodeType(TypeNode $type_node, IdentifierContext $ide
return new FloatType();
case 'bool':
return new BoolType();
case 'null':
return new NullType();
default:
return new ObjectType(
$this->tryGetClassNameFromIdentifier($type_node, $identifier_context)
Expand Down
8 changes: 8 additions & 0 deletions tests/PhpDocTypeReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PhpDocTypeReader\Type\FloatType;
use PhpDocTypeReader\Type\GenericType;
use PhpDocTypeReader\Type\IntType;
use PhpDocTypeReader\Type\NullType;
use PhpDocTypeReader\Type\ObjectType;
use PhpDocTypeReader\Type\StringType;
use PhpDocTypeReader\Type\UnionType;
Expand Down Expand Up @@ -220,6 +221,13 @@ public function paramProvider()
'/** @param int|string $union_var */',
$default_identifier_context,
],
[
[
'nullable_var' => new UnionType([new IntType(), new NullType()]),
],
'/** @param int|null $nullable_var */',
$default_identifier_context,
],
];
}
}

0 comments on commit 667e3af

Please sign in to comment.