Passed
Pull Request — master (#160)
by Dmitriy
02:49
created

DatabaseCollector   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 38
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A collectQuery() 0 7 1
A getCollected() 0 3 1
A collect() 0 3 1
A getIndexData() 0 5 1
A reset() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector\Database;
6
7
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
8
use Yiisoft\Yii\Debug\Collector\CollectorTrait;
9
use Yiisoft\Yii\Debug\Collector\IndexCollectorInterface;
10
11
class DatabaseCollector implements CollectorInterface, IndexCollectorInterface
12
{
13
    use CollectorTrait;
14
15
    private array $queries = [];
16
17
    public function getCollected(): array
18
    {
19
        return $this->queries;
20
    }
21
22
    public function collect(string $sql, array $params, string $line): void
23
    {
24
        $this->collectQuery($sql, $params, $line);
25
    }
26
27
    private function collectQuery(string $sql, array $params, string $line): void
28
    {
29
        $this->queries[] = [
30
            'rawSql' => $sql,
31
            'params' => $params,
32
            'line' => $line,
33
            'time' => microtime(true),
34
        ];
35
    }
36
37
    public function getIndexData(): array
38
    {
39
        return [
40
            'db' => [
41
                'total' => count($this->queries),
42
            ],
43
        ];
44
    }
45
46
    private function reset(): void
0 ignored issues
show
Unused Code introduced by
The method reset() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
47
    {
48
        $this->queries = [];
49
    }
50
}
51