Oct
21
2 days ago
started
started time in 2 days ago
started
started time in 2 days ago
started
started time in 2 days ago
Oct
20
3 days ago
Activity icon
issue

mortenscheel issue barryvdh/laravel-ide-helper

mortenscheel
mortenscheel

MetaCommand doesn't work if custom beforeResolving() callback uses class_exists()

Versions:

  • ide-helper Version: 2.10.0
  • Laravel Version: 8.65.0
  • PHP Version: 8.0.7

Description:

Running the ide-helper:meta command results in a lot of services being skipped unncessesarily if class_exists() gets called when an abstract is resolved from the container.

One of the packages I use (laravel-actions) registers a beforeResolving callback which checks if the abstract is a class: class_exists($abstract). But since a lot of the abstracts are not class names (config, request etc), it means that the MetaCommand's autoloader eventually gets called, which throws an exception and the service gets skipped.

I considered asking laravel-actions to wrap the class_exists() call in a try-catch, but I realized it would be an unreasonable request, since class_exists() isn't supposed to throw an exception.

Is the custom autoloader strictly necessary? When I disabled it, all the warnings went away, and it generated a meta file which looks perfect to me.

Steps To Reproduce:

  • Register a beforeResolving callback which calls class_exists($abstract)(or installlorisleiva/laravel-actions`).
  • Run php artisan ide-helper:meta and watch the console output.
started
started time in 3 days ago
Oct
19
4 days ago
Activity icon
issue

jamesratcliffe issue comment barryvdh/laravel-ide-helper

jamesratcliffe
jamesratcliffe

"artisan ide-helper:models --nowrite" gives "Multiple definitions exist for class ..."

First off, thanks for a great package!

After some hassle, I've got the facades and Eloquent/Builder stuff working like a charm.

But I'm struggling a bit now with the Model helpers. I'd prefer them in the separate _ide_helper_models.php. But if I do so, PhpStorm finds both the original Model and the generated helper. How do I prevent that?

jamesratcliffe
jamesratcliffe

@ThomasCollignon You're right. I tested with the scope it just excludes a random file. The inspection is disabled in other files, but not in that excluded file.

I'm pretty sure this means the only workaround is to not use this option with ide-helper or to totally disable the inspection. 😞

Activity icon
issue

ThomasCollignon issue comment barryvdh/laravel-ide-helper

ThomasCollignon
ThomasCollignon

"artisan ide-helper:models --nowrite" gives "Multiple definitions exist for class ..."

First off, thanks for a great package!

After some hassle, I've got the facades and Eloquent/Builder stuff working like a charm.

But I'm struggling a bit now with the Model helpers. I'd prefer them in the separate _ide_helper_models.php. But if I do so, PhpStorm finds both the original Model and the generated helper. How do I prevent that?

ThomasCollignon
ThomasCollignon

@ThomasCollignon Does that mean that my method is just effectively disabling the inspection?

IMO yes.

Activity icon
issue

jamesratcliffe issue comment barryvdh/laravel-ide-helper

jamesratcliffe
jamesratcliffe

"artisan ide-helper:models --nowrite" gives "Multiple definitions exist for class ..."

First off, thanks for a great package!

After some hassle, I've got the facades and Eloquent/Builder stuff working like a charm.

But I'm struggling a bit now with the Model helpers. I'd prefer them in the separate _ide_helper_models.php. But if I do so, PhpStorm finds both the original Model and the generated helper. How do I prevent that?

jamesratcliffe
jamesratcliffe

@ThomasCollignon Does that mean that my steps are just effectively disabling the inspection?