Completed
Push — master ( 8e89e8...9e8f4c )
by Freek
01:51
created

DbDumper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
dumpToFile() 0 1 ?
A create() 0 4 1
getDbName() 0 1 ?
A checkIfDumpWasSuccessFul() 0 16 4
1
<?php
2
3
namespace Spatie\DbDumper;
4
5
use Spatie\DbDumper\Exceptions\DumpFailed;
6
use Symfony\Component\Process\Process;
7
8
abstract class DbDumper
9
{
10
    public static function create()
11
    {
12
        return new static();
13
    }
14
15
    /**
16
     * Dump the contents of the database to the given file.
17
     *
18
     * @param string $dumpFile
19
     */
20
    abstract public function dumpToFile($dumpFile);
21
22
    /**
23
     * @return string
24
     */
25
    abstract public function getDbName();
26
27
    /**
28
     * @param \Symfony\Component\Process\Process $process
29
     * @param string                             $outputFile
30
     *
31
     * @return bool
32
     *
33
     * @throws \Spatie\DbDumper\Exceptions\DumpFailed
34
     */
35
    protected function checkIfDumpWasSuccessFul(Process $process, $outputFile)
36
    {
37
        if (!$process->isSuccessful()) {
38
            throw DumpFailed::processDidNotEndSuccessfully($process);
39
        }
40
41
        if (!file_exists($outputFile)) {
42
            throw DumpFailed::dumpfileWasNotCreated();
43
        }
44
45
        if (filesize($outputFile) === 0) {
46
            throw DumpFailed::dumpfileWasEmpty();
47
        }
48
49
        return true;
50
    }
51
}
52