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

daycry / doctrine / 24675033129

20 Apr 2026 03:26PM UTC coverage: 78.027% (+1.9%) from 76.142%
24675033129

push

github

daycry
Fixes & improvements

Fixes & improvements

122 of 157 new or added lines in 8 files covered. (77.71%)

51 existing lines in 5 files now uncovered.

522 of 669 relevant lines covered (78.03%)

10.3 hits per line

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

92.75
/src/Debug/Toolbar/Collectors/DoctrineQueryMiddleware.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Daycry\Doctrine\Debug\Toolbar\Collectors;
6

7
use Doctrine\DBAL\Driver;
8
use Doctrine\DBAL\Driver\API\ExceptionConverter;
9
use Doctrine\DBAL\Driver\Connection;
10
use Doctrine\DBAL\Driver\Middleware;
11
use Doctrine\DBAL\Driver\Result;
12
use Doctrine\DBAL\Driver\Statement;
13
use Doctrine\DBAL\ParameterType;
14
use Doctrine\DBAL\Platforms\AbstractPlatform;
15
use Doctrine\DBAL\ServerVersionProvider;
16

17
class DoctrineQueryMiddleware implements Middleware
18
{
19
    protected DoctrineCollector $collector;
20

21
    public function __construct(DoctrineCollector $collector)
46✔
22
    {
23
        $this->collector = $collector;
46✔
24
    }
25

26
    public function wrap(Driver $driver): Driver
46✔
27
    {
28
        $collector = $this->collector;
46✔
29

30
        return new class ($driver, $collector) implements Driver {
46✔
31
            private Driver $driver;
32
            private DoctrineCollector $collector;
33

34
            public function __construct(Driver $driver, DoctrineCollector $collector)
35
            {
36
                $this->driver    = $driver;
46✔
37
                $this->collector = $collector;
46✔
38
            }
39

40
            public function connect(array $params): Connection
41
            {
42
                $conn      = $this->driver->connect($params);
40✔
43
                $collector = $this->collector;
40✔
44

45
                return new class ($conn, $collector) implements Connection {
40✔
46
                    private Connection $conn;
47
                    private DoctrineCollector $collector;
48

49
                    public function __construct(Connection $conn, DoctrineCollector $collector)
50
                    {
51
                        $this->conn      = $conn;
40✔
52
                        $this->collector = $collector;
40✔
53
                    }
54

55
                    public function prepare(string $sql): Statement
56
                    {
57
                        $innerStmt = $this->conn->prepare($sql);
17✔
58
                        $collector = $this->collector;
17✔
59

60
                        return new class ($innerStmt, $sql, $collector) implements Statement {
17✔
61
                            private Statement $innerStmt;
62
                            private string $sql;
63
                            private DoctrineCollector $collector;
64

65
                            /**
66
                             * @var array<int|string, mixed>
67
                             */
68
                            private array $params = [];
69

70
                            public function __construct(Statement $innerStmt, string $sql, DoctrineCollector $collector)
71
                            {
72
                                $this->innerStmt = $innerStmt;
17✔
73
                                $this->sql       = $sql;
17✔
74
                                $this->collector = $collector;
17✔
75
                            }
76

77
                            public function bindValue(int|string $param, mixed $value, ParameterType $type): void
78
                            {
79
                                $this->params[$param] = $value;
17✔
80
                                $this->innerStmt->bindValue($param, $value, $type);
17✔
81
                            }
82

83
                            public function execute(): Result
84
                            {
85
                                $start  = microtime(true);
17✔
86
                                $result = $this->innerStmt->execute();
17✔
87
                                $end    = microtime(true);
17✔
88
                                $this->collector->addQuery([
17✔
89
                                    'sql'      => $this->sql,
17✔
90
                                    'params'   => $this->params,
17✔
91
                                    'types'    => [],
17✔
92
                                    'start'    => $start,
17✔
93
                                    'end'      => $end,
17✔
94
                                    'duration' => ($end - $start) * 1000,
17✔
95
                                ]);
17✔
96

97
                                return $result;
17✔
98
                            }
99
                        };
17✔
100
                    }
101

102
                    public function query(string $sql): Result
103
                    {
104
                        $start  = microtime(true);
18✔
105
                        $result = $this->conn->query($sql);
18✔
106
                        $end    = microtime(true);
18✔
107
                        $this->collector->addQuery([
18✔
108
                            'sql'      => $sql,
18✔
109
                            'params'   => [],
18✔
110
                            'types'    => [],
18✔
111
                            'start'    => $start,
18✔
112
                            'end'      => $end,
18✔
113
                            'duration' => ($end - $start) * 1000, // Convert to milliseconds
18✔
114
                        ]);
18✔
115

116
                        return $result;
18✔
117
                    }
118

119
                    public function beginTransaction(): void
120
                    {
121
                        $this->conn->beginTransaction();
1✔
122
                    }
123

124
                    public function commit(): void
125
                    {
126
                        $this->conn->commit();
1✔
127
                    }
128

129
                    public function rollBack(): void
130
                    {
131
                        $this->conn->rollBack();
×
132
                    }
133

134
                    public function lastInsertId(): int|string
135
                    {
136
                        return $this->conn->lastInsertId();
1✔
137
                    }
138

139
                    public function getNativeConnection()
140
                    {
141
                        return $this->conn->getNativeConnection();
×
142
                    }
143

144
                    public function exec(string $sql): int|string
145
                    {
146
                        $start  = microtime(true);
1✔
147
                        $result = $this->conn->exec($sql);
1✔
148
                        $end    = microtime(true);
1✔
149
                        $this->collector->addQuery([
1✔
150
                            'sql'      => $sql,
1✔
151
                            'params'   => [],
1✔
152
                            'types'    => [],
1✔
153
                            'start'    => $start,
1✔
154
                            'end'      => $end,
1✔
155
                            'duration' => ($end - $start) * 1000,
1✔
156
                        ]);
1✔
157

158
                        return $result;
1✔
159
                    }
160

161
                    public function quote(string $value): string
162
                    {
163
                        return $this->conn->quote($value);
×
164
                    }
165

166
                    public function getServerVersion(): string
167
                    {
168
                        return $this->conn->getServerVersion();
39✔
169
                    }
170

171
                    /**
172
                     * @param array<int|string, mixed> $arguments
173
                     */
174
                    public function __call(string $name, array $arguments): mixed
175
                    {
176
                        /** @var mixed */
UNCOV
177
                        return $this->conn->{$name}(...$arguments);
×
178
                    }
179
                };
40✔
180
            }
181

182
            public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform
183
            {
184
                return $this->driver->getDatabasePlatform($versionProvider);
46✔
185
            }
186

187
            public function getExceptionConverter(): ExceptionConverter
188
            {
189
                return $this->driver->getExceptionConverter();
×
190
            }
191
        };
46✔
192
    }
193
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc