Skip to content

Incorrect behavior of DowngradeAttributeToAnnotationRector #9355

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

Activity

  1. samsonasik commented on Sep 8, 2025

    @samsonasik
    Member

    Re-open, it cause error on downgrade, seems due to reprinting single line, ref https://github.com/rectorphp/rector-src/actions/runs/17532914306/job/49817300076#step:14:70

  2. samsonasik commented on Sep 8, 2025

    @samsonasik
    Member

    @kkmuffme I tried 2 times handle it on rector side, see PR:

    but it keep cause our rector-src issues, see:

    so we seems can't handle it, this probably a bug on humbug/php-scoper

    You may need to create reproducible code and report there. If it fixed there, we may then can re-skip the Override and SensitiveParameter here :)

    Thank you for understanding.

  3. github-actions commented on Feb 8, 2026

    @github-actions
    Contributor

    This issue has been automatically locked because it has been closed for 150 days. Please open a new issue if you have a similar problem.

  4. locked as resolved and limited conversation to collaborators on Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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