Neo4jDataCollector::getQueryCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neo4j\Neo4jBundle\Collector;
6
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
10
11
/**
12
 * @author Xavier Coureau <[email protected]>
13
 */
14
final class Neo4jDataCollector extends DataCollector
15
{
16
    /**
17
     * @var QueryLogger
18
     */
19
    private $queryLogger;
20
21
    public function __construct(QueryLogger $logger)
22
    {
23
        $this->queryLogger = $logger;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function collect(Request $request, Response $response, \Exception $exception = null)
30
    {
31
        $this->data['time'] = $this->queryLogger->getElapsedTime();
32
        $this->data['nb_queries'] = count($this->queryLogger);
33
        $this->data['statements'] = $this->queryLogger->getStatements();
34
        $this->data['failed_statements'] = array_filter($this->queryLogger->getStatements(), function ($statement) {
35
            return !isset($statement['success']) || !$statement['success'];
36
        });
37
    }
38
39
    public function reset()
40
    {
41
        $this->data = [];
42
        $this->queryLogger->reset();
43
    }
44
45
    /**
46
     * @return int
47
     */
48
    public function getQueryCount()
49
    {
50
        return $this->data['nb_queries'];
51
    }
52
53
    /**
54
     * Return all statements, successful and not successful.
55
     *
56
     * @return array
57
     */
58
    public function getStatements()
59
    {
60
        return $this->data['statements'];
61
    }
62
63
    /**
64
     * Return not successful statements.
65
     *
66
     * @return array
67
     */
68
    public function getFailedStatements()
69
    {
70
        return $this->data['failed_statements'];
71
    }
72
73
    /**
74
     * @return float
75
     */
76
    public function getTime()
77
    {
78
        return $this->data['time'];
79
    }
80
81
    /**
82
     * @return float
83
     */
84
    public function getTimeForQuery()
85
    {
86
        return $this->data['time'];
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getName()
93
    {
94
        return 'neo4j';
95
    }
96
}
97