24
24
*/
25
25
final class Connection extends AbstractConnectionMiddleware
26
26
{
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
+ ) {
34
35
parent ::__construct ($ connection );
35
-
36
- $ this ->debugDataHolder = $ debugDataHolder ;
37
- $ this ->stopwatch = $ stopwatch ;
38
- $ this ->connectionName = $ connectionName ;
39
36
}
40
37
41
38
public function prepare (string $ sql ): DriverStatement
@@ -44,28 +41,22 @@ public function prepare(string $sql): DriverStatement
44
41
parent ::prepare ($ sql ),
45
42
$ this ->debugDataHolder ,
46
43
$ this ->connectionName ,
47
- $ sql
44
+ $ sql,
48
45
);
49
46
}
50
47
51
48
public function query (string $ sql ): Result
52
49
{
53
50
$ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ($ sql ));
54
51
55
- if (null !== $ this ->stopwatch ) {
56
- $ this ->stopwatch ->start ('doctrine ' , 'doctrine ' );
57
- }
58
-
52
+ $ this ->stopwatch ?->start('doctrine ' , 'doctrine ' );
59
53
$ query ->start ();
60
54
61
55
try {
62
56
$ result = parent ::query ($ sql );
63
57
} finally {
64
58
$ query ->stop ();
65
-
66
- if (null !== $ this ->stopwatch ) {
67
- $ this ->stopwatch ->stop ('doctrine ' );
68
- }
59
+ $ this ->stopwatch ?->stop('doctrine ' );
69
60
}
70
61
71
62
return $ result ;
@@ -75,20 +66,14 @@ public function exec(string $sql): int
75
66
{
76
67
$ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ($ sql ));
77
68
78
- if (null !== $ this ->stopwatch ) {
79
- $ this ->stopwatch ->start ('doctrine ' , 'doctrine ' );
80
- }
81
-
69
+ $ this ->stopwatch ?->start('doctrine ' , 'doctrine ' );
82
70
$ query ->start ();
83
71
84
72
try {
85
73
$ affectedRows = parent ::exec ($ sql );
86
74
} finally {
87
75
$ query ->stop ();
88
-
89
- if (null !== $ this ->stopwatch ) {
90
- $ this ->stopwatch ->stop ('doctrine ' );
91
- }
76
+ $ this ->stopwatch ?->stop('doctrine ' );
92
77
}
93
78
94
79
return $ affectedRows ;
@@ -101,24 +86,14 @@ public function beginTransaction(): bool
101
86
$ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ('"START TRANSACTION" ' ));
102
87
}
103
88
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();
111
91
112
92
try {
113
93
$ ret = parent ::beginTransaction ();
114
94
} 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 ' );
122
97
}
123
98
124
99
return $ ret ;
@@ -131,24 +106,14 @@ public function commit(): bool
131
106
$ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ('"COMMIT" ' ));
132
107
}
133
108
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();
141
111
142
112
try {
143
113
$ ret = parent ::commit ();
144
114
} 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 ' );
152
117
}
153
118
154
119
return $ ret ;
@@ -161,24 +126,14 @@ public function rollBack(): bool
161
126
$ this ->debugDataHolder ->addQuery ($ this ->connectionName , $ query = new Query ('"ROLLBACK" ' ));
162
127
}
163
128
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();
171
131
172
132
try {
173
133
$ ret = parent ::rollBack ();
174
134
} 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 ' );
182
137
}
183
138
184
139
return $ ret ;
0 commit comments