2424 */
2525final 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 }
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 ;
0 commit comments