Completed
Push — master ( 3cdfc2...4aa078 )
by Maksim
03:09
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
/*
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