Skip to content

Incorrect behavior of DowngradeAttributeToAnnotationRector #9355

@kkmuffme

Description

@kkmuffme

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/9ddd11a3-9f6a-411f-802a-b6420d7e9b53

<?php

class Foo {
 	public function run(bool $param) {}   
}

final class DemoFile extends Foo
{
    #[Override]
    public function run(bool $param) {
        if ($this->isTrue($param)) {
            return 5;
        }

        return '10';
    }

    private function isTrue($value) {
        return $value === true;
    }
}

Responsible rules

  • DowngradeAttributeToAnnotationRector

Expected Behavior

  1. attributes that do not have a corresponding annotation should not be changed instead of being removed completely, as otherwise information is lost (and annotations are just regular code comments in older PHP versions anyway, so there's no reason to completely remove them)
    EDIT: at least for non-param annotations, since those need to be removed in all cases, e.g. https://getrector.com/demo/6ae7b65b-69e7-4d2c-b390-1961698831df is correct

  2. this rector should not modify code it does not even touch - e.g. why does it remove the empty line between } and return '10'; or move the { of the function declaration to the next line? These are all unrelated to the annotation and shouldn't be modified

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