Completed
Push — master ( bcd560...9ae212 )
by CodexShaper
02:01
created

SqliteDumper::prepareRestoreCommand()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 2
rs 10
1
<?php
2
3
namespace CodexShaper\Dumper\Drivers;
4
5
use CodexShaper\Dumper\Dumper;
6
7
class SqliteDumper extends Dumper
8
{
9
    public function dump(string $destinationPath = "")
10
    {
11
        $destinationPath = !empty($destinationPath) ? '"' . $destinationPath . '"' : '"' . $this->destinationPath . '"';
12
        $dumpCommand     = $this->prepareDumpCommand($destinationPath);
13
        $this->command   = $this->removeExtraSpaces($dumpCommand);
14
        $this->run();
15
    }
16
17
    public function restore(string $restorePath = "")
18
    {
19
        $restorePath    = !empty($restorePath) ? '"' . $restorePath . '"' : '"' . $this->restorePath . '"';
20
        $restoreCommand = $this->prepareRestoreCommand($restorePath);
21
        $this->command  = $this->removeExtraSpaces($restoreCommand);
22
        $this->run();
23
    }
24
25 8
    protected function prepareDumpCommand(string $destinationPath): string
26
    {
27 8
        $dumpCommand = sprintf(
28 8
            "%s %s .dump",
29 8
            $this->quoteCommand($this->commandBinaryPath . 'sqlite3'),
30 8
            $this->dbName
31
        );
32
33 8
        if ($this->isCompress) {
34 2
            $compressCommand = $this->quoteCommand("{$this->compressBinaryPath}{$this->compressCommand}");
35 2
            return "{$dumpCommand} | $compressCommand > \"{$destinationPath}{$this->compressExtension}\"";
36
        }
37
38 6
        return "{$dumpCommand} > \"{$destinationPath}\"";
39
    }
40
41 8
    protected function prepareRestoreCommand(string $filePath): string
42
    {
43 8
        $restoreCommand = sprintf("%s %s",
44 8
            $this->quoteCommand($this->commandBinaryPath . 'sqlite3'),
45 8
            $this->dbName
46
        );
47
48 8
        if ($this->isCompress) {
49 2
            $compressCommand = $this->quoteCommand("{$this->compressBinaryPath}{$this->compressCommand}");
50 2
            return "$compressCommand < \"{$filePath}\" | {$restoreCommand}";
51
        }
52
53 6
        return "{$restoreCommand} < \"{$filePath}\"";
54
    }
55
}
56