Conditions | 1 |
Paths | 1 |
Total Lines | 228 |
Code Lines | 146 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
163 | public function databaseUrls() : iterable |
||
164 | { |
||
165 | $driver = $this->createMock(Driver::class); |
||
166 | $driverClass = get_class($driver); |
||
167 | |||
168 | return [ |
||
169 | 'simple URL' => [ |
||
170 | 'mysql://foo:bar@localhost/baz', |
||
171 | [ |
||
172 | 'user' => 'foo', |
||
173 | 'password' => 'bar', |
||
174 | 'host' => 'localhost', |
||
175 | 'dbname' => 'baz', |
||
176 | 'driver' => PDOMySQLDriver::class, |
||
177 | ], |
||
178 | ], |
||
179 | 'simple URL with port' => [ |
||
180 | 'mysql://foo:bar@localhost:11211/baz', |
||
181 | [ |
||
182 | 'user' => 'foo', |
||
183 | 'password' => 'bar', |
||
184 | 'host' => 'localhost', |
||
185 | 'port' => 11211, |
||
186 | 'dbname' => 'baz', |
||
187 | 'driver' => PDOMySQLDriver::class, |
||
188 | ], |
||
189 | ], |
||
190 | 'sqlite relative URL with host' => [ |
||
191 | 'sqlite://localhost/foo/dbname.sqlite', |
||
192 | [ |
||
193 | 'path' => 'foo/dbname.sqlite', |
||
194 | 'driver' => PDOSqliteDriver::class, |
||
195 | ], |
||
196 | ], |
||
197 | 'sqlite absolute URL with host' => [ |
||
198 | 'sqlite://localhost//tmp/dbname.sqlite', |
||
199 | [ |
||
200 | 'path' => '/tmp/dbname.sqlite', |
||
201 | 'driver' => PDOSqliteDriver::class, |
||
202 | ], |
||
203 | ], |
||
204 | 'sqlite relative URL without host' => [ |
||
205 | 'sqlite:///foo/dbname.sqlite', |
||
206 | [ |
||
207 | 'path' => 'foo/dbname.sqlite', |
||
208 | 'driver' => PDOSqliteDriver::class, |
||
209 | ], |
||
210 | ], |
||
211 | 'sqlite absolute URL without host' => [ |
||
212 | 'sqlite:////tmp/dbname.sqlite', |
||
213 | [ |
||
214 | 'path' => '/tmp/dbname.sqlite', |
||
215 | 'driver' => PDOSqliteDriver::class, |
||
216 | ], |
||
217 | ], |
||
218 | 'sqlite memory' => [ |
||
219 | 'sqlite:///:memory:', |
||
220 | [ |
||
221 | 'memory' => true, |
||
222 | 'driver' => PDOSqliteDriver::class, |
||
223 | ], |
||
224 | ], |
||
225 | 'sqlite memory with host' => [ |
||
226 | 'sqlite://localhost/:memory:', |
||
227 | [ |
||
228 | 'memory' => true, |
||
229 | 'driver' => PDOSqliteDriver::class, |
||
230 | ], |
||
231 | ], |
||
232 | 'params parsed from URL override individual params' => [ |
||
233 | [ |
||
234 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
235 | 'password' => 'lulz', |
||
236 | ], |
||
237 | [ |
||
238 | 'user' => 'foo', |
||
239 | 'password' => 'bar', |
||
240 | 'host' => 'localhost', |
||
241 | 'dbname' => 'baz', |
||
242 | 'driver' => PDOMySQLDriver::class, |
||
243 | ], |
||
244 | ], |
||
245 | 'params not parsed from URL but individual params are preserved' => [ |
||
246 | [ |
||
247 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
248 | 'port' => 1234, |
||
249 | ], |
||
250 | [ |
||
251 | 'user' => 'foo', |
||
252 | 'password' => 'bar', |
||
253 | 'host' => 'localhost', |
||
254 | 'port' => 1234, |
||
255 | 'dbname' => 'baz', |
||
256 | 'driver' => PDOMySQLDriver::class, |
||
257 | ], |
||
258 | ], |
||
259 | 'query params from URL are used as extra params' => [ |
||
260 | 'url' => 'mysql://foo:bar@localhost/dbname?charset=UTF-8', |
||
261 | ['charset' => 'UTF-8'], |
||
262 | ], |
||
263 | 'simple URL with fallthrough scheme not defined in map' => [ |
||
264 | 'sqlsrv://foo:bar@localhost/baz', |
||
265 | [ |
||
266 | 'user' => 'foo', |
||
267 | 'password' => 'bar', |
||
268 | 'host' => 'localhost', |
||
269 | 'dbname' => 'baz', |
||
270 | 'driver' => SQLSrvDriver::class, |
||
271 | ], |
||
272 | ], |
||
273 | 'simple URL with fallthrough scheme containing underscores fails' => [ |
||
274 | 'pdo_mysql://foo:bar@localhost/baz', |
||
275 | false, |
||
276 | ], |
||
277 | 'simple URL with fallthrough scheme containing dashes works' => [ |
||
278 | 'pdo-mysql://foo:bar@localhost/baz', |
||
279 | [ |
||
280 | 'user' => 'foo', |
||
281 | 'password' => 'bar', |
||
282 | 'host' => 'localhost', |
||
283 | 'dbname' => 'baz', |
||
284 | 'driver' => PDOMySQLDriver::class, |
||
285 | ], |
||
286 | ], |
||
287 | 'simple URL with percent encoding' => [ |
||
288 | 'mysql://foo%3A:bar%2F@localhost/baz+baz%40', |
||
289 | [ |
||
290 | 'user' => 'foo:', |
||
291 | 'password' => 'bar/', |
||
292 | 'host' => 'localhost', |
||
293 | 'dbname' => 'baz+baz@', |
||
294 | 'driver' => PDOMySQLDriver::class, |
||
295 | ], |
||
296 | ], |
||
297 | 'simple URL with percent sign in password' => [ |
||
298 | 'mysql://foo:bar%25bar@localhost/baz', |
||
299 | [ |
||
300 | 'user' => 'foo', |
||
301 | 'password' => 'bar%bar', |
||
302 | 'host' => 'localhost', |
||
303 | 'dbname' => 'baz', |
||
304 | 'driver' => PDOMySQLDriver::class, |
||
305 | ], |
||
306 | ], |
||
307 | |||
308 | // DBAL-1234 |
||
309 | 'URL without scheme and without any driver information' => [ |
||
310 | ['url' => '//foo:bar@localhost/baz'], |
||
311 | false, |
||
312 | ], |
||
313 | 'URL without scheme but default driver' => [ |
||
314 | [ |
||
315 | 'url' => '//foo:bar@localhost/baz', |
||
316 | 'driver' => 'pdo_mysql', |
||
317 | ], |
||
318 | [ |
||
319 | 'user' => 'foo', |
||
320 | 'password' => 'bar', |
||
321 | 'host' => 'localhost', |
||
322 | 'dbname' => 'baz', |
||
323 | 'driver' => PDOMySQLDriver::class, |
||
324 | ], |
||
325 | ], |
||
326 | 'URL without scheme but custom driver' => [ |
||
327 | [ |
||
328 | 'url' => '//foo:bar@localhost/baz', |
||
329 | 'driverClass' => $driverClass, |
||
330 | ], |
||
331 | [ |
||
332 | 'user' => 'foo', |
||
333 | 'password' => 'bar', |
||
334 | 'host' => 'localhost', |
||
335 | 'dbname' => 'baz', |
||
336 | 'driverClass' => $driverClass, |
||
337 | ], |
||
338 | ], |
||
339 | 'URL without scheme but driver and custom driver' => [ |
||
340 | [ |
||
341 | 'url' => '//foo:bar@localhost/baz', |
||
342 | 'driver' => 'pdo_mysql', |
||
343 | 'driverClass' => $driverClass, |
||
344 | ], |
||
345 | [ |
||
346 | 'user' => 'foo', |
||
347 | 'password' => 'bar', |
||
348 | 'host' => 'localhost', |
||
349 | 'dbname' => 'baz', |
||
350 | 'driverClass' => $driverClass, |
||
351 | ], |
||
352 | ], |
||
353 | 'URL with default driver' => [ |
||
354 | [ |
||
355 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
356 | 'driver' => 'sqlite', |
||
357 | ], |
||
358 | [ |
||
359 | 'user' => 'foo', |
||
360 | 'password' => 'bar', |
||
361 | 'host' => 'localhost', |
||
362 | 'dbname' => 'baz', |
||
363 | 'driver' => PDOMySQLDriver::class, |
||
364 | ], |
||
365 | ], |
||
366 | 'URL with default custom driver' => [ |
||
367 | [ |
||
368 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
369 | 'driverClass' => $driverClass, |
||
370 | ], |
||
371 | [ |
||
372 | 'user' => 'foo', |
||
373 | 'password' => 'bar', |
||
374 | 'host' => 'localhost', |
||
375 | 'dbname' => 'baz', |
||
376 | 'driver' => PDOMySQLDriver::class, |
||
377 | ], |
||
378 | ], |
||
379 | 'URL with default driver and default custom driver' => [ |
||
380 | [ |
||
381 | 'url' => 'mysql://foo:bar@localhost/baz', |
||
382 | 'driver' => 'sqlite', |
||
383 | 'driverClass' => $driverClass, |
||
384 | ], |
||
385 | [ |
||
386 | 'user' => 'foo', |
||
387 | 'password' => 'bar', |
||
388 | 'host' => 'localhost', |
||
389 | 'dbname' => 'baz', |
||
390 | 'driver' => PDOMySQLDriver::class, |
||
391 | ], |
||
396 |