BackupEngineSqlite   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 75
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getExportProcess() 0 4 1
A getRestoreProcess() 0 4 1
A getFileExtension() 0 4 1
A export() 0 11 1
A restore() 0 11 1
1
<?php
2
3
namespace Cornford\Backup\Engines;
4
5
class BackupEngineSqlite extends BackupEngineAbstract
6
{
7
    private const ENGINE_NAME = 'sqlite';
8
    private const ENGINE_EXTENSION = 'sqlite';
9
    private const ENGINE_EXPORT_PROCESS = 'cp';
10
    private const ENGINE_RESTORE_PROCESS = 'cp';
11
12
    /**
13
     * Get export process.
14
     *
15
     * @return string
16
     */
17
    public function getExportProcess()
18
    {
19
        return self::ENGINE_EXPORT_PROCESS;
20
    }
21
22
    /**
23
     * Get restore process.
24
     *
25
     * @return string
26
     */
27
    public function getRestoreProcess()
28
    {
29
        return self::ENGINE_RESTORE_PROCESS;
30
    }
31
32
    /**
33
     * Get database file extension.
34
     *
35
     * @return string
36
     */
37
    public function getFileExtension()
38
    {
39
        return self::ENGINE_EXTENSION;
40
    }
41
42
    /**
43
     * Export the database to a file path.
44
     *
45
     * @param string $filepath
46
     *
47
     * @return bool
48
     */
49
    public function export($filepath)
50
    {
51
        $command = sprintf(
52
            '%s %s %s',
53
            $this->getExportCommand(),
54
            escapeshellarg($this->getDatabase()),
55
            escapeshellarg($filepath)
56
        );
57
58
        return $this->getBackupProcess()->run($command, __FUNCTION__);
59
    }
60
61
    /**
62
     * Restore the database from a file path.
63
     *
64
     * @param string $filepath
65
     *
66
     * @return bool
67
     */
68
    public function restore($filepath)
69
    {
70
        $command = sprintf(
71
            '%s -f %s %s',
72
            $this->getRestoreCommand(),
73
            escapeshellarg($filepath),
74
            escapeshellarg($this->getDatabase())
75
        );
76
77
        return $this->getBackupProcess()->run($command, __FUNCTION__);
78
    }
79
}
80