DefaultCommand::end()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 2
eloc 2
nc 2
nop 1
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