Statement::bindValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
ccs 0
cts 3
cp 0
cc 1
nc 1
nop 3
crap 2
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