Statement::bindValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
nc 1
nop 3
dl 0
loc 6
c 0
b 0
f 0
cc 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of orm
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\Orm\Infrastructure\Logging;
13
14
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
15
use Doctrine\DBAL\Driver\Result as ResultInterface;
16
use Doctrine\DBAL\Driver\Statement as StatementInterface;
17
use Doctrine\DBAL\ParameterType;
18
use Psr\Log\LoggerInterface;
19
20
/**
21
 * Statement
22
 *
23
 * @package Slick\Orm\Infrastructure\Logging
24
 */
25
final class Statement extends AbstractStatementMiddleware
26
{
27
    /** @var array<int|string, mixed>  */
28
    private array $params = [];
29
30
    /** @var array<int,ParameterType>|array<string,ParameterType> */
31
    private array $types = [];
32
33
    /** @internal This statement can be only instantiated by its connection. */
34
    public function __construct(
35
        StatementInterface $statement,
36
        private readonly LoggerInterface $logger,
37
        private readonly string $sql,
38
    ) {
39
        parent::__construct($statement);
40
    }
41
42
    public function bindValue(int|string $param, mixed $value, ParameterType $type): void
43
    {
44
        $this->params[$param] = $value;
45
        $this->types[$param]  = $type;
46
47
        parent::bindValue($param, $value, $type);
48
    }
49
50
    public function execute(): ResultInterface
51
    {
52
        $time = microtime(true);
53
        $result = parent::execute();
54
        $duration = microtime(true) - $time;
55
        $this->logger->debug('Executing statement: {sql} (parameters: {params}, types: {types})', [
56
            'sql'    => $this->sql,
57
            'params' => $this->params,
58
            'types'  => $this->types,
59
            'duration'  => $duration
60
        ]);
61
62
        return $result;
63
    }
64
}
65