10000 Restore PHP8 features for Doctrine debug middlewares · symfony/symfony@f0ff902 · GitHub
[go: up one dir, main page]

Skip to content

Commit f0ff902

Browse files
committed
Restore PHP8 features for Doctrine debug middlewares
1 parent 5102746 commit f0ff902

File tree

8 files changed

+71
-158
lines changed

8 files changed

+71
-158
lines changed

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,20 @@
2929
*/
3030
class DoctrineDataCollector extends DataCollector
3131
{
32-
private $registry;
3332
private array $connections;
3433
private array $managers;
35-
private ?DebugDataHolder $debugDataHolder;
3634

3735
/**
3836
* @var array<string, DebugStack>
3937
*/
4038
private array $loggers = [];
4139

42-
public function __construct(ManagerRegistry $registry, DebugDataHolder $debugDataHolder = null)
43-
{
44-
$this->registry = $registry;
40+
public function __construct(
41+
private ManagerRegistry $registry,
42+
private ?DebugDataHolder $debugDataHolder = null,
43+
) {
4544
$this->connections = $registry->getConnectionNames();
4645
$this->managers = $registry->getManagerNames();
47-
$this->debugDataHolder = $debugDataHolder;
4846
}
4947

5048
/**

src/Symfony/Bridge/Doctrine/Middleware/Debug/Connection.php

Lines changed: 25 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@
2424
*/
2525
final class Connection extends AbstractConnectionMiddleware
2626
{
27-
private $nestingLevel = 0;
28-
private $debugDataHolder;
29-
private $stopwatch;
30-
private $connectionName;
31-
32-
public function __construct(ConnectionInterface $connection, DebugDataHolder $debugDataHolder, ?Stopwatch $stopwatch, string $connectionName)
33-
{
27+
private int $nestingLevel = 0;
28+
29+
public function __construct(
30+
ConnectionInterface $connection,
31+
private DebugDataHolder $debugDataHolder,
32+
private ?Stopwatch $stopwatch,
33+
private string $connectionName,
34+
) {
3435
parent::__construct($connection);
35-
36-
$this->debugDataHolder = $debugDataHolder;
37-
$this->stopwatch = $stopwatch;
38-
$this->connectionName = $connectionName;
3936< B41A code class="diff-text syntax-highlighted-line">
}
4037

4138
public function prepare(string $sql): DriverStatement
@@ -44,28 +41,22 @@ public function prepare(string $sql): DriverStatement
4441
parent::prepare($sql),
4542
$this->debugDataHolder,
4643
$this->connectionName,
47-
$sql
44+
$sql,
4845
);
4946
}
5047

5148
public function query(string $sql): Result
5249
{
5350
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query($sql));
5451

55-
if (null !== $this->stopwatch) {
56-
$this->stopwatch->start('doctrine', 'doctrine');
57-
}
58-
52+
$this->stopwatch?->start('doctrine', 'doctrine');
5953
$query->start();
6054

6155
try {
6256
$result = parent::query($sql);
6357
} finally {
6458
$query->stop();
65-
66-
if (null !== $this->stopwatch) {
67-
$this->stopwatch->stop('doctrine');
68-
}
59+
$this->stopwatch?->stop('doctrine');
6960
}
7061

7162
return $result;
@@ -75,20 +66,14 @@ public function exec(string $sql): int
7566
{
7667
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query($sql));
7768

78-
if (null !== $this->stopwatch) {
79-
$this->stopwatch->start('doctrine', 'doctrine');
80-
}
81-
69+
$this->stopwatch?->start('doctrine', 'doctrine');
8270
$query->start();
8371

8472
try {
8573
$affectedRows = parent::exec($sql);
8674
} finally {
8775
$query->stop();
88-
89-
if (null !== $this->stopwatch) {
90-
$this->stopwatch->stop('doctrine');
91-
}
76+
$this->stopwatch?->stop('doctrine');
9277
}
9378

9479
return $affectedRows;
@@ -101,24 +86,14 @@ public function beginTransaction(): bool
10186
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"START TRANSACTION"'));
10287
}
10388

104-
if (null !== $this->stopwatch) {
105-
$this->stopwatch->start('doctrine', 'doctrine');
106-
}
107-
108-
if (null !== $query) {
109-
$query->start();
110-
}
89+
$this->stopwatch?->start('doctrine', 'doctrine');
90+
$query?->start();
11191

11292
try {
11393
$ret = parent::beginTransaction();
11494
} finally {
115-
if (null !== $query) {
116-
$query->stop();
117-
}
118-
119-
if (null !== $this->stopwatch) {
120-
$this->stopwatch->stop('doctrine');
121-
}
95+
$query?->stop();
96+
$this->stopwatch?->stop('doctrine');
12297
}
12398

12499
return $ret;
@@ -131,24 +106,14 @@ public function commit(): bool
131106
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"COMMIT"'));
132107
}
133108

134-
if (null !== $this->stopwatch) {
135-
$this->stopwatch->start('doctrine', 'doctrine');
136-
}
137-
138-
if (null !== $query) {
139-
$query->start();
140-
}
109+
$this->stopwatch?->start('doctrine', 'doctrine');
110+
$query?->start();
141111

142112
try {
143113
$ret = parent::commit();
144114
} finally {
145-
if (null !== $query) {
146-
$query->stop();
147-
}
148-
149-
if (null !== $this->stopwatch) {
150-
$this->stopwatch->stop('doctrine');
151-
}
115+
$query?->stop();
116+
$this->stopwatch?->stop('doctrine');
152117
}
153118

154119
return $ret;
@@ -161,24 +126,14 @@ public function rollBack(): bool
161126
$this->debugDataHolder->addQuery($this->connectionName, $query = new Query('"ROLLBACK"'));
162127
}
163128

164-
if (null !== $this->stopwatch) {
165-
$this->stopwatch->start('doctrine', 'doctrine');
166-
}
167-
168-
if (null !== $query) {
169-
$query->start();
170-
}
129+
$this->stopwatch?->start('doctrine', 'doctrine');
130+
$query?->start();
171131

172132
try {
173133
$ret = parent::rollBack();
174134
} finally {
175-
if (null !== $query) {
176-
$query->stop();
177-
}
178-
179-
if (null !== $this->stopwatch) {
180-
$this->stopwatch->stop('doctrine');
181-
}
135+
$query?->stop();
136+
$this->stopwatch?->stop('doctrine');
182137
}
183138

184139
return $ret;

src/Symfony/Bridge/Doctrine/Middleware/Debug/DebugDataHolder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class DebugDataHolder
1818
{
19-
private $data = [];
19+
private array $data = [];
2020

2121
public function addQuery(string $connectionName, Query $query): void
2222
{

src/Symfony/Bridge/Doctrine/Middleware/Debug/Driver.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,13 @@
2222
*/
2323
final class Driver extends AbstractDriverMiddleware
2424
{
25-
private $debugDataHolder;
26-
private $stopwatch;
27-
private $connectionName;
28-
29-
public function __construct(DriverInterface $driver, DebugDataHolder $debugDataHolder, ?Stopwatch $stopwatch, string $connectionName)
30-
{
25+
public function __construct(
26+
DriverInterface $driver,
27+
private DebugDataHolder $debugDataHolder,
28+
private ?Stopwatch $stopwatch,
29+
private string $connectionName,
30+
) {
3131
parent::__construct($driver);
32-
33-
$this->debugDataHolder = $debugDataHolder;
34-
$this->stopwatch = $stopwatch;
35-
$this->connectionName = $connectionName;
3632
}
3733

3834
public function connect(array $params): Connection
@@ -41,7 +37,7 @@ public function connect(array $params): Connection
4137
parent::connect($params),
4238
$this->debugDataHolder,
4339
$this->stopwatch,
44-
$this->connectionName
40+
$this->connectionName,
4541
);
4642
}
4743
}

src/Symfony/Bridge/Doctrine/Middleware/Debug/Middleware.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@
2222
*/
2323
final class Middleware implements MiddlewareInterface
2424
{
25-
private $debugDataHolder;
26-
private $stopwatch;
27-
private $connectionName;
28-
29-
public function __construct(DebugDataHolder $debugDataHolder, ?Stopwatch $stopwatch, string $connectionName = 'default')
30-
{
31-
$this->debugDataHolder = $debugDataHolder;
32-
$this->stopwatch = $stopwatch;
33-
$this->connectionName = $connectionName;
25+
public function __construct(
26+
private DebugDataHolder $debugDataHolder,
27+
private ?Stopwatch $stopwatch,
28+
private string $connectionName = 'default',
29+
) {
3430
}
3531

3632
public function wrap(DriverInterface $driver): DriverInterface

src/Symfony/Bridge/Doctrine/Middleware/Debug/Query.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
*/
2121
class Query
2222
{
23-
private $params = [];
24-
private $types = [];
23+
private array $params = [];
24+
private array $types = [];
2525

26-
private $start;
27-
private $duration;
26+
private ?float $start = null;
27+
private ?float $duration = null;
2828

29-
private $sql;
30-
31-
public function __construct(string $sql)
32-
{
33-
$this->sql = $sql;
29+
public function __construct(
30+
private string $sql,
31+
) {
3432
}
3533

3634
public function start(): void
@@ -45,11 +43,7 @@ public function stop(): void
4543
}
4644
}
4745

48-
/**
49-
* @param string|int $param
50-
* @param string|int|float|bool|null $variable
51-
*/
52-
public function setParam($param, &$variable, int $type): void
46+
public function setParam(string|int $param, null|string|int|float|bool &$variable, int $type): void
5347
{
5448
// Numeric indexes start at 0 in profiler
5549
$idx = \is_int($param) ? $param - 1 : $param;
@@ -58,11 +52,7 @@ public function setParam($param, &$variable, int $type): void
5852
$this->types[$idx] = $type;
5953
}
6054

61-
/**
62-
* @param string|int $param
63-
* @param string|int|float|bool|null $value
64-
*/
65-
public function setValue($param, $value, int $type): void
55+
public function setValue(string|int $param, null|string|int|float|bool $value, int $type): void
6656
{
6757
// Numeric indexes start at 0 in profiler
6858
$idx = \is_int($param) ? $param - 1 : $param;

src/Symfony/Bridge/Doctrine/Middleware/Debug/Statement.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
*/
2424
final class Statement extends AbstractStatementMiddleware
2525
{
26-
private $debugDataHolder;
27-
private $connectionName;
28-
private $query;
26+
private Query $query;
2927

30-
public function __construct(StatementInterface $statement, DebugDataHolder $debugDataHolder, string $connectionName, string $sql)
31-
{
28+
public function __construct(
29+
StatementInterface $statement,
30+
private DebugDataHolder $debugDataHolder,
31+
private string $connectionName,
32+
string $sql,
33+
) {
3234
parent::__construct($statement);
3335

34-
$this->debugDataHolder = $debugDataHolder;
35-
$this->connectionName = $connectionName;
3636
$this->query = new Query($sql);
3737
}
3838

0 commit comments

Comments
 (0)
0