CreatorDb::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Velikonja\LabbyBundle\Database;
4
5
use Symfony\Component\Console\Output\BufferedOutput;
6
use Symfony\Component\Console\Output\NullOutput;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Velikonja\LabbyBundle\Executor\SymfonyCommandExecutor;
9
10
class CreatorDb
11
{
12
    /**
13
     * @var SymfonyCommandExecutor
14
     */
15
    private $executor;
16
17
    /**
18
     * @param SymfonyCommandExecutor $executor
19
     */
20 3
    public function __construct(SymfonyCommandExecutor $executor)
21
    {
22 3
        $this->executor = $executor;
23 3
    }
24
25
    /**
26
     * @param OutputInterface $output
27
     */
28 3
    public function create(OutputInterface $output = null)
29
    {
30 3
        $error     = false;
31 3
        $outputTmp = new NullOutput();
32
33
        // SF 2.3 does not have BufferedOutput
34 3
        if (class_exists('Symfony\Component\Console\Output\BufferedOutput')) {
35 3
            $outputTmp = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true);
36
        }
37
38
        try {
39 3
            $this->executor->execute('doctrine:database:drop --force', $outputTmp);
40 1
        } catch (\RuntimeException $e) {
41
            // catches an error if database does not exist
42 1
            $error = true;
43
        }
44
45 3
        if (! $error && method_exists($outputTmp, 'fetch')) {
46 2
            $output->write($outputTmp->fetch());
47
        }
48
49 3
        $this->executor->execute('doctrine:database:create', $output);
50 3
    }
51
}
52