BenSampo / laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.
https://sampo.co.uk/blog/using-enums-in-laravel
MIT License
1.99k stars 163 forks source link

False positive when converting to native enums #355

Open atymic opened 6 months ago

atymic commented 6 months ago

For some reason the rector rule is catching random bits of unrelated code, for example the below sample. It seems to be a bit random, will attempt to debug further to figure out why, by have narrowed it down to \BenSampo\Enum\Rector\ToNativeRector::inConfiguredClasses returning true when it should not.

    ---------- begin diff ----------
@@ @@
     {
         $jwtHeader = explode(' ', $request->header('authorization', ''));

-        abort_if(empty($jwtHeader) || count($jwtHeader) !== 2, 400);
+        abort_if((empty($jwtHeader))->value || count($jwtHeader) !== 2, 400);

         $jwt = $jwtHeader[1];
    ----------- end diff -----------

Applied rules:
 * ToNativeUsagesRector

Screen Shot 2024-02-18 at 18 09 00@2x

atymic commented 6 months ago

Okay, digging deeper it seems like somehow NeverType is a subtype of my class according to the AST? I unfortunately don't think I have enough knowledge in this area to debug haha.

Screen Shot 2024-02-18 at 18 19 13@2x

spawnia commented 6 months ago

Can you try if https://github.com/BenSampo/laravel-enum/issues/355 fixes the issue?