Completed
Pull Request — 1.x (#4)
by Yuu
38:06
created

PsrSqlLogger::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the Ray.DoctrineOrmModule package
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\DoctrineOrmModule\Logger;
8
9
use Doctrine\DBAL\Logging\SQLLogger;
10
use Psr\Log\LoggerInterface;
11
12
class PsrSqlLogger implements SQLLogger
13
{
14
    /**
15
     * @var LoggerInterface
16
     */
17
    private $logger;
18
19
    /**
20
     * @var float
21
     */
22
    private $start;
23
24
    /**
25
     * constructor.
26
     *
27
     * @param LoggerInterface $logger
28
     */
29 4
    public function __construct(LoggerInterface $logger)
30
    {
31 4
        $this->logger = $logger;
32 4
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 1
    public function startQuery($sql, array $params = null, array $types = null)
38
    {
39 1
        $this->logger->debug($sql, ['params' => $params, 'types' => $types]);
40 1
        $this->start = microtime(true);
41 1
    }
42
43
    /**
44
     * [@inheritdoc}
45
     */
46 1
    public function stopQuery()
47
    {
48 1
        $time = round(microtime(true) - $this->start, 3);
49 1
        $this->logger->debug('query execution time: ' . $time . 's');
50 1
    }
51
}
52