Completed
Push — master ( 58d02c...4bffa9 )
by CodexShaper
05:11 queued 02:40
created

SqliteDumper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 22
c 3
b 0
f 0
dl 0
loc 46
ccs 0
cts 27
cp 0
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareDumpCommand() 0 14 2
A restore() 0 6 2
A prepareRestoreCommand() 0 12 2
A dump() 0 6 2
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
    protected function prepareDumpCommand(string $destinationPath): string
26
    {
27
        $dumpCommand = sprintf(
28
            "%ssqlite3 %s .dump",
29
            $this->dumpCommandPath,
30
            $this->dbName
31
        );
32
33
        if ($this->isCompress) {
34
35
            return "{$dumpCommand} | {$this->compressBinaryPath}{$this->compressCommand} > {$destinationPath}{$this->compressExtension}";
36
        }
37
38
        return "{$dumpCommand} > {$destinationPath}";
39
    }
40
41
    protected function prepareRestoreCommand(string $filePath): string
42
    {
43
        $restoreCommand = sprintf("%ssqlite3 %s",
44
            $this->dumpCommandPath,
45
            $this->dbName
46
        );
47
48
        if ($this->isCompress) {
49
            return "{$this->compressBinaryPath}{$this->compressCommand} < {$filePath} | {$restoreCommand}";
50
        }
51
52
        return "{$restoreCommand} < {$filePath}";
53
    }
54
}
55