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

ReflectionClass->getFileName() returns false for core/extnsion clasess which causes fatal error

Open dotdevio opened this issue 3 years ago • 11 comments

Versions:

  • ide-helper Version: 2.9.1
  • PHP Version: Tested on 8.0 but i think may relate to others as well.

Description:

This method: https://github.com/barryvdh/laravel-ide-helper/blob/244e936b740b18ab56180af2e1172436544764f2/src/UsesResolver.php#L26 fails when $classFQN will be php core/extension class as per php docs: https://www.php.net/manual/ru/reflectionclass.getfilename.php, for example this bug occurs when i install swoole/ide-helper.

php artisan ide-helper:generate

   ValueError 

  Path cannot be empty

  at vendor/barryvdh/laravel-ide-helper/src/UsesResolver.php:44
    40|     {
    41|         return $this->loadFromCode(
    42|             $classFQN,
    43|             file_get_contents(
  > 44|                 $filename
    45|             )
    46|         );
    47|     }
    48| 

      +20 vendor frames 
  21  artisan:36
      Illuminate\Foundation\Console\Kernel::handle()

Steps To Reproduce:

for example u may install swoole/ide-helper.

Possible solution

    /**
     * @param string $classFQN
     * @return array
     */
    public function loadFromClass(string $classFQN): array
    {
        $ref = (new \ReflectionClass($classFQN));

        if (false === $ref->getFileName()) {
            return [];
        }

        return $this->loadFromFile(
            $classFQN,
            $ref->getFileName()
        );
    }

dotdevio avatar Mar 18 '21 18:03 dotdevio

this needs to be fixed asap

vsg24 avatar Jul 02 '21 16:07 vsg24

Please fixed this bug. Thanx

mikloshumli avatar Dec 13 '21 16:12 mikloshumli

this needs to be fixed

birkaaa avatar Dec 13 '21 16:12 birkaaa

Fix it please! Thx!

sanya6456 avatar Dec 14 '21 11:12 sanya6456

I'm facing this problem too. It is seems ReflectionClass->getFileName() fails using this helper with swoole, because classes related swoole extention can not be resolved. Previously this problem was skipped as below.

Exception: Target class [swoole.room] does not exist.
Skipping \SwooleTW\Http\Websocket\Facades\Room.
Exception: Target class [swoole.websocket] does not exist.
Skipping \SwooleTW\Http\Websocket\Facades\Websocket.
Exception: Target class [swoole.room] does not exist.
Skipping \SwooleTW\Http\Websocket\Facades\Room.
Exception: Target class [swoole.websocket] does not exist.
Skipping \SwooleTW\Http\Websocket\Facades\Websocket.

https://github.com/barryvdh/laravel-ide-helper/issues/1186

ay4toh5i avatar Jan 25 '22 04:01 ay4toh5i

Previously this problem was skipped as below.

Isn't it anymore? Because the code is still there https://github.com/barryvdh/laravel-ide-helper/blob/c5e18beff1a2933913f86d56281581566e5c8705/src/Alias.php#L305

mfn avatar May 03 '22 11:05 mfn

This is also still happening for me.

yogesh98 avatar Nov 03 '22 21:11 yogesh98

This is still an issue for me.

yogesh98 avatar Jan 27 '23 23:01 yogesh98

This is still an issue for me with Swoole after update the package version

anderson-xd avatar Apr 19 '23 15:04 anderson-xd

I got this error as well. Since @dotdevpro suggested a fix, is there any way to merge it?

If there's any problem related to SwooleTW package I can help to address the solution btw.

Arkanius avatar Apr 19 '23 15:04 Arkanius

The swoole related issue with fixed with https://github.com/barryvdh/laravel-ide-helper/pull/1477 and is in the latest release.

Don't know about the others, though.

mfn avatar Feb 16 '24 22:02 mfn