Completed
Push — master ( 31c1f9...0bd8b0 )
by Karel
10s
created

ElasticaDataCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 58
ccs 18
cts 18
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A collect() 0 5 1
A getQueryCount() 0 4 1
A getQueries() 0 4 1
A getTime() 0 9 2
A getName() 0 4 1
1
<?php
2
3
namespace FOS\ElasticaBundle\DataCollector;
4
5
use FOS\ElasticaBundle\Logger\ElasticaLogger;
6
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\Response;
9
10
/**
11
 * Data collector collecting elastica statistics.
12
 *
13
 * @author Gordon Franke <[email protected]>
14
 */
15
class ElasticaDataCollector extends DataCollector
16
{
17
    protected $logger;
18
19
    /**
20
     * @param ElasticaLogger $logger
21
     */
22 4
    public function __construct(ElasticaLogger $logger)
23
    {
24 4
        $this->logger = $logger;
25 4
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 3
    public function collect(Request $request, Response $response, \Exception $exception = null)
31
    {
32 3
        $this->data['nb_queries'] = $this->logger->getNbQueries();
33 3
        $this->data['queries'] = $this->logger->getQueries();
34 3
    }
35
36
    /**
37
     * @return mixed
38
     */
39 1
    public function getQueryCount()
40
    {
41 1
        return $this->data['nb_queries'];
42
    }
43
44
    /**
45
     * @return mixed
46
     */
47 1
    public function getQueries()
48
    {
49 1
        return $this->data['queries'];
50
    }
51
52
    /**
53
     * @return int
54
     */
55 1
    public function getTime()
56
    {
57 1
        $time = 0;
58 1
        foreach ($this->data['queries'] as $query) {
59 1
            $time += $query['engineMS'];
60
        }
61
62 1
        return $time;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 1
    public function getName()
69
    {
70 1
        return 'elastica';
71
    }
72
}
73