Skip to content

Incorrect behavior of AddReturnDocblockForCommonObjectDenominatorRector #9486

@Yoann-TYT

Description

@Yoann-TYT

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/075301d9-2544-491b-8b8f-d6ccbfcffc4c

<?php

final class Project
{
    public function __construct(
        public string $title
    ) {}
}

final class ProjectRepository
{
    /**
     * @return array<int, Project>
     */
    public function findRecent(): array
    {
        return [
            new Project('recent-1'),
            new Project('recent-2'),
        ];
    }
}

final class ProjectService
{
    public function __construct(private ProjectRepository $repo) {}

    public function getProjectsFromRepo(): array
    {
        return $this->repo->findRecent();
    }

    public function getProjectsInline(): array
    {
        return [
            new Project('inline-1'),
            new Project('inline-2'),
        ];
    }
}

Responsible rules

  • AddReturnDocblockForCommonObjectDenominatorRector

Expected Behavior

Rector correctly adds the docblock for the getProjectsInline method, but not for the getProjectsFromRepo one. In short, it cannot generate it recursively. Do you think this case is too complex to handle, or could it be supported in the future?

Thanks a lot for your amazing work on Rector !

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