Completed
Push — master ( 50808e...8a6350 )
by Gianluca
05:45
created

SQLLoggerCollector   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 88
ccs 20
cts 22
cp 0.9091
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A getPriority() 0 4 1
A collect() 0 3 1
A canHide() 0 4 1
A getQueryCount() 0 4 1
A getQueries() 0 4 1
A getQueryTime() 0 10 2
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineORMModule\Collector;
21
22
use ZendDeveloperTools\Collector\CollectorInterface;
23
use ZendDeveloperTools\Collector\AutoHideInterface;
24
25
use Zend\Mvc\MvcEvent;
26
27
use Doctrine\DBAL\Logging\DebugStack;
28
29
/**
30
 * Collector to be used in ZendDeveloperTools to record and display SQL queries
31
 *
32
 * @license MIT
33
 * @link    www.doctrine-project.org
34
 * @author  Marco Pivetta <[email protected]>
35
 */
36
class SQLLoggerCollector implements CollectorInterface, AutoHideInterface
37
{
38
    /**
39
     * Collector priority
40
     */
41
    const PRIORITY = 10;
42
43
    /**
44
     * @var DebugStack
45
     */
46
    protected $sqlLogger;
47
48
    /**
49
     * @var string
50
     */
51
    protected $name;
52
53
    /**
54
     * @param DebugStack $sqlLogger
55
     * @param string     $name
56
     */
57 11
    public function __construct(DebugStack $sqlLogger, $name)
58
    {
59 11
        $this->sqlLogger = $sqlLogger;
60 11
        $this->name = (string) $name;
61 11
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66 2
    public function getName()
67
    {
68 2
        return $this->name;
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74 1
    public function getPriority()
75
    {
76 1
        return static::PRIORITY;
77
    }
78
79
    /**
80
     * {@inheritDoc}
81
     */
82 1
    public function collect(MvcEvent $mvcEvent)
83
    {
84 1
    }
85
86
    /**
87
     * {@inheritDoc}
88
     */
89 1
    public function canHide()
90
    {
91 1
        return empty($this->sqlLogger->queries);
92
    }
93
94
    /**
95
     * @return int
96
     */
97 1
    public function getQueryCount()
98
    {
99 1
        return count($this->sqlLogger->queries);
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    public function getQueries()
106
    {
107
        return $this->sqlLogger->queries;
108
    }
109
110
    /**
111
     * @return float
112
     */
113 1
    public function getQueryTime()
114
    {
115 1
        $time = 0.0;
116
117 1
        foreach ($this->sqlLogger->queries as $query) {
118 1
            $time += $query['executionMS'];
119 1
        }
120
121 1
        return $time;
122
    }
123
}
124