SQLLogger::getCurrentBenchmark()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author Fabian Fuelling <[email protected]>
4
 * @created: 17.12.14 17:11
5
 */
6
7
namespace Fabfuel\Prophiler\Adapter\Doctrine;
8
9
use Doctrine\DBAL\Logging\SQLLogger as DoctrineSQLLogger;
10
use Fabfuel\Prophiler\Adapter\AdapterAbstract;
11
use Fabfuel\Prophiler\Benchmark\BenchmarkInterface;
12
13
class SQLLogger extends AdapterAbstract implements DoctrineSQLLogger
14
{
15
    /**
16
     * @var BenchmarkInterface
17
     */
18
    protected $currentBenchmark;
19
20
    /**
21
     * Logs a SQL statement
22
     *
23
     * @param string $sql The SQL to be executed
24
     * @param array|null $params The SQL parameters
25
     * @param array|null $types The SQL parameter types
26
     * @return void
27
     */
28 1
    public function startQuery($sql, array $params = null, array $types = null)
29
    {
30
        $metadata = [
31 1
            'query' => $sql,
32 1
            'params' => $params,
33 1
            'types' => $types,
34 1
        ];
35 1
        $this->setCurrentBenchmark($this->profiler->start('Doctrine::query', $metadata, 'Database'));
36 1
    }
37
38
    /**
39
     * Marks the last started query as stopped
40
     *
41
     * @return void
42
     */
43 1
    public function stopQuery()
44
    {
45 1
        $this->profiler->stop($this->getCurrentBenchmark());
46 1
    }
47
48
    /**
49
     * @return BenchmarkInterface
50
     */
51 1
    public function getCurrentBenchmark()
52
    {
53 1
        return $this->currentBenchmark;
54
    }
55
56
    /**
57
     * @param BenchmarkInterface $currentBenchmark
58
     */
59 1
    public function setCurrentBenchmark(BenchmarkInterface $currentBenchmark)
60
    {
61 1
        $this->currentBenchmark = $currentBenchmark;
62 1
    }
63
}
64