Skip to content

Incorrect behavior of DocblockReturnArrayFromDirectArrayInstanceRector #9599

@jmfeurprier

Description

@jmfeurprier

Bug Report

Rector adds a Docblock for methods even though they override methods with existing Docblocks.

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/9dc1a1da-6e22-4297-85ba-03a40194ce65

<?php

declare(strict_types=1);

interface FooInterface
{
    /**
     * @return int[]
     */
    public function getCodes(): iterable;
}

readonly abstract class FooBase
{
    /**
     * @return string[]
     */
    abstract public function getMethods(): iterable;
}

readonly class Foo extends FooBase implements FooInterface
{
    #[Override]
    public function getCodes(): iterable
    {
        return [
            200,
            201,
        ];
    }

    #[Override]
    public function getMethods(): iterable
    {
        return [
            'GET',
            'POST',
        ];
    }

    /**
     * @return string[]
     */
    public function getProtocols(): iterable
    {
        return [
            'http',
            'https',
        ];
    }
}

Responsible rules

  • DocblockReturnArrayFromDirectArrayInstanceRector

Expected Behavior

Rector should not add a Docblock to methods which override a method with existing Docblock.

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