driftingly/rector-laravel

Refactor uses FQDN despite namespace is present (since 0.16.0)

Closed this issue · 3 comments

I just noticed #76 got merged, and since then I have an issue:

One of my blade file is specifying a namespace for a Facade, but rector still tries to use the FQDN at the call location.

Here is my blade file (before)

@php
    use Illuminate\Support\Str;
    
    $parentId = Str::random(12);
@endphp

<div class="accordion" id="{{ $id }}">
    {{ $slot }}
</div>

And here is what Rector wants to refactor:

@php
  use Illuminate\Support\Str;

- $parentId = Str::random(12);
+ $parentId = Illuminate\Support\Str::random(12);
@endphp

Is it something I need to configure to explicitly disable FQDN when the namespace is present?

This might have to do with imports not being correctly recognized within blade files. Usually, this rule would not touch that piece of code.
Maybe this rule should be skippable after all, or at least configurable.

Can this package help better understanding namespaces?

https://github.com/Stillat/blade-parser

@khalyomede That package looks pretty cool; I'll have to check it out for another project.
@GeniJaho I've released the update to extract the facade rule.