Conditions | 1 |
Paths | 1 |
Total Lines | 332 |
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 |
||
243 | protected function regularExpressionsProvider() |
||
244 | { |
||
245 | $testData = [ |
||
246 | [ |
||
247 | 'correct' => [ |
||
248 | 'asd fgh ąśćź', |
||
249 | ], |
||
250 | 'incorrect' => [ |
||
251 | 'asd fgh ąśćź 23', |
||
252 | ] |
||
253 | ], |
||
254 | [ |
||
255 | 'correct' => [ |
||
256 | 'asd fgh ąśćź _,.-', |
||
257 | ], |
||
258 | 'incorrect' => [ |
||
259 | 'asd fgh ąśćź 23_,.', |
||
260 | ] |
||
261 | ], |
||
262 | [ |
||
263 | 'correct' => [ |
||
264 | 'asd fghfg ążć._,;:-', |
||
265 | ], |
||
266 | 'incorrect' => [ |
||
267 | 'asd fghfg ążć 23 ._,;:-', |
||
268 | ] |
||
269 | ], |
||
270 | [ |
||
271 | 'correct' => [ |
||
272 | 'sdg sar ąśćź 3242 _ ,\\.;:/!@#$%^&*()+=|{}][<>?`~\'"-', |
||
273 | ], |
||
274 | 'incorrect' => [ |
||
275 | 'sdg sar ąśćź 3242 _ ,\\.;:/!@#$%^&*()+=|{}][<>?`~\'"-' . "\n\t", |
||
276 | ] |
||
277 | ], |
||
278 | [ |
||
279 | 'correct' => [ |
||
280 | 23525 |
||
281 | ], |
||
282 | 'incorrect' => [ |
||
283 | '3234a', |
||
284 | ] |
||
285 | ], |
||
286 | [ |
||
287 | 'correct' => [ |
||
288 | '234-2423/94', |
||
289 | ], |
||
290 | 'incorrect' => [ |
||
291 | '4-3234a', |
||
292 | ] |
||
293 | ], |
||
294 | [ |
||
295 | 'correct' => [ |
||
296 | 'asdas .,_- 23423', |
||
297 | ], |
||
298 | 'incorrect' => [ |
||
299 | '4-asdas .,_- 23423 @', |
||
300 | ] |
||
301 | ], |
||
302 | [ |
||
303 | 'correct' => [ |
||
304 | 'asdas .,_- 23423:;', |
||
305 | ], |
||
306 | 'incorrect' => [ |
||
307 | '4-asdas .,_- 234:;23 @', |
||
308 | ] |
||
309 | ], |
||
310 | [ |
||
311 | 'correct' => [ |
||
312 | -234234, |
||
313 | 234234, |
||
314 | ], |
||
315 | 'incorrect' => [ |
||
316 | '4-3234a', |
||
317 | ] |
||
318 | ], |
||
319 | [ |
||
320 | 'correct' => [ |
||
321 | -2342.2342, |
||
322 | 2342.2342, |
||
323 | '2342,2342', |
||
324 | '-2342,2342', |
||
325 | ], |
||
326 | 'incorrect' => [ |
||
327 | 234324, |
||
328 | '2343.24adsf', |
||
329 | -234324, |
||
330 | ] |
||
331 | ], |
||
332 | [ |
||
333 | 'correct' => [ |
||
334 | -2342.2342, |
||
335 | 2342.2342, |
||
336 | '2342,2342', |
||
337 | '-2342,2342', |
||
338 | 234324, |
||
339 | -234324, |
||
340 | ], |
||
341 | 'incorrect' => [ |
||
342 | '2343.24adsf', |
||
343 | ] |
||
344 | ], |
||
345 | [ |
||
346 | 'correct' => [ |
||
347 | '[email protected]', |
||
348 | '12te-st@ma_il.com', |
||
349 | ], |
||
350 | 'incorrect' => [ |
||
351 | 'testmail.com', |
||
352 | 'test@mail', |
||
353 | '[email protected]', |
||
354 | ] |
||
355 | ], |
||
356 | [ |
||
357 | 'correct' => [ |
||
358 | 'http://someweb.com', |
||
359 | 'http://someweb.com/', |
||
360 | 'http://some-web_.com', |
||
361 | 'someweb.com', |
||
362 | ], |
||
363 | 'incorrect' => [ |
||
364 | 'http://someweb.com/subpage', |
||
365 | 'gesfgsdfg', |
||
366 | 'https://someweb.com', |
||
367 | 'http://someweb.com/some-subpage?param1=asdas%d¶m2=asdas+-', |
||
368 | ] |
||
369 | ], |
||
370 | [ |
||
371 | 'correct' => [ |
||
372 | 'http://someweb.com', |
||
373 | 'https://someweb.com', |
||
374 | 'ftp://someweb.com', |
||
375 | 'ftps://someweb.com', |
||
376 | 'http://someweb.com/', |
||
377 | 'http://some-web_.com', |
||
378 | 'someweb.com', |
||
379 | ], |
||
380 | 'incorrect' => [ |
||
381 | 'http://someweb.com/subpage', |
||
382 | 'gesfgsdfg', |
||
383 | 'http://someweb.com/some-subpage?param1=asdas%d¶m2=asdas+-', |
||
384 | ] |
||
385 | ], |
||
386 | [ |
||
387 | 'correct' => [ |
||
388 | 'http://someweb.com', |
||
389 | 'http://someweb.com/some-subpage', |
||
390 | 'http://someweb.com/some-subpage?param1=asdas%d¶m2=asdas+-', |
||
391 | 'https://someweb.com', |
||
392 | 'ftp://someweb.com', |
||
393 | 'ftps://someweb.com', |
||
394 | 'http://someweb.com/', |
||
395 | 'http://some-web_.com', |
||
396 | 'someweb.com', |
||
397 | ], |
||
398 | 'incorrect' => [ |
||
399 | 'gesfgsdfg', |
||
400 | 'http://someweb.com/some-subpage?param1=\asda*', |
||
401 | ] |
||
402 | ], |
||
403 | [ |
||
404 | 'correct' => [ |
||
405 | 123123, |
||
406 | 1231.23, |
||
407 | '234234,23', |
||
408 | ], |
||
409 | 'incorrect' => [ |
||
410 | '2342f', |
||
411 | 1231.2334, |
||
412 | '234234,23324', |
||
413 | ] |
||
414 | ], |
||
415 | [ |
||
416 | 'correct' => [ |
||
417 | '42-400', |
||
418 | ], |
||
419 | 'incorrect' => [ |
||
420 | '42400', |
||
421 | '42-00', |
||
422 | '422-00', |
||
423 | ] |
||
424 | ], |
||
425 | [ |
||
426 | 'correct' => [ |
||
427 | '+48 600 700 800', |
||
428 | '600-700-000', |
||
429 | '+48600700800', |
||
430 | '+48 ( 052 ) 131 231-2312', |
||
431 | ], |
||
432 | 'incorrect' => [ |
||
433 | '34234234d', |
||
434 | '23423/234234/234234', |
||
435 | ] |
||
436 | ], |
||
437 | [ |
||
438 | 'correct' => [ |
||
439 | '12-12-1983', |
||
440 | ], |
||
441 | 'incorrect' => [ |
||
442 | '12/12/1983', |
||
443 | '2-12-1983', |
||
444 | '12-2-1983', |
||
445 | '12-12-83', |
||
446 | '1983-12-12', |
||
447 | ] |
||
448 | ], |
||
449 | [ |
||
450 | 'correct' => [ |
||
451 | '1983-12-12', |
||
452 | ], |
||
453 | 'incorrect' => [ |
||
454 | '1983/12/12', |
||
455 | '1983-2-12', |
||
456 | '1983-12-2', |
||
457 | '12-12-83', |
||
458 | '12-12-1983', |
||
459 | ] |
||
460 | ], |
||
461 | [ |
||
462 | 'correct' => [ |
||
463 | '1983-12', |
||
464 | ], |
||
465 | 'incorrect' => [ |
||
466 | '1983-1', |
||
467 | '83-12', |
||
468 | ] |
||
469 | ], |
||
470 | [ |
||
471 | 'correct' => [ |
||
472 | '2017-06-27 16:42', |
||
473 | ], |
||
474 | 'incorrect' => [ |
||
475 | '17-06-27 16:42', |
||
476 | '2017-6-27 16:42', |
||
477 | '2017-06-27', |
||
478 | '2017-06-27 16:2', |
||
479 | '2017-06-27 16:42:34', |
||
480 | ] |
||
481 | ], |
||
482 | [ |
||
483 | 'correct' => [ |
||
484 | '12/12/1983', |
||
485 | ], |
||
486 | 'incorrect' => [ |
||
487 | '12-12-1983', |
||
488 | '1983-12-12', |
||
489 | '12/1/1983', |
||
490 | '1/12/1983', |
||
491 | '12/12/83', |
||
492 | ] |
||
493 | ], |
||
494 | [ |
||
495 | 'correct' => [ |
||
496 | '12/12/1983 07:23', |
||
497 | ], |
||
498 | 'incorrect' => [ |
||
499 | '12/12/1983 7:23', |
||
500 | '12/12/1983', |
||
501 | '12-12-1983', |
||
502 | '1983-12-12', |
||
503 | '12/1/1983', |
||
504 | '1/12/1983', |
||
505 | '12/12/83', |
||
506 | ] |
||
507 | ], |
||
508 | [ |
||
509 | 'correct' => [ |
||
510 | '16:45', |
||
511 | '16:45:48', |
||
512 | ], |
||
513 | 'incorrect' => [ |
||
514 | '6:45', |
||
515 | '6:45:48', |
||
516 | '16:45:8', |
||
517 | ] |
||
518 | ], |
||
519 | [ |
||
520 | 'correct' => [ |
||
521 | '#ff0000', |
||
522 | ], |
||
523 | 'incorrect' => [ |
||
524 | 'ff0000', |
||
525 | '#fff0000', |
||
526 | '#hf0000', |
||
527 | ] |
||
528 | ], |
||
529 | [ |
||
530 | 'correct' => [ |
||
531 | '#fff0000235', |
||
532 | '#0000', |
||
533 | ], |
||
534 | 'incorrect' => [ |
||
535 | '#fffz0000', |
||
536 | ] |
||
537 | ], |
||
538 | [ |
||
539 | 'correct' => [ |
||
540 | '0x235ad', |
||
541 | ], |
||
542 | 'incorrect' => [ |
||
543 | 0x235ad, |
||
544 | 32345, |
||
545 | '0235ad', |
||
546 | '0x235adz', |
||
547 | 'x235ad', |
||
548 | ] |
||
549 | ], |
||
550 | [ |
||
551 | 'correct' => [ |
||
552 | '0755', |
||
553 | '075512431254213', |
||
554 | ], |
||
555 | 'incorrect' => [ |
||
556 | 755, |
||
557 | 0755, |
||
558 | '0755a', |
||
559 | ] |
||
560 | ], |
||
561 | [ |
||
562 | 'correct' => [ |
||
563 | 'b01010101110110', |
||
564 | ], |
||
565 | 'incorrect' => [ |
||
566 | '010101011101102', |
||
567 | 01010101110110, |
||
568 | ] |
||
569 | ], |
||
570 | ]; |
||
571 | |||
572 | return array_combine( |
||
573 | array_keys(Validator::$regularExpressions), |
||
574 | $testData |
||
575 | ); |
||
578 |