Skip to content

Commit

Permalink
add support for mixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sj-i committed Aug 26, 2021
1 parent 667e3af commit 838b7be
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 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\MixedType;
use PhpDocTypeReader\Type\NullType;
use PhpDocTypeReader\Type\ObjectType;
use PhpDocTypeReader\Type\StringType;
Expand Down Expand Up @@ -102,6 +103,8 @@ private function getTypeFromNodeType(TypeNode $type_node, IdentifierContext $ide
{
if ($type_node instanceof IdentifierTypeNode) {
switch ($type_node->name) {
case 'mixed':
return new MixedType();
case 'int':
return new IntType();
case 'string':
Expand Down
2 changes: 1 addition & 1 deletion src/Type/AtomicType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

namespace PhpDocTypeReader\Type;

abstract class AtomicType implements Type
abstract class AtomicType extends MixedType
{
}
18 changes: 18 additions & 0 deletions src/Type/MixedType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* This file is part of the sj-i/phpdoc-type-reader package.
*
* (c) sji <sji@sj-i.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace PhpDocTypeReader\Type;

class MixedType implements Type
{
}
2 changes: 1 addition & 1 deletion src/Type/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace PhpDocTypeReader\Type;

class UnionType implements Type
class UnionType extends MixedType
{
/** @var AtomicType[] */
public array $types;
Expand Down
13 changes: 13 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\MixedType;
use PhpDocTypeReader\Type\NullType;
use PhpDocTypeReader\Type\ObjectType;
use PhpDocTypeReader\Type\StringType;
Expand All @@ -46,6 +47,11 @@ public function varProvider(): array
[]
);
return [
[
new MixedType(),
'/** @var mixed */',
$default_identifier_context
],
[
new IntType(),
'/** @var int */',
Expand Down Expand Up @@ -133,6 +139,13 @@ public function paramProvider()
[]
);
return [
[
[
'mixed_var' => new MixedType()
],
'/** @param mixed $mixed_var */',
$default_identifier_context
],
[
[
'integer_var' => new IntType()
Expand Down

0 comments on commit 838b7be

Please sign in to comment.