Skip to content

Commit

Permalink
[TypeDeclaration] Handle (object) cast on CompleteVarDocTypePropertyR…
Browse files Browse the repository at this point in the history
…ector (#503)
  • Loading branch information
samsonasik authored Jul 25, 2021
1 parent dfbd366 commit 34c3e8f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
use PhpParser\Node\Expr\Cast\Bool_;
use PhpParser\Node\Expr\Cast\Double;
use PhpParser\Node\Expr\Cast\Int_;
use PhpParser\Node\Expr\Cast\Object_;
use PhpParser\Node\Expr\Cast\String_;
use PHPStan\Type\ArrayType;
use PHPStan\Type\BooleanType;
use PHPStan\Type\FloatType;
use PHPStan\Type\IntegerType;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use Rector\Core\Exception\NotImplementedYetException;
Expand Down Expand Up @@ -56,6 +58,10 @@ public function resolve(Node $node): Type
return new ArrayType(new MixedType(), new MixedType());
}

if ($node instanceof Object_) {
return new ObjectType('stdClass');
}

throw new NotImplementedYetException($node::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Property\CompleteVarDocTypePropertyRector\Fixture;

class ObjectCastToStdClass
{
/**
* @var object[]
*/
private static $services = [];

public static function register(array $service)
{
self::$services[] = (object) $service;
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Property\CompleteVarDocTypePropertyRector\Fixture;

class ObjectCastToStdClass
{
/**
* @var \stdClass[]
*/
private static $services = [];

public static function register(array $service)
{
self::$services[] = (object) $service;
}
}

?>

0 comments on commit 34c3e8f

Please sign in to comment.