Completed
Push — master ( 0f71cc...99d0b0 )
by Karel
15:42
created

ElasticaDataCollector   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 68
ccs 18
cts 27
cp 0.6667
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A getQueryCount() 0 4 1
A __construct() 0 4 1
A collect() 0 5 1
A getQueries() 0 4 1
A getTime() 0 9 2
A getExecutionTime() 0 9 2
A reset() 0 5 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
25
{
26
    protected $logger;
27
28 4
    public function __construct(ElasticaLogger $logger)
29
    {
30 4
        $this->logger = $logger;
31 4
    }
32
33 3
    public function collect(Request $request, Response $response, \Exception $exception = null)
34
    {
35 3
        $this->data['nb_queries'] = $this->logger->getNbQueries();
36 3
        $this->data['queries'] = $this->logger->getQueries();
37 3
    }
38
39
    /**
40
     * @return mixed
41
     */
42 1
    public function getQueryCount()
43
    {
44 1
        return $this->data['nb_queries'];
45
    }
46
47
    /**
48
     * @return mixed
49
     */
50 1
    public function getQueries()
51
    {
52 1
        return $this->data['queries'];
53
    }
54
55
    /**
56
     * @return int
57
     */
58 1
    public function getTime()
59
    {
60 1
        $time = 0;
61 1
        foreach ($this->data['queries'] as $query) {
62 1
            $time += $query['engineMS'];
63
        }
64
65 1
        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 1
    public function getName()
82
    {
83 1
        return 'elastica';
84
    }
85
86
    public function reset()
87
    {
88
        $this->logger->reset();
89
        $this->data = [];
90
    }
91
}
92