Completed
Branch master (1b515e)
by GBProd
28:38 queued 20:49
created

ElasticaDataCollector   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 46
ccs 16
cts 18
cp 0.8889
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 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 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
        }
49
50 1
        return $time;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getName()
57
    {
58
        return 'elastica';
59
    }
60
}