CreatorDb   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 42
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B create() 0 23 5
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