Completed
Push — master ( dddca7...cf9d09 )
by GBProd
04:26
created

ElasticaDataCollector::collect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
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 4
    public function __construct(ElasticaLogger $logger)
20
    {
21 4
        $this->logger = $logger;
22 4
    }
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 1
    public function getQueryCount()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
34
    {
35 1
        return $this->data['nb_queries'];
36
    }
37
38 1
    public function getQueries()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
39
    {
40 1
        return $this->data['queries'];
41
    }
42
43 1
    public function getTime()
44
    {
45 1
        $time = 0;
46 1
        foreach ($this->data['queries'] as $query) {
47 1
            $time += $query['engineMS'];
48 1
        }
49
50 1
        return $time;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getName()
57
    {
58
        return 'elastica';
59
    }
60
}