SQLLoggerCollector::canHide()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineORMModule\Collector;
6
7
use Doctrine\DBAL\Logging\DebugStack;
8
use Laminas\DeveloperTools\Collector\AutoHideInterface;
9
use Laminas\DeveloperTools\Collector\CollectorInterface;
10
use Laminas\Mvc\MvcEvent;
11
use function count;
12
13
/**
14
 * Collector to be used in DeveloperTools to record and display SQL queries
15
 */
16
class SQLLoggerCollector implements CollectorInterface, AutoHideInterface
17
{
18
    /**
19
     * Collector priority
20
     */
21
    public const PRIORITY = 10;
22
23
    /** @var DebugStack */
24
    protected $sqlLogger;
25
26
    /** @var string */
27
    protected $name;
28
29 11
    public function __construct(DebugStack $sqlLogger, string $name)
30
    {
31 11
        $this->sqlLogger = $sqlLogger;
32 11
        $this->name      = (string) $name;
33 11
    }
34
35
    /**
36
     * {@inheritDoc}
37
     */
38 2
    public function getName()
39
    {
40 2
        return $this->name;
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46 1
    public function getPriority()
47
    {
48 1
        return self::PRIORITY;
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54 1
    public function collect(MvcEvent $mvcEvent)
55
    {
56 1
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61 1
    public function canHide()
62
    {
63 1
        return empty($this->sqlLogger->queries);
64
    }
65
66 1
    public function getQueryCount() : int
67
    {
68 1
        return count($this->sqlLogger->queries);
69
    }
70
71
    /**
72
     * @return mixed[]
73
     */
74
    public function getQueries() : array
75
    {
76
        return $this->sqlLogger->queries;
77
    }
78
79 1
    public function getQueryTime() : float
80
    {
81 1
        $time = 0.0;
82
83 1
        foreach ($this->sqlLogger->queries as $query) {
84 1
            $time += $query['executionMS'];
85
        }
86
87 1
        return $time;
88
    }
89
}
90