Passed
Push — main ( c11f66...ecdc1f )
by Thierry
18:56 queued 12:09
created

History::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver;
4
5
use function intval;
6
use function microtime;
7
use function preg_match;
8
9
class History
10
{
11
    /**
12
     * @var TranslatorInterface
13
     */
14
    protected $trans;
15
16
    /**
17
     * Executed queries
18
     *
19
     * @var array
20
     */
21
    protected $queries = [];
22
23
    /**
24
     * The constructor
25
     *
26
     * @param TranslatorInterface $trans
27
     */
28
    public function __construct(TranslatorInterface $trans)
29
    {
30
        $this->trans = $trans;
31
    }
32
33
    /**
34
     * Save a query in the history
35
     *
36
     * @param string $query
37
     *
38
     * @return void
39
     */
40
    public function save(string $query)
41
    {
42
        $this->queries[] = [
43
            'start' => intval(microtime(true)),
44
            'query' => (preg_match('~;$~', $query) ? "DELIMITER ;;\n$query;\nDELIMITER " : $query),
45
        ];
46
    }
47
48
    /**
49
     * Get the remembered queries
50
     *
51
     * @return array
52
     */
53
    public function queries()
54
    {
55
        return $this->queries;
56
    }
57
}