Completed
Push — master ( 98dd85...467f0f )
by GBProd
02:08
created

ElasticaDataCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 61
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

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 getName() 0 4 1
A getTime() 0 9 2
1
<?php
2
3
namespace GBProd\ElasticaBundle\DataCollector;
4
5
use GBProd\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 5
    public function __construct(ElasticaLogger $logger)
20
    {
21 5
        $this->logger = $logger;
22 5
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 3
    public function collect(Request $request, Response $response, \Exception $exception = null)
28
    {
29 3
        $this->data['nb_queries'] = $this->logger->getNbQueries();
30 3
        $this->data['queries'] = $this->logger->getQueries();
31 3
    }
32
33
    /**
34
     * Nb of queries executed
35
     *
36
     * @return integer
37
     */
38 1
    public function getQueryCount()
39
    {
40 1
        return $this->data['nb_queries'];
41
    }
42
43
    /**
44
     * Queries
45
     *
46
     * @return array
47
     */
48 1
    public function getQueries()
49
    {
50 1
        return $this->data['queries'];
51
    }
52
53
    /**
54
     * Execution time
55
     *
56
     * @return integer
57
     */
58 1
    public function getTime()
59
    {
60 1
        $time = 0;
61 1
        foreach ($this->data['queries'] as $query) {
62 1
            $time += $query['response']['took'];
63 1
        }
64
65 1
        return $time;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 1
    public function getName()
72
    {
73 1
        return 'elastica';
74
    }
75
}
76