Completed
Push — master ( ae1aa8...20d020 )
by CodexShaper
02:07
created

PrepareOptionsTrait::getDumperClassName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace CodexShaper\Dumper\Traits;
4
5
trait PrepareOptionsTrait
6
{
7 58
    public function prepareHost()
8
    {
9 58
        switch (strtolower($this->getDumperClassName())) {
10 58
            case 'pgsqldumper':
11 30
                return ($this->socket !== '') ? $this->socket : $this->host;
12 28
            case 'mongodumper';
13 28
                return !empty($this->host) ? "--host {$this->host}" : "";
14
        }
15
    }
16
17 58
    public function preparePort()
18
    {
19 58
        switch (strtolower($this->getDumperClassName())) {
20 58
            case 'pgsqldumper':
21 30
                return !empty($this->port) ? '-p ' . $this->port : '';
22 28
            case 'mongodumper':
23 28
                return !empty($this->port) ? "--port {$this->port}" : "";
24
        }
25
    }
26
27 28
    public function prepareSocket()
28
    {
29 28
        switch (strtolower($this->getDumperClassName())) {
30 28
            case 'mysqldumper':
31 28
                return ($this->socket !== '') ? "--socket={$this->socket}" : '';
32
        }
33
    }
34
35 80
    public function prepareDatabase()
36
    {
37 80
        switch (strtolower($this->getDumperClassName())) {
38 80
            case 'mysqldumper':
39 46
            case 'pgsqldumper':
40 64
                return !empty($this->dbName) ? $this->dbName : "";
41 16
            case 'mongodumper';
42 16
                return !empty($this->dbName) ? "--db {$this->dbName}" : "";
43
        }
44
    }
45
46 58
    public function prepareUserName()
47
    {
48 58
        switch (strtolower($this->getDumperClassName())) {
49 58
            case 'pgsqldumper':
50 30
                return !empty($this->username) ? $this->username : "";
51 28
            case 'mongodumper';
52 28
                return !empty($this->username) ? "--username {$this->username}" : "";
53
        }
54
    }
55
56 52
    public function prepareIncludeTables()
57
    {
58 52
        switch (strtolower($this->getDumperClassName())) {
59 52
            case 'mysqldumper':
60 28
                $includeTables = (count($this->tables) > 0) ? implode(' ', $this->tables) : '';
61 28
                return !empty($includeTables) ? "--tables {$includeTables}" : '';
62 24
            case 'pgsqldumper':
63 24
                return (count($this->tables) > 0) ? '-t ' . implode(' -t ', $this->tables) : "";
64
        }
65
    }
66
67 52
    public function prepareIgnoreTables()
68
    {
69 52
        switch (strtolower($this->getDumperClassName())) {
70 52
            case 'mysqldumper':
71 28
                $ignoreTablesArgs = [];
72 28
                foreach ($this->ignoreTables as $tableName) {
73 4
                    $ignoreTablesArgs[] = "--ignore-table={$this->dbName}.{$tableName}";
74
                }
75 28
                return (count($ignoreTablesArgs) > 0) ? implode(' ', $ignoreTablesArgs) : '';
76 24
            case 'pgsqldumper';
77 24
                return (count($this->ignoreTables) > 0) ? '-T ' . implode(' -T ', $this->ignoreTables) : '';
78
        }
79
    }
80
81 92
    public function getDumperClassName()
82
    {
83 92
        $classWithNamespace = static::class;
84 92
        $partials           = explode("\\", $classWithNamespace);
85 92
        $className          = end($partials);
86 92
        return $className;
87
    }
88
}
89