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
Expand Up @@ -23,10 +23,11 @@ public function detect(ParamTagValueNode|ReturnTagValueNode $tagValueNode): bool
return false;
}

if ($genericTypeNode->type->name === 'Collection') {
$name = ltrim($genericTypeNode->type->name, '\\');
if ($name === 'Collection') {
return true;
}

return $genericTypeNode->type->name === DoctrineClass::COLLECTION;
return $name === DoctrineClass::COLLECTION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private function isCollectionIdentifierTypeNode(TypeNode $typeNode): bool
}

return in_array(
$typeNode->name,
ltrim($typeNode->name, '\\'),
[DoctrineClass::COLLECTION, DoctrineClass::ARRAY_COLLECTION, 'Collection', 'ArrayCollection'],
true
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Rector\Doctrine\Tests\Set\TypedCollectionsWithoutImportNames\Fixture;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\DocumentManager;

final class ParamTypePosition
{
private array $items;

/**
* @param mixed[]|ArrayCollection $collection
*/
public function __construct(
private readonly DocumentManager $documentManager,
private $collection
) {
foreach ($this->collection as $item) {
$this->items[] = $item;
}
}
}

?>
-----
<?php

namespace Rector\Doctrine\Tests\Set\TypedCollectionsWithoutImportNames\Fixture;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\DocumentManager;

final class ParamTypePosition
{
private array $items;

/**
* @param \Doctrine\Common\Collections\Collection<int, mixed> $collection
*/
public function __construct(
private readonly DocumentManager $documentManager,
private \Doctrine\Common\Collections\Collection $collection
) {
foreach ($this->collection as $item) {
$this->items[] = $item;
}
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Rector\Doctrine\Tests\Set\TypedCollectionsWithoutImportNames\Fixture;

use Doctrine\Common\Collections\ArrayCollection;
use Rector\Doctrine\Tests\Set\TypedCollections\Source\SomeItem;

abstract class RemoveNullableOnParamArray
{

/**
* @param array|ArrayCollection|SomeItem[] $items
*/
public function handleAllocations(int $counter, $items = []): void
{
foreach ($items as $item) {
}
}
}

?>
-----
<?php

namespace Rector\Doctrine\Tests\Set\TypedCollectionsWithoutImportNames\Fixture;

use Doctrine\Common\Collections\ArrayCollection;
use Rector\Doctrine\Tests\Set\TypedCollections\Source\SomeItem;

abstract class RemoveNullableOnParamArray
{

/**
* @param \Doctrine\Common\Collections\Collection<int, SomeItem> $items
*/
public function handleAllocations(int $counter, \Doctrine\Common\Collections\Collection $items): void
{
foreach ($items as $item) {
}
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Doctrine\Tests\Set\TypedCollectionsWithoutImportNames;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class TypedCollectionsWithoutImportNamesTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_set.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\ValueObject\PhpVersion;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([__DIR__ . '/../../../../config/sets/typed-collections.php']);

$rectorConfig->phpVersion(PhpVersion::PHP_84);
};
Loading