laravel-ide-helper icon indicating copy to clipboard operation
laravel-ide-helper copied to clipboard

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

Open mortenscheel opened this issue 4 years ago • 0 comments

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.

mortenscheel avatar Oct 20 '21 15:10 mortenscheel