Skip to content

Incorrect behavior of RenamePropertyToMatchTypeRector #7672

@Atesca

Description

@Atesca

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.org/demo/4d56e655-adbd-4793-ad19-efdb46fdee80

<?php

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

final class SkipDoctrineCollection
{
    /**
     * @var Collection<int, Checkbox>
     */
    private Collection $checkboxes;

    public function __construct()
    {
        $this->checkboxes = new ArrayCollection();
    }

    public function getCheckboxes(): Collection
    {
        return $this->checkboxes;
    }
}

but there no changes if the property is public

See https://getrector.org/demo/a907458f-45dc-4467-b879-f9862575f1c3

<?php

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

final class SkipDoctrineCollection
{
    /**
     * @var Collection<int, Checkbox>
     */
    public Collection $checkboxes;

    public function __construct()
    {
        $this->checkboxes = new ArrayCollection();
    }

    public function getCheckboxes(): Collection
    {
        return $this->checkboxes;
    }
}

and no changes if there are 2 private Collections

See https://getrector.org/demo/460b439c-6dcc-4ec9-8c98-64f1c4e218f4

<?php

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

final class SkipDoctrineCollection
{
    /**
     * @var Collection<int, Checkbox>
     */
    private Collection $checkboxes;

    /**
     * @var Collection<int, Radiobox>
     */
    private Collection $radioboxes;

    public function __construct()
    {
        $this->checkboxes = new ArrayCollection();
        $this->radioboxes = new ArrayCollection();
    }

    public function getCheckboxes(): Collection
    {
        return $this->checkboxes;
    }

    public function getRadioboxes(): Collection
    {
        return $this->radioboxes;
    }
}

Responsible rules

  • RenamePropertyToMatchTypeRector

Expected Behavior

No changes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions