SchemaCrawlerCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 5 1
A createArgumentsFromOptions() 0 10 6
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: vernerd
5
 * Date: 2019-09-24
6
 * Time: 22:30.
7
 */
8
9
namespace DanielWerner\LaravelSchemaCrawler\Console\Commands;
10
11
use Illuminate\Console\Command;
12
use DanielWerner\LaravelSchemaCrawler\Facades\SchemaCrawler;
13
use DanielWerner\LaravelSchemaCrawler\SchemaCrawlerArguments;
14
15
class SchemaCrawlerCommand extends Command
16
{
17
    /**
18
     * The name and signature of the console command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'schema:generate {--output-file=schema.pdf} {--output-format=pdf} 
23
                            {--connection=default} {--info-level=standard} {--command=schema}';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = 'Generates diagram from the database';
31
32
    public function handle()
33
    {
34
        $file = SchemaCrawler::crawl($this->createArgumentsFromOptions());
35
        $this->line('Generated diagram to '.$file);
36
    }
37
38
    /**
39
     * @return SchemaCrawlerArguments
40
     */
41
    private function createArgumentsFromOptions(): SchemaCrawlerArguments
42
    {
43
        return new SchemaCrawlerArguments(
44
            $this->hasOption('output-file') ? $this->option('output-file') : null,
45
            $this->hasOption('output-format') ? $this->option('output-format') : null,
46
            $this->hasOption('connection') ? $this->option('connection') : null,
47
            $this->hasOption('info-level') ? $this->option('info-level') : null,
48
            $this->hasOption('command') ? $this->option('command') : null
49
        );
50
    }
51
}
52