Skip to content

CompleteReturnDocblockFromToManyRector changes Collection key type #9682

@aprat84

Description

@aprat84

Bug Report

Subject Details
Rector version 2.3.8

The CompleteReturnDocblockFromToManyRector replaces my already correct return type, specifically, it changes the key type of the Collection.

Sometimes a Collection can be indexed by some value, which could be a string.

Minimal PHP Code Causing Issue

https://getrector.com/demo/09c4e216-f609-46dc-bf39-4c95de2ce627

<?php

 use Doctrine\ORM\Mapping as ORM;

 /**
  * @ORM\Entity
  */
 final class Trainer
 {
     /**
      * @ORM\OneToMany(targetEntity=Training::class, indexBy=someField)
      * @var \Doctrine\Common\Collections\Collection<string, Training>
      */
     private $trainings;

     /**
      * @return \Doctrine\Common\Collections\Collection<string, Training>
      */
     public function getTrainings()
     {
         return $this->trainings;
     }
 }
<?php

use Rector\Config\RectorConfig;
use Rector\Doctrine\TypedCollections\Rector\Class_\CompleteReturnDocblockFromToManyRector;

return RectorConfig::configure()
    ->withRules([
        CompleteReturnDocblockFromToManyRector::class,
    ]);

Expected Behaviour

Should not change the Collection key type from string to int.
In that particular case in the example above, should do nothing.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions