Passed
Push — master ( 1497f5...8a34be )
by Mike
10:00
created

Dumper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 25
cp 0
rs 9.52
c 0
b 0
f 0
cc 1
nc 1
nop 11
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
4
namespace Nexus\Dumper\Business;
5
6
7
use Nexus\DockerClient\DockerClientFacade;
8
9
class Dumper
10
{
11
    /**
12
     * @var string
13
     */
14
    private $volume;
15
16
    /**
17
     * @var string
18
     */
19
    private $path;
20
21
    /**
22
     * @var string
23
     */
24
    private $sshHost;
25
26
    /**
27
     * @var string
28
     */
29
    private $sshUser;
30
31
    /**
32
     * @var string
33
     */
34
    private $engine;
35
36
    /**
37
     * @var string
38
     */
39
    private $project;
40
41
    /**
42
     * @var string
43
     */
44
    private $version;
45
46
    /**
47
     * @var string
48
     */
49
    private $datapath;
50
51
    /**
52
     * @var string
53
     */
54
    private $imageName;
55
56
    /**
57
     * @var string
58
     */
59
    private $dumpDirectory;
60
61
    /**
62
     * @var DockerClientFacade
63
     */
64
    private $dockerFacade;
65
66
    /**
67
     * Dumper constructor.
68
     *
69
     * @param string $volume
70
     * @param string $path
71
     * @param string $sshHost
72
     * @param string $sshUser
73
     * @param string $engine
74
     * @param string $project
75
     * @param string $version
76
     * @param string $datapath
77
     * @param string $imageName
78
     * @param string $dumpDirectory
79
     * @param \Nexus\DockerClient\DockerClientFacade $dockerFacade
80
     */
81
    public function __construct(
82
        string $volume,
83
        string $path,
84
        string $sshHost,
85
        string $sshUser,
86
        string $engine,
87
        string $project,
88
        string $version,
89
        string $datapath,
90
        string $imageName,
91
        string $dumpDirectory,
92
        DockerClientFacade $dockerFacade
93
    ) {
94
        $this->volume = $volume;
95
        $this->path = $path;
96
        $this->sshHost = $sshHost;
97
        $this->sshUser = $sshUser;
98
        $this->engine = $engine;
99
        $this->project = $project;
100
        $this->version = $version;
101
        $this->datapath = $datapath;
102
        $this->imageName = $imageName;
103
        $this->dumpDirectory = $dumpDirectory;
104
        $this->dockerFacade = $dockerFacade;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function dump()
111
    {
112
        $command = $this->getCommand('dump');
113
114
        return $this->dockerFacade->runDocker($command);
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function restore()
121
    {
122
        $command = $this->getCommand('restore');
123
124
        return $this->dockerFacade->runDocker($command);
125
    }
126
127
    /**
128
     * @return string
129
     */
130
    private function getCommand(string $type): string
131
    {
132
        $command = sprintf(
133
            'run --rm -v %s:%s -v %s:/dump -e SSHHOST=%s -e SSHUSER=%s -e ENGINE=%s -e PROJECT=%s -e VERSION=%s -e DATAPATH=%s %s %s',
134
            $this->volume,
135
            $this->path,
136
            $this->dumpDirectory,
137
            $this->sshHost,
138
            $this->sshUser,
139
            $this->engine,
140
            $this->project,
141
            $this->version,
142
            $this->datapath,
143
            $this->imageName,
144
            $type
145
        );
146
        return $command;
147
    }
148
149
150
}