Completed
Push — master ( 3cdfc2...4aa078 )
by Maksim
03:09
created

ElasticaDataCollector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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
0 ignored issues
show
Bug introduced by
There is one abstract method reset in this class; you could implement it, or declare this class as abstract.
Loading history...
25
{
26
    protected $logger;
27
28
    /**
29
     * @param ElasticaLogger $logger
30
     */
31 4
    public function __construct(ElasticaLogger $logger)
32
    {
33 4
        $this->logger = $logger;
34 4
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 3
    public function collect(Request $request, Response $response, \Exception $exception = null)
40
    {
41 3
        $this->data['nb_queries'] = $this->logger->getNbQueries();
42 3
        $this->data['queries'] = $this->logger->getQueries();
43 3
    }
44
45
    /**
46
     * @return mixed
47
     */
48 1
    public function getQueryCount()
49
    {
50 1
        return $this->data['nb_queries'];
51
    }
52
53
    /**
54
     * @return mixed
55
     */
56 1
    public function getQueries()
57
    {
58 1
        return $this->data['queries'];
59
    }
60
61
    /**
62
     * @return int
63
     */
64 1
    public function getTime()
65
    {
66 1
        $time = 0;
67 1
        foreach ($this->data['queries'] as $query) {
68 1
            $time += $query['engineMS'];
69
        }
70
71 1
        return $time;
72
    }
73
74
    /**
75
     * @return int
76
     */
77
    public function getExecutionTime()
78
    {
79
        $time = 0;
80
        foreach ($this->data['queries'] as $query) {
81
            $time += $query['executionMS'];
82
        }
83
84
        return $time;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 1
    public function getName()
91
    {
92 1
        return 'elastica';
93
    }
94
}
95