SchemaCrawlerArguments   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 75
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 25 1
A toArray() 0 11 2
A getOutputFile() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: vernerd
5
 * Date: 2019-09-23
6
 * Time: 17:44.
7
 */
8
9
namespace DanielWerner\LaravelSchemaCrawler;
10
11
use Illuminate\Support\Str;
12
13
class SchemaCrawlerArguments
14
{
15
    protected $user;
16
17
    protected $password;
18
19
    protected $infoLevel;
20
21
    protected $command;
22
23
    protected $url;
24
25
    protected $outputFile;
26
27
    protected $outputFormat;
28
29
    protected $schemas;
30
31
    /**
32
     * SchemaCrawlerArguments constructor.
33
     * @param string|null $outputFile
34
     * @param string|null $outputFormat
35
     * @param string|null $connection
36
     * @param string|null $infoLevel
37
     * @param string|null $command
38
     */
39
    public function __construct(
40
        ?string $outputFile = null,
41
        ?string $outputFormat = null,
42
        ?string $connection = null,
43
        ?string $infoLevel = null,
44
        ?string $command = null
45
    ) {
46
        $connection = config('database.'.($connection ?? config('laravel-schemacrawler.connection')));
47
48
        $this->user = config('database.connections.'.$connection.'.username');
49
        $this->password = config('database.connections.'.$connection.'.password');
50
        $this->infoLevel = $infoLevel ?? config('laravel-schemacrawler.info_level');
51
        $this->command = $command ?? 'schema';
52
53
        $databaseDriver = config('database.connections.'.$connection.'.driver');
54
        $host = config('database.connections.'.$connection.'.host');
55
        $port = config('database.connections.'.$connection.'.port');
56
        $this->url = JDBC::url($databaseDriver, $host, $port);
57
58
        $this->outputFile = config('laravel-schemacrawler.output_base_path').DIRECTORY_SEPARATOR.
59
            ($outputFile ?? config('laravel-schemacrawler.output_file'));
60
61
        $this->outputFormat = $outputFormat ?? config('laravel-schemacrawler.output_format');
62
        $this->schemas = config('database.connections.'.$connection.'.database');
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    public function toArray(): array
69
    {
70
        $arguments = [];
71
72
        foreach ($this as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<DanielWerner\Larave...SchemaCrawlerArguments> is not traversable.
Loading history...
73
            $arguments[] = '--'.Str::snake($key, '-');
74
            $arguments[] = $value;
75
        }
76
77
        return $arguments;
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getOutputFile(): string
84
    {
85
        return $this->outputFile;
86
    }
87
}
88