Statement   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
dl 0
loc 33
rs 10
c 1
b 0
f 0
ccs 0
cts 14
cp 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A bindValue() 0 5 1
A __construct() 0 5 1
A execute() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\DBAL\Logging;
6
7
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
8
use Doctrine\DBAL\Driver\Result;
9
use Doctrine\DBAL\Driver\Statement as StatementInterface;
10
use Doctrine\DBAL\ParameterType;
11
12
final class Statement extends AbstractStatementMiddleware
13
{
14
    /**
15
     * @var array<int,mixed>|array<string,mixed>
16
     */
17
    private array $params = [];
18
19
    public function __construct(
20
        StatementInterface $statement,
21
        private readonly string $sql,
22
    ) {
23
        parent::__construct($statement);
24
    }
25
26
    public function bindValue(int|string $param, mixed $value, ParameterType $type): void
27
    {
28
        $this->params[$param] = $value;
29
30
        parent::bindValue($param, $value, $type);
31
    }
32
33
    public function execute(): Result
34
    {
35
        $start = microtime(true);
36
        $result = parent::execute();
37
        $end = microtime(true);
38
39
        _log()->debug($this->sql, [
40
            'params' => $this->params,
41
            'time' => number_format(($end - $start) / 1000, 6),
42
        ]);
43
44
        return $result;
45
    }
46
}
47