ElasticaDataCollector   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

8 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
A reset() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the FOSElasticaBundle package.
5
 *
6
 * (c) FriendsOfSymfony <https://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 7
    public function __construct(ElasticaLogger $logger)
29
    {
30 7
        $this->logger = $logger;
31 7
    }
32
33 5
    public function collect(Request $request, Response $response, ?\Throwable $exception = null)
34
    {
35 5
        $this->data['nb_queries'] = $this->logger->getNbQueries();
36 5
        $this->data['queries'] = $this->logger->getQueries();
37 5
    }
38
39
    /**
40
     * @return mixed
41
     */
42 3
    public function getQueryCount()
43
    {
44 3
        return $this->data['nb_queries'];
45
    }
46
47
    /**
48
     * @return mixed
49
     */
50 3
    public function getQueries()
51
    {
52 3
        return $this->data['queries'];
53
    }
54
55
    /**
56
     * @return int
57
     */
58 3
    public function getTime()
59
    {
60 3
        $time = 0;
61 3
        foreach ($this->data['queries'] as $query) {
62 3
            $time += $query['engineMS'];
63
        }
64
65 3
        return $time;
66
    }
67
68
    /**
69
     * @return int
70
     */
71 2
    public function getExecutionTime()
72
    {
73 2
        $time = 0;
74 2
        foreach ($this->data['queries'] as $query) {
75 2
            $time += $query['executionMS'];
76
        }
77
78 2
        return $time;
79
    }
80
81 1
    public function getName()
82
    {
83 1
        return 'elastica';
84
    }
85
86 1
    public function reset()
87
    {
88 1
        $this->logger->reset();
89 1
        $this->data = [];
90 1
    }
91
}
92