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

ElasticaDataCollector::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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