Sqlite   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 22.73 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dumpToFile() 10 10 1
A getDumpCommand() 0 16 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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