barryvdh / laravel-ide-helper

IDE Helper for Laravel
MIT License
14.16k stars 1.16k forks source link

Laravel added aliases for 'Arr' and 'Str' no autocomplete from helper #784

Closed dmason30 closed 7 months ago

dmason30 commented 5 years ago

ide-helper version: 2.6.2

In Laravel 5.8.3 aliases were added for the Arr and Str classes by default:

https://github.com/laravel/laravel/pull/4951

They are not added as a Facade though just alias of a class, I assume this is the issue:

'Arr' => Illuminate\Support\Arr::class,
'Str' => Illuminate\Support\Str::class,

In PHPStorm I am not getting any autcomplete functions for these classes: image

Do I need to create my own Facade for these classes?


ide-helper.php The ide-helper outputs this in the ide-helper.php file:

...
namespace Illuminate\Support { 

    class Arr {

    }

    class Str {

    }

}
...
namespace  { 
    ....

    class Arr extends \Illuminate\Support\Arr {}

    ....

    class Str extends \Illuminate\Support\Str {}

    ....
}
...

Temporary solution I get autocomplete if I remove this section from the ide-helper.php but this file is regenerated often.

...
namespace Illuminate\Support { 

    class Arr {

    }

    class Str {

    }

}
cbaconnier commented 5 years ago

I also get errors in PHPstorm due to this issue, I guess.

PHPstorm error

pverhaert commented 5 years ago

Use real-time facades: https://laravel.com/docs/5.8/facades#real-time-facades Just add Facades\ to the path.

'Arr' => Facades\Illuminate\Support\Arr::class,     
'Str' => Facades\Illuminate\Support\Str::class,
Str
liquid207 commented 5 years ago

@pverhaert There are some functions that don't work properly with your solution. e.g.

class Arr
{
     public static function forget(&$array, $keys)
    {
     ...
    }
}

because __callStatic method in Illuminate\Support\Facades\Facade cannot pass reference parameters.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.

barryvdh commented 4 years ago

I guess they should only be added if they're a facade. In the case of these classes I would only expect a root class to extend the Support class.

tminich commented 4 years ago

I guess they should only be added if they're a facade. In the case of these classes I would only expect a root class to extend the Support class.

Not quite sure if I understand what you mean, but they should be examined. They are macroable and the helper is able to pick those macros up.

mfn commented 4 years ago

With https://github.com/barryvdh/laravel-ide-helper/releases/tag/v2.8.1 there was recent improvements regarding macros

Add support for macros of all macroable classes

But don't know how this works together with such classes which aren't "real" Facades 🤷‍♀️

tminich commented 4 years ago

But don't know how this works together with such classes which aren't "real" Facades 🤷‍♀️

Sorry if I wasn't clear, what I meant is that macros are indeed already working with Str and Arr (well, probably, I only have macros for Str). I just wanted to point that out so the helper wouldn't be updated to simply completely ignore them as there is value in examining and adding ide helpers for them despite not actually being Facades.