• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daycry / doctrine / 40847823331

29 Oct 2026 09:12AM UTC coverage: 93.52% (+0.3%) from 93.219%
40847823331

Pull #22

github

web-flow
Merge a6b38eda7 into 3fe444e81
Pull Request #22: Release 6.0: PHP 8.5 standalone core and CodeIgniter 4 adapter

435 of 468 new or added lines in 23 files covered. (92.95%)

967 of 1034 relevant lines covered (93.52%)

25.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.43
/src/Logging/QueryMiddleware.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Daycry\Doctrine\Logging;
6

7
use Closure;
8
use Doctrine\DBAL\Driver;
9
use Doctrine\DBAL\Driver\Connection;
10
use Doctrine\DBAL\Driver\Middleware;
11
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
12
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
13
use Doctrine\DBAL\Driver\Middleware\AbstractStatementMiddleware;
14
use Doctrine\DBAL\Driver\Result;
15
use Doctrine\DBAL\Driver\Statement;
16
use Doctrine\DBAL\ParameterType;
17

18
/**
19
 * Shared instrumentation for successful DBAL queries.
20
 */
21
abstract class QueryMiddleware implements Middleware
22
{
23
    /**
24
     * @param array<int|string, mixed> $params
25
     */
26
    abstract protected function onQuery(string $sql, array $params, float $start, float $duration): void;
27

28
    public function wrap(Driver $driver): Driver
135 ✔
29
    {
30
        return new class ($driver, $this->onQuery(...)) extends AbstractDriverMiddleware {
135 ✔
31
            public function __construct(Driver $driver, private readonly Closure $record)
32
            {
33
                parent::__construct($driver);
135 ✔
34
            }
35

36
            public function connect(array $params): Connection
37
            {
38
                return new class (parent::connect($params), $this->record) extends AbstractConnectionMiddleware {
90 ✔
39
                    public function __construct(private readonly Connection $connection, private readonly Closure $record)
40
                    {
41
                        parent::__construct($connection);
90 ✔
42
                    }
43

44
                    public function prepare(string $sql): Statement
45
                    {
46
                        return new class (parent::prepare($sql), $sql, $this->record) extends AbstractStatementMiddleware {
42 ✔
47
                            /**
48
                             * @var array<int|string, mixed>
49
                             */
50
                            private array $params = [];
51

52
                            public function __construct(Statement $statement, private readonly string $sql, private readonly Closure $record)
53
                            {
54
                                parent::__construct($statement);
42 ✔
55
                            }
56

57
                            public function bindValue(int|string $param, mixed $value, ParameterType $type): void
58
                            {
59
                                parent::bindValue($param, $value, $type);
42 ✔
60
                                $this->params[$param] = $value;
42 ✔
61
                            }
62

63
                            public function execute(): Result
64
                            {
65
                                $start  = microtime(true);
42 ✔
66
                                $timer  = hrtime(true);
42 ✔
67
                                $result = parent::execute();
42 ✔
68
                                ($this->record)($this->sql, $this->params, $start, (float) (hrtime(true) - $timer) / 1e9);
42 ✔
69

70
                                return $result;
42 ✔
71
                            }
72
                        };
42 ✔
73
                    }
74

75
                    public function query(string $sql): Result
76
                    {
77
                        $start  = microtime(true);
52 ✔
78
                        $timer  = hrtime(true);
52 ✔
79
                        $result = parent::query($sql);
52 ✔
80
                        ($this->record)($sql, [], $start, (float) (hrtime(true) - $timer) / 1e9);
50 ✔
81

82
                        return $result;
50 ✔
83
                    }
84

85
                    public function exec(string $sql): int|string
86
                    {
87
                        $start  = microtime(true);
25 ✔
88
                        $timer  = hrtime(true);
25 ✔
89
                        $result = parent::exec($sql);
25 ✔
90
                        ($this->record)($sql, [], $start, (float) (hrtime(true) - $timer) / 1e9);
25 ✔
91

92
                        return $result;
25 ✔
93
                    }
94

95
                    /**
96
                     * @param array<int|string, mixed> $arguments
97
                     */
98
                    public function __call(string $name, array $arguments): mixed
99
                    {
NEW
100
                        return $this->connection->{$name}(...$arguments);
×
101
                    }
102
                };
90 ✔
103
            }
104
        };
135 ✔
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc