MySqlDumper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 95.24%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 66
ccs 20
cts 21
cp 0.9524
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 29 3
A dump() 0 12 2
1
<?php
2
3
namespace Velikonja\LabbyBundle\Database\Mysql;
4
5
use Symfony\Component\Process\ProcessBuilder;
6
use Velikonja\LabbyBundle\Database\DatabaseException;
7
use Velikonja\LabbyBundle\Database\DumperInterface;
8
9
class MySqlDumper implements DumperInterface
10
{
11
    /**
12
     * @var \Symfony\Component\Process\ProcessBuilder
13
     */
14
    private $processBuilder;
15
16
    /**
17
     * @var string
18
     */
19
    private $executable;
20
21
    /**
22
     * @param array               $options
23
     * @param int                 $timeout
24
     * @param null|string         $executable
25
     * @param null|ProcessBuilder $processBuilder
26
     */
27 3
    public function __construct(
28
        array $options,
29
        $timeout = 60,
30
        $executable = null,
31
        ProcessBuilder $processBuilder = null
32
    ) {
33 3
        if (! $executable) {
34 3
            $executable = '/usr/bin/mysqldump';
35
        }
36
37 3
        $this->executable = $executable;
38
39 3
        if (! $processBuilder) {
40 3
            $processBuilder = new ProcessBuilder();
41
        }
42
43
        $processBuilder
44 3
            ->setTimeout($timeout)
45 3
            ->setPrefix($this->executable)
46 3
            ->setArguments(array(
47 3
                '--user=' . $options['user'],
48 3
                '--password=' . $options['password'],
49 3
                '--host=' . $options['host'],
50 3
                $options['dbname'],
51
            ));
52
53 3
        $this->processBuilder = $processBuilder;
54
55 3
    }
56
57
    /**
58
     * @throws DatabaseException
59
     *
60
     * @return string
61
     */
62 3
    public function dump()
63
    {
64 3
        $process = $this->processBuilder->getProcess();
65
66 3
        $process->run();
67
68 3
        if (! $process->isSuccessful()) {
69
            throw new DatabaseException($process->getErrorOutput());
70
        }
71
72 3
        return $process->getOutput();
73
    }
74
}
75