Skip to content

Override imported in global namespace #9277

@wernerkrauss

Description

@wernerkrauss

Bug Report

Subject Details
Rector version 2.1.2

When running AddOverrideAttributeToOverriddenMethodsRector in a Silverstripe 5 project, it makes troubles in Page and PageController. Those classes are for historical reasons in global namespace and wrapped in namespace { ... }

For some reasons, rector also adds use Overwrite; statement which gives me a PHP Warning:

Warning: The use statement with non-compound name 'Override' has no effect in /var/www/html/app/src/PageController.php on line 5

Minimal PHP Code Causing Issue

<?php

namespace {

    use SilverStripe\CMS\Controllers\ContentController;

    class PageController extends ContentController
    {
//here will rector add  #[Override] 
        protected function init()
        {
            parent::init();
            // You can include any CSS or JS required by your project here.
            // See: https://docs.silverstripe.org/en/developer_guides/templates/requirements/
        }

    }
}

When I remove the namespace {} construct, everything is fine.

Expected Behaviour

Rector should check if I'm in global namespace and then not import global classes.

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