Completed
Push — master ( 239ace...08a73c )
by Sebastian
02:56
created

Plan::addRestoreCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace phpbu\App\Backup\Restore;
4
5
/**
6
 * Class Plan
7
 *
8
 * @package    phpbu
9
 * @subpackage Backup
10
 * @author     Sebastian Feldmann <[email protected]>
11
 * @copyright  Sebastian Feldmann <[email protected]>
12
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
13
 * @link       https://www.phpbu.de/
14
 * @since      Class available since Release 6.0.0
15
 */
16
class Plan
17
{
18
    /**
19
     * List of commands to execute to restore the backup
20
     *
21
     * Holding multiple lists of commands ['command' => 'foo', 'comment' => 'some comment']
22
     *
23
     * @var array
24
     */
25
    private $commands = [
26
        'decrypt'    => [],
27
        'decompress' => [],
28
        'restore'    => []
29
    ];
30
31
    /**
32
     * Is used crypt supported
33
     *
34
     * @var bool
35
     */
36
    private $supportedCrypt = true;
37
38
    /**
39
     * Is used source supported
40
     *
41
     * @var bool
42
     */
43
    private $supportedSource = true;
44
45
    /**
46
     * Mark the crypt implementation as not supported to restore
47
     *
48
     * @return void
49
     */
50 1
    public function markCryptAsUnsupported(): void
51
    {
52 1
        $this->supportedCrypt = false;
53 1
    }
54
55
    /**
56
     * Does crypt support restore
57
     *
58
     * @return bool
59
     */
60 3
    public function isCryptSupported(): bool
61
    {
62 3
        return $this->supportedCrypt;
63
    }
64
65
    /**
66
     * Add a decryption command to the restore plan
67
     *
68
     * @param  string $command
69
     * @param  string $comment
70
     * @return void
71
     */
72 4
    public function addDecryptionCommand(string $command, string $comment = ''): void
73
    {
74 4
        $this->addCommand('decrypt', $command, $comment);
75 4
    }
76
77
    /**
78
     * Return the list of decryption commands
79
     *
80
     * @return array
81
     */
82 6
    public function getDecryptionCommands(): array
83
    {
84 6
        return $this->commands['decrypt'];
85
    }
86
87
    /**
88
     * Add an decompression command to the restore plan
89
     *
90
     * @param  string $command
91
     * @param  string $comment
92
     * @return void
93
     */
94 1
    public function addDecompressionCommand(string $command, string $comment = ''): void
95
    {
96 1
        $this->addCommand('decompress', $command, $comment);
97 1
    }
98
99
    /**
100
     * Return the list of decompression commands
101
     *
102
     * @return array
103
     */
104 5
    public function getDecompressionCommands(): array
105
    {
106 5
        return $this->commands['decompress'];
107
    }
108
109
    /**
110
     * Mark used source as unsupported to restore
111
     *
112
     * @return void
113
     */
114
    public function markSourceAsUnsupported(): void
115
    {
116
        $this->supportedSource = false;
117
    }
118
119
    /**
120
     * Does the source support restore
121
     *
122
     * @return bool
123
     */
124 3
    public function isSourceSupported(): bool
125
    {
126 3
        return $this->supportedSource;
127
    }
128
129
    /**
130
     * Add restore command to the restore plan
131
     *
132
     * @param  string $command
133
     * @param  string $comment
134
     * @return void
135
     */
136 2
    public function addRestoreCommand(string $command, string $comment = ''): void
137
    {
138 2
        $this->addCommand('restore', $command, $comment);
139 2
    }
140
141
    /**
142
     * Return the list of restore commands
143
     *
144
     * @return array
145
     */
146 5
    public function getRestoreCommands(): array
147
    {
148 5
        return $this->commands['restore'];
149
    }
150
151
    /**
152
     * Add a command to the plan
153
     *
154
     * @param  string $type
155
     * @param  string $command
156
     * @param  string $comment
157
     * @return void
158
     */
159 4
    private function addCommand(string $type, string $command, string $comment): void
160
    {
161 4
        $this->commands[$type][] = ['command' => $command, 'comment' => $comment];
162 4
    }
163
}
164