vkovic / laravel-commando

Collection of handy Laravel artisan commands that most projects needs
MIT License
60 stars 10 forks source link

model:fields command cause an error if class in wrong namespace #4

Closed vkovic closed 4 years ago

vkovic commented 4 years ago

When running the model:fields command if some of the classes being filtered (we are filtering only models) is not in correct namespace, ReflectionException : Class X\Y\Class does not exist will be thrown

Solution could be:

// File: src/Handlers/Helper.php

// This lines should be replaced with
if ($this->isAbstractClass($class) || $this->isInterface($class)) {
    continue;
}
// those lines
try {
    // If class is in wrong namespace code below will throw an error
    // (reflection exception), so we wrap it like this to avoid it.
    // Try to show error somewhere so user is aware of what's happening.
    if ($this->isAbstractClass($class) || $this->isInterface($class)) {
        continue;
    }
} catch (\Throwable $e) {
    continue;
}