Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behavior of AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector, ExplicitRelationCollectionRector #8791

Open
AlexeyKosov opened this issue Aug 15, 2024 · 0 comments
Labels

Comments

@AlexeyKosov
Copy link

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/557ea3f4-d855-4f40-bc78-cdd3f46bebb0

<?php
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity()]
class Training
{
    #[ORM\Column(name: 'id', type: 'string')]
    #[ORM\Id]
    private string $id;
    
    #[ORM\ManyToOne(targetEntity: Trainer::class, inversedBy: "trainings")]
    private Trainer $trainer;
}

#[ORM\Entity()]
class Trainer
{
    /**
     * @var Collection|Training[]
     */
    #[ORM\OneToMany(targetEntity: Training::class, indexBy: "id", mappedBy: "trainer")]
    private $trainings = [];
    
    public function getTrainings()
    {
        return $this->trainings;
    }
    
    public function setTrainings($trainings)
    {
        $this->trainings = $trainings;
    }
}

Responsible rules

  • AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector

  • ExplicitRelationCollectionRector

Expected Behavior

The Training entity's ID is a string, so the Trainer::$trainings collection when indexed by ID (note the indexBy: "id" property), should have the Collection<string, Training> type rather than Collection<int, Training>.

So the point is that collections don't always have integer keys as it's hardcoded now, and it would be great to either properly determine their key type or skip the key definition at all (just use Collection<Training>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant