Psr3SqlLogger::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Doctrine\Tools;
4
5
use Doctrine\DBAL\Logging\SQLLogger;
6
use Psr\Log\LoggerInterface;
7
use Psr\Log\LogLevel;
8
9
class Psr3SqlLogger implements SQLLogger
10
{
11
    /** @var LoggerInterface */
12
    private $logger;
13
14
    /** @var string */
15
    private $level;
16
17
    /**
18
     * Constructor.
19
     *
20
     * @param LoggerInterface $logger
21
     * @param string          $level
22
     */
23 6
    public function __construct(LoggerInterface $logger = null, $level = LogLevel::DEBUG)
24
    {
25 6
        $this->logger = $logger;
26 6
        $this->level = $level;
27 6
    }
28
29
    /**
30
     * Logs a SQL statement somewhere.
31
     *
32
     * @param string $sql    The SQL to be executed.
33
     * @param array  $params The SQL parameters.
34
     * @param array  $types  The SQL parameter types.
35
     */
36 6
    public function startQuery($sql, array $params = null, array $types = null)
37
    {
38 6
        $this->logger && $this->logger->log(
39 3
            $this->level,
40 3
            'Execute SQL',
41
            [
42 3
                'query' => $sql,
43 3
                'params' => $params,
44 1
                'types' => $types
45 2
            ]
46 2
        );
47 6
    }
48
49
    /**
50
     * Marks the last started query as stopped. This can be used for timing of queries.
51
     */
52 6
    public function stopQuery()
53
    {
54 6
    }
55
}
56