imanghafoori1 / laravel-microscope

Fearless refactoring, it does a lot of smart checks to find certain errors.
MIT License
1.46k stars 97 forks source link

`check:imports` false positives for PHP constants #290

Open rodrigopedra opened 1 month ago

rodrigopedra commented 1 month ago

Sample output from a real project. PHP global constants prefixed with a backslash \ are considered to be Class references.

$ php artisan check:imports --nofix

Checking imports and class references...
   1 Class Reference does not exist:
   \STR_PAD_LEFT
at app/Casts/RegistrationNumber.php:29
 _______________________________________________________________________________________________________________________ 
   2 Class Reference does not exist:
   \STR_PAD_LEFT
at app/Casts/SerialNumber.php:31
 _______________________________________________________________________________________________________________________ 
   3 Class Reference does not exist:
   \PHP_EOL
at app/Console/Commands/AssessMissingRecords.php:66
 _______________________________________________________________________________________________________________________ 
   4 Class Reference does not exist:
   \JSON_BIGINT_AS_STRING
at app/Console/Commands/ObserveJobs.php:52
 _______________________________________________________________________________________________________________________ 
   5 Class Reference does not exist:
   \JSON_OBJECT_AS_ARRAY
at app/Console/Commands/ObserveJobs.php:52
 _______________________________________________________________________________________________________________________ 
   6 Class Reference does not exist:
   \JSON_BIGINT_AS_STRING
at app/Console/Commands/ObserveJobs.php:108
 _______________________________________________________________________________________________________________________ 
   7 Class Reference does not exist:
   \JSON_OBJECT_AS_ARRAY
at app/Console/Commands/ObserveJobs.php:108
 _______________________________________________________________________________________________________________________ 
   8 Class Reference does not exist:
   \PREG_SPLIT_NO_EMPTY
at app/Console/Commands/ObserveQueues.php:69
 _______________________________________________________________________________________________________________________ 
   9 Class Reference does not exist:
   \PREG_SPLIT_NO_EMPTY
at app/Console/Commands/ObserveWorkers.php:37
 _______________________________________________________________________________________________________________________ 
  10 Class Reference does not exist:
   \PREG_SPLIT_NO_EMPTY
at app/Console/Commands/ObserveWorkers.php:46
 _______________________________________________________________________________________________________________________ 
... OMITTED FOR BREVITY
 _______________________________________________________________________________________________________________________ 
Imports were checked under:
./composer.json
   ➖  PSR-4 
       ➖  App\:                      ./app/ ( 562 files )
       ➖  Database\Factories\:       ./database/factories/ ( 1 file )
       ➖  Database\Seeders\:         ./database/seeders/ ( 1 file )
       ➖  Tests\:                    ./tests/ ( 3 files )
 ⬛ Overall:
   ➖  567 classes
   ➖   blade
       ➖  resources/views/ ( 175 files )
   ➖   config
       ➖  config/ ( 15 files )
   ➖   migrations
       ➖  database/migrations/ ( 42 files )
   ➖  3  routes
       ➖  routes/api.php
       ➖  routes/web.php
       ➖  routes/local.php
   ➖  1  autoloaded file
       ➖  app/helpers.php
6599 references were checked, 28 errors found.
 🔸 0 unused imports found.
 🔸 0 wrong imports found.
 🔸 28 wrong class references found.
time: 0.98 (sec)
imanghafoori1 commented 1 month ago

Thanks for submitting the issue. I will fix it soon.

rodrigopedra commented 1 month ago

No problems. Thank you for this fantastic package!