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

DbDumper::setDbName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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