Completed
Pull Request — master (#104)
by Mikael
07:53
created

DatabaseCollectorConfigurator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 13 2
1
<?php
2
/*
3
 * This file is part of the PommProject/PommBundle package.
4
 *
5
 * (c) 2018 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\PommBundle\Configurator;
11
12
use PommProject\Foundation\Pomm;
13
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
14
15
/**
16
 * Data collector for the database profiler.
17
 *
18
 * @package PommBundle
19
 * @copyright 2018 Grégoire HUBERT
20
 * @author Paris Mikael
21
 * @license X11 {@link http://opensource.org/licenses/mit-license.php}
22
 * @see DataCollector
23
 */
24
class DatabaseCollectorConfigurator
25
{
26
    protected $datacollector;
27
28
    public function __construct(DataCollector $datacollector)
29
    {
30
        $this->datacollector = $datacollector;
31
    }
32
33
    /**
34
     * @param Pomm $pomm
35
     *
36
     * @return null
37
     */
38
    public function configure(Pomm $pomm)
39
    {
40
        $callable = [$this->datacollector, 'execute'];
41
42
        foreach ($pomm->getSessionBuilders() as $name => $builder) {
43
            $pomm->addPostConfiguration($name, function ($session) use ($callable) {
44
                $session
45
                    ->getClientUsingPooler('listener', 'query')
46
                    ->attachAction($callable)
47
                ;
48
            });
49
        }
50
    }
51
}
52