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

ElasticaDataCollector::getExecutionTime()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
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