Dumper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 25
dl 0
loc 76
ccs 0
cts 39
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A restore() 0 5 1
A dump() 0 5 1
A clear() 0 5 1
A __construct() 0 6 1
A getCommand() 0 17 1
1
<?php
2
3
4
namespace Nexus\Dumper\Business\Model;
5
6
7
use DataProvider\DumperConfigDataProvider;
8
use Nexus\DockerClient\Business\DockerClientFacadeInterface;
9
10
class Dumper implements DumperInterface
11
{
12
    /**
13
     * @var DumperConfigDataProvider
14
     */
15
    private $configDataProvider;
16
17
    /**
18
     * @var \Nexus\DockerClient\Business\DockerClientFacadeInterface
19
     */
20
    private $dockerFacade;
21
22
    /**
23
     * Dumper constructor.
24
     *
25
     * @param DumperConfigDataProvider $configDataProvider
26
     * @param \Nexus\DockerClient\Business\DockerClientFacadeInterface $dockerFacade
27
     */
28
    public function __construct(
29
        DumperConfigDataProvider $configDataProvider,
30
        DockerClientFacadeInterface $dockerFacade
31
    ) {
32
        $this->configDataProvider = $configDataProvider;
33
        $this->dockerFacade = $dockerFacade;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function clear(): string
40
    {
41
        $command = $this->getCommand('clear');
42
43
        return $this->dockerFacade->runDocker($command);
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function dump(): string
50
    {
51
        $command = $this->getCommand('dump');
52
53
        return $this->dockerFacade->runDocker($command);
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function restore(): string
60
    {
61
        $command = $this->getCommand('restore');
62
63
        return $this->dockerFacade->runDocker($command);
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    private function getCommand(string $type): string
70
    {
71
        $command = sprintf(
72
            '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',
73
            $this->configDataProvider->getVolume(),
74
            $this->configDataProvider->getPath(),
75
            $this->configDataProvider->getDumpDirectory(),
76
            $this->configDataProvider->getSshHost(),
77
            $this->configDataProvider->getSshUser(),
78
            $this->configDataProvider->getEngine(),
79
            $this->configDataProvider->getProject(),
80
            $this->configDataProvider->getVersion(),
81
            $this->configDataProvider->getPath(),
82
            $this->configDataProvider->getImageName(),
83
            $type
84
        );
85
        return $command;
86
    }
87
88
89
}