Sqlite::getDumpCommand()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\DbDumper\Databases;
4
5
use Spatie\DbDumper\DbDumper;
6
use Symfony\Component\Process\Process;
7
8
class Sqlite extends DbDumper
9
{
10
    /**
11
     * Dump the contents of the database to a given file.
12
     *
13
     * @param string $dumpFile
14
     *
15
     * @throws \Spatie\DbDumper\Exceptions\DumpFailed
16
     */
17 View Code Duplication
    public function dumpToFile(string $dumpFile)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
    {
19
        $command = $this->getDumpCommand($dumpFile);
20
21
        $process = Process::fromShellCommandline($command, null, null, null, $this->timeout);
22
23
        $process->run();
24
25
        $this->checkIfDumpWasSuccessFul($process, $dumpFile);
26
    }
27
28
    /**
29
     * Get the command that should be performed to dump the database.
30
     *
31
     * @param string $dumpFile
32
     *
33
     * @return string
34
     */
35
    public function getDumpCommand(string $dumpFile): string
36
    {
37
        $dumpInSqlite = "echo 'BEGIN IMMEDIATE;\n.dump'";
38
        if ($this->isWindows()) {
39
            $dumpInSqlite = '(echo BEGIN IMMEDIATE; & echo .dump)';
40
        }
41
        $quote = $this->determineQuote();
42
43
        $command = sprintf(
44
            "{$dumpInSqlite} | {$quote}%ssqlite3{$quote} --bail {$quote}%s{$quote}",
45
            $this->dumpBinaryPath,
46
            $this->dbName
47
        );
48
49
        return $this->echoToFile($command, $dumpFile);
50
    }
51
}
52