DebugStack   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 54
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A startQuery() 0 13 2
A stopQuery() 0 7 2
1
<?php
2
3
namespace Communibase\Logging;
4
5
/**
6
 * Includes executed Queries in a Debug Stack.
7
 */
8
class DebugStack implements QueryLogger
9
{
10
    /**
11
     * Executed queries.
12
     *
13
     * @var array
14
     */
15
    public $queries = [];
16
17
    /**
18
     * If Debug Stack is enabled (log queries) or not.
19
     *
20
     * @var boolean
21
     */
22
    public $enabled = true;
23
24
    /**
25
     * @var float|null
26
     */
27
    public $start;
28
29
    /**
30
     * @var integer
31
     */
32
    public $currentQuery = 0;
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function startQuery($query, array $params = null, array $data = null)
38
    {
39
        if (!$this->enabled) {
40
            return;
41
        }
42
        $this->start = microtime(true);
43
        $this->queries[++$this->currentQuery] = [
44
            'query' => $query,
45
            'params' => $params,
46
            'data' => $data,
47
            'executionMS' => 0
48
        ];
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function stopQuery()
55
    {
56
        if (!$this->enabled) {
57
            return;
58
        }
59
        $this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start;
60
    }
61
}
62