RefactorDbCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 9
c 2
b 1
f 0
dl 0
loc 34
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 3
1
<?php
2
3
namespace Signifly\DatabaseRefactors\Commands;
4
5
use Exception;
6
use Illuminate\Console\Command;
7
use ReflectionClass;
8
9
class RefactorDbCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'db:refactor {--class=}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Refactor database by specified refactor class';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return mixed
29
     */
30
    public function handle()
31
    {
32
        $class = $this->option('class');
33
34
        if (! class_exists($class)) {
35
            throw new Exception('Invalid refactor class: '.$class);
36
        }
37
38
        if (! (new ReflectionClass($class))->hasMethod('run')) {
39
            throw new Exception('Method run does not exist on: '.$class);
40
        }
41
42
        (new $class)->run();
43
    }
44
}
45