Completed
Pull Request — master (#1149)
by Oleg
06:13
created

ElasticaDataCollector   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 78.26%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 71
ccs 18
cts 23
cp 0.7826
rs 10
c 0
b 0
f 0

7 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 getExecutionTime() 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
     * @return int
67
     */
68
    public function getExecutionTime()
69
    {
70
        $time = 0;
71
        foreach ($this->data['queries'] as $query) {
72
            $time += $query['executionMS'];
73
        }
74
75
        return $time;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 1
    public function getName()
82
    {
83 1
        return 'elastica';
84
    }
85
}
86