DefaultCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 11
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A end() 0 4 2
A init() 0 9 2
1
<?php
2
3
namespace ProjetNormandie\CommonBundle\Command;
4
5
use Doctrine\DBAL\Logging\DebugStack;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
8
abstract class DefaultCommand extends ContainerAwareCommand
9
{
10
    private $sglLoggerEnabled = false;
11
    private $stack = null;
12
13
    /**
14
     * @param $input
15
     */
16
    protected function init($input)
17
    {
18
        if ($input->getOption('debug')) {
19
            $this->sglLoggerEnabled = true;
20
            // Start setup logger
21
            $doctrine = $this->getContainer()->get('doctrine');
22
            $doctrineConnection = $doctrine->getConnection();
23
            $this->stack = new DebugStack();
24
            $doctrineConnection->getConfiguration()->setSQLLogger($this->stack);
25
            // End setup logger
26
        }
27
    }
28
29
    /**
30
     * @param $output
31
     */
32
    protected function end($output)
33
    {
34
        if ($this->sglLoggerEnabled) {
35
            $output->writeln(sprintf('%s queries', count($this->stack->queries)));
36
        }
37
    }
38
}
39