Completed
Push — master ( fbc1fa...9bba21 )
by
unknown
14s
created

ElasticaDataCollector::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\ElasticaBundle\DataCollector;
13
14
use FOS\ElasticaBundle\Logger\ElasticaLogger;
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
18
19
/**
20
 * Data collector collecting elastica statistics.
21
 *
22
 * @author Gordon Franke <[email protected]>
23
 */
24
class ElasticaDataCollector extends DataCollector
25
{
26
    protected $logger;
27
28
    public function __construct(ElasticaLogger $logger)
29
    {
30
        $this->logger = $logger;
31
    }
32
33
    public function collect(Request $request, Response $response, \Exception $exception = null)
34
    {
35
        $this->data['nb_queries'] = $this->logger->getNbQueries();
36
        $this->data['queries'] = $this->logger->getQueries();
37
    }
38
39
    /**
40
     * @return mixed
41
     */
42
    public function getQueryCount()
43
    {
44
        return $this->data['nb_queries'];
45
    }
46
47
    /**
48
     * @return mixed
49
     */
50
    public function getQueries()
51
    {
52
        return $this->data['queries'];
53
    }
54
55
    /**
56
     * @return int
57
     */
58
    public function getTime()
59
    {
60
        $time = 0;
61
        foreach ($this->data['queries'] as $query) {
62
            $time += $query['engineMS'];
63
        }
64
65
        return $time;
66
    }
67
68
    /**
69
     * @return int
70
     */
71
    public function getExecutionTime()
72
    {
73
        $time = 0;
74
        foreach ($this->data['queries'] as $query) {
75
            $time += $query['executionMS'];
76
        }
77
78
        return $time;
79
    }
80
81
    public function getName()
82
    {
83
        return 'elastica';
84
    }
85
86
    public function reset()
87
    {
88
        $this->logger->reset();
89
        $this->data = [];
90
    }
91
}
92