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

daycry / doctrine / 16045998748

03 Jul 2025 08:53AM UTC coverage: 78.852% (-1.3%) from 80.15%
16045998748

push

github

daycry
Feature: Doctrine Collector

- Add doctrine collector to codeigniter toolbar

49 of 66 new or added lines in 3 files covered. (74.24%)

261 of 331 relevant lines covered (78.85%)

15.57 hits per line

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

82.22
/src/Collectors/DoctrineQueryMiddleware.php
1
<?php
2

3
namespace Daycry\Doctrine\Collectors;
4

5
use Doctrine\DBAL\Driver;
6
use Doctrine\DBAL\Driver\API\ExceptionConverter;
7
use Doctrine\DBAL\Driver\Connection as DriverConnection;
8
use Doctrine\DBAL\Driver\Middleware;
9
use Doctrine\DBAL\Platforms\AbstractPlatform;
10
use Doctrine\DBAL\ServerVersionProvider;
11

12
class DoctrineQueryMiddleware implements Middleware
13
{
14
    protected $collector;
15

16
    public function __construct(DoctrineCollector $collector)
17
    {
18
        $this->collector = $collector;
52✔
19
    }
20

21
    public function wrap(Driver $driver): Driver
22
    {
23
        $collector = $this->collector;
52✔
24

25
        return new class ($driver, $collector) implements Driver {
52✔
26
            private $driver;
27
            private $collector;
28

29
            public function __construct(Driver $driver, DoctrineCollector $collector)
30
            {
31
                $this->driver    = $driver;
52✔
32
                $this->collector = $collector;
52✔
33
            }
34

35
            public function connect(array $params): DriverConnection
36
            {
37
                $conn      = $this->driver->connect($params);
44✔
38
                $collector = $this->collector;
44✔
39

40
                return new class ($conn, $collector) implements DriverConnection {
44✔
41
                    private $conn;
42
                    private $collector;
43

44
                    public function __construct(DriverConnection $conn, DoctrineCollector $collector)
45
                    {
46
                        $this->conn      = $conn;
44✔
47
                        $this->collector = $collector;
44✔
48
                    }
49

50
                    public function prepare(string $sql): Driver\Statement
51
                    {
52
                        $start = microtime(true);
22✔
53
                        $stmt  = $this->conn->prepare($sql);
22✔
54
                        $this->collector->addQuery([
22✔
55
                            'sql'      => $sql,
22✔
56
                            'params'   => [],
22✔
57
                            'types'    => [],
22✔
58
                            'start'    => $start,
22✔
59
                            'end'      => null,
22✔
60
                            'duration' => null,
22✔
61
                        ]);
22✔
62

63
                        return $stmt;
22✔
64
                    }
65

66
                    public function query(string $sql): Driver\Result
67
                    {
68
                        $start  = microtime(true);
24✔
69
                        $result = $this->conn->query($sql);
24✔
70
                        $end    = microtime(true);
24✔
71
                        $this->collector->addQuery([
24✔
72
                            'sql'      => $sql,
24✔
73
                            'params'   => [],
24✔
74
                            'types'    => [],
24✔
75
                            'start'    => $start,
24✔
76
                            'end'      => $end,
24✔
77
                            'duration' => $end - $start,
24✔
78
                        ]);
24✔
79

80
                        return $result;
24✔
81
                    }
82

83
                    public function beginTransaction(): void
84
                    {
NEW
85
                        $this->conn->beginTransaction();
×
86
                    }
87

88
                    public function commit(): void
89
                    {
NEW
90
                        $this->conn->commit();
×
91
                    }
92

93
                    public function rollBack(): void
94
                    {
NEW
95
                        $this->conn->rollBack();
×
96
                    }
97

98
                    public function lastInsertId(): int|string
99
                    {
NEW
100
                        return $this->conn->lastInsertId();
×
101
                    }
102

103
                    public function quote(string $value): string
104
                    {
NEW
105
                        return $this->conn->quote($value);
×
106
                    }
107

108
                    public function exec(string $sql): int
109
                    {
NEW
110
                        return $this->conn->exec($sql);
×
111
                    }
112

113
                    public function getNativeConnection(): object
114
                    {
NEW
115
                        return $this->conn->getNativeConnection();
×
116
                    }
117

118
                    public function getServerVersion(): string
119
                    {
120
                        return method_exists($this->conn, 'getServerVersion') ? $this->conn->getServerVersion() : 'unknown';
44✔
121
                    }
122
                };
44✔
123
            }
124

125
            public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform
126
            {
127
                return $this->driver->getDatabasePlatform($versionProvider);
52✔
128
            }
129

130
            public function getExceptionConverter(): ExceptionConverter
131
            {
NEW
132
                return $this->driver->getExceptionConverter();
×
133
            }
134
        };
52✔
135
    }
136
}
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