Passed
Push — master ( 21ff38...8c0b29 )
by Mike
02:34
created

Dumper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 0
cts 23
cp 0
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 10
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 $imageName;
50
51
    /**
52
     * @var string
53
     */
54
    private $dumpDirectory;
55
56
    /**
57
     * @var DockerClientFacade
58
     */
59
    private $dockerFacade;
60
61
    /**
62
     * Dumper constructor.
63
     *
64
     * @param string $volume
65
     * @param string $path
66
     * @param string $sshHost
67
     * @param string $sshUser
68
     * @param string $engine
69
     * @param string $project
70
     * @param string $version
71
     * @param string $imageName
72
     * @param string $dumpDirectory
73
     * @param \Nexus\DockerClient\DockerClientFacade $dockerFacade
74
     */
75
    public function __construct(
76
        string $volume,
77
        string $path,
78
        string $sshHost,
79
        string $sshUser,
80
        string $engine,
81
        string $project,
82
        string $version,
83
        string $imageName,
84
        string $dumpDirectory,
85
        DockerClientFacade $dockerFacade
86
    ) {
87
        $this->volume = $volume;
88
        $this->path = $path;
89
        $this->sshHost = $sshHost;
90
        $this->sshUser = $sshUser;
91
        $this->engine = $engine;
92
        $this->project = $project;
93
        $this->version = $version;
94
        $this->imageName = $imageName;
95
        $this->dumpDirectory = $dumpDirectory;
96
        $this->dockerFacade = $dockerFacade;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function clear()
103
    {
104
        $command = $this->getCommand('clear');
105
106
        return $this->dockerFacade->runDocker($command);
107
    }
108
109
    /**
110
     * @return string
111
     */
112
    public function dump()
113
    {
114
        $command = $this->getCommand('dump');
115
116
        return $this->dockerFacade->runDocker($command);
117
    }
118
119
    /**
120
     * @return string
121
     */
122
    public function restore()
123
    {
124
        $command = $this->getCommand('restore');
125
126
        return $this->dockerFacade->runDocker($command);
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    private function getCommand(string $type): string
133
    {
134
        $command = sprintf(
135
            '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',
136
            $this->volume,
137
            $this->path,
138
            $this->dumpDirectory,
139
            $this->sshHost,
140
            $this->sshUser,
141
            $this->engine,
142
            $this->project,
143
            $this->version,
144
            $this->path,
145
            $this->imageName,
146
            $type
147
        );
148
        return $command;
149
    }
150
151
152
}