Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Rector\Doctrine\Tests\TypedCollections\Rector\MethodCall\SetArrayToNewCollectionRector\Fixture;

use Rector\Doctrine\Tests\TypedCollections\Rector\MethodCall\SetArrayToNewCollectionRector\Source\ItemType;
use Doctrine\Common\Collections\Collection;

final class IncludeLocalSetter
{
public function run()
{
$someVariable = [new ItemType(), new ItemType()];

$this->setItems($someVariable);
}

public function setItems(Collection $collection)
{
}
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Doctrine\Tests\TypedCollections\Rector\MethodCall\SetArrayToNewCollectionRector\Fixture;

use Rector\Doctrine\Tests\TypedCollections\Rector\MethodCall\SetArrayToNewCollectionRector\Source\ItemType;
use Doctrine\Common\Collections\Collection;

final class IncludeLocalSetter
{
public function run()
{
$someVariable = [new ItemType(), new ItemType()];

$this->setItems(new \Doctrine\Common\Collections\ArrayCollection($someVariable));
}

public function setItems(Collection $collection)
{
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\Reflection\Php\PhpParameterReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ObjectType;
use PHPStan\Type\ThisType;
use PHPStan\Type\TypeCombinator;
use Rector\Doctrine\Enum\DoctrineClass;
use Rector\NodeNameResolver\NodeNameResolver;
Expand Down Expand Up @@ -42,6 +43,12 @@ public function detect(MethodCall|StaticCall|New_ $callLike, int $position): boo
}

$callerType = TypeCombinator::removeNull($callerType);

// to support same-class calls as well
if ($callerType instanceof ThisType) {
$callerType = $callerType->getStaticObjectType();
}

if (! $callerType instanceof ObjectType) {
return false;
}
Expand Down