Code Duplication    Length = 9-10 lines in 19 locations

src/Assert.php 19 locations

@@ 249-257 (lines=9) @@
246
        }
247
    }
248
249
    public static function natural($value, $message = '')
250
    {
251
        if (!is_int($value) || $value < 0) {
252
            static::reportInvalidArgument(sprintf(
253
                $message ?: 'Expected a non-negative integer. Got %s',
254
                static::valueToString($value)
255
            ));
256
        }
257
    }
258
259
    public static function boolean($value, $message = '')
260
    {
@@ 435-443 (lines=9) @@
432
        }
433
    }
434
435
    public static function null($value, $message = '')
436
    {
437
        if (null !== $value) {
438
            static::reportInvalidArgument(sprintf(
439
                $message ?: 'Expected null. Got: %s',
440
                static::valueToString($value)
441
            ));
442
        }
443
    }
444
445
    public static function notNull($value, $message = '')
446
    {
@@ 454-462 (lines=9) @@
451
        }
452
    }
453
454
    public static function true($value, $message = '')
455
    {
456
        if (true !== $value) {
457
            static::reportInvalidArgument(sprintf(
458
                $message ?: 'Expected a value to be true. Got: %s',
459
                static::valueToString($value)
460
            ));
461
        }
462
    }
463
464
    public static function false($value, $message = '')
465
    {
@@ 464-472 (lines=9) @@
461
        }
462
    }
463
464
    public static function false($value, $message = '')
465
    {
466
        if (false !== $value) {
467
            static::reportInvalidArgument(sprintf(
468
                $message ?: 'Expected a value to be false. Got: %s',
469
                static::valueToString($value)
470
            ));
471
        }
472
    }
473
474
    public static function ip($value, $message = '')
475
    {
@@ 520-529 (lines=10) @@
517
        }
518
    }
519
520
    public static function eq($value, $expect, $message = '')
521
    {
522
        if ($expect != $value) {
523
            static::reportInvalidArgument(sprintf(
524
                $message ?: 'Expected a value equal to %2$s. Got: %s',
525
                static::valueToString($value),
526
                static::valueToString($expect)
527
            ));
528
        }
529
    }
530
531
    public static function notEq($value, $expect, $message = '')
532
    {
@@ 541-550 (lines=10) @@
538
        }
539
    }
540
541
    public static function same($value, $expect, $message = '')
542
    {
543
        if ($expect !== $value) {
544
            static::reportInvalidArgument(sprintf(
545
                $message ?: 'Expected a value identical to %2$s. Got: %s',
546
                static::valueToString($value),
547
                static::valueToString($expect)
548
            ));
549
        }
550
    }
551
552
    public static function notSame($value, $expect, $message = '')
553
    {
@@ 562-571 (lines=10) @@
559
        }
560
    }
561
562
    public static function greaterThan($value, $limit, $message = '')
563
    {
564
        if ($value <= $limit) {
565
            static::reportInvalidArgument(sprintf(
566
                $message ?: 'Expected a value greater than %2$s. Got: %s',
567
                static::valueToString($value),
568
                static::valueToString($limit)
569
            ));
570
        }
571
    }
572
573
    public static function greaterThanEq($value, $limit, $message = '')
574
    {
@@ 573-582 (lines=10) @@
570
        }
571
    }
572
573
    public static function greaterThanEq($value, $limit, $message = '')
574
    {
575
        if ($value < $limit) {
576
            static::reportInvalidArgument(sprintf(
577
                $message ?: 'Expected a value greater than or equal to %2$s. Got: %s',
578
                static::valueToString($value),
579
                static::valueToString($limit)
580
            ));
581
        }
582
    }
583
584
    public static function lessThan($value, $limit, $message = '')
585
    {
@@ 584-593 (lines=10) @@
581
        }
582
    }
583
584
    public static function lessThan($value, $limit, $message = '')
585
    {
586
        if ($value >= $limit) {
587
            static::reportInvalidArgument(sprintf(
588
                $message ?: 'Expected a value less than %2$s. Got: %s',
589
                static::valueToString($value),
590
                static::valueToString($limit)
591
            ));
592
        }
593
    }
594
595
    public static function lessThanEq($value, $limit, $message = '')
596
    {
@@ 595-604 (lines=10) @@
592
        }
593
    }
594
595
    public static function lessThanEq($value, $limit, $message = '')
596
    {
597
        if ($value > $limit) {
598
            static::reportInvalidArgument(sprintf(
599
                $message ?: 'Expected a value less than or equal to %2$s. Got: %s',
600
                static::valueToString($value),
601
                static::valueToString($limit)
602
            ));
603
        }
604
    }
605
606
    public static function range($value, $min, $max, $message = '')
607
    {
@@ 651-659 (lines=9) @@
648
        }
649
    }
650
651
    public static function notWhitespaceOnly($value, $message = '')
652
    {
653
        if (preg_match('/^\s*$/', $value)) {
654
            static::reportInvalidArgument(sprintf(
655
                $message ?: 'Expected a non-whitespace string. Got: %s',
656
                static::valueToString($value)
657
            ));
658
        }
659
    }
660
661
    public static function startsWith($value, $prefix, $message = '')
662
    {
@@ 702-710 (lines=9) @@
699
        }
700
    }
701
702
    public static function regex($value, $pattern, $message = '')
703
    {
704
        if (!preg_match($pattern, $value)) {
705
            static::reportInvalidArgument(sprintf(
706
                $message ?: 'The value %s does not match the expected pattern.',
707
                static::valueToString($value)
708
            ));
709
        }
710
    }
711
712
    public static function notRegex($value, $pattern, $message = '')
713
    {
@@ 724-732 (lines=9) @@
721
        }
722
    }
723
724
    public static function letter($value, $message = '')
725
    {
726
        if (!preg_match('/^\p{L}+$/u', $value)) {
727
            static::reportInvalidArgument(sprintf(
728
                $message ?: 'Expected a value to contain only Unicode letters. Got: %s',
729
                static::valueToString($value)
730
            ));
731
        }
732
    }
733
734
    public static function alpha($value, $message = '')
735
    {
@@ 820-829 (lines=10) @@
817
        }
818
    }
819
820
    public static function minLength($value, $min, $message = '')
821
    {
822
        if (static::strlen($value) < $min) {
823
            static::reportInvalidArgument(sprintf(
824
                $message ?: 'Expected a value to contain at least %2$s characters. Got: %s',
825
                static::valueToString($value),
826
                $min
827
            ));
828
        }
829
    }
830
831
    public static function maxLength($value, $max, $message = '')
832
    {
@@ 831-840 (lines=10) @@
828
        }
829
    }
830
831
    public static function maxLength($value, $max, $message = '')
832
    {
833
        if (static::strlen($value) > $max) {
834
            static::reportInvalidArgument(sprintf(
835
                $message ?: 'Expected a value to contain at most %2$s characters. Got: %s',
836
                static::valueToString($value),
837
                $max
838
            ));
839
        }
840
    }
841
842
    public static function lengthBetween($value, $min, $max, $message = '')
843
    {
@@ 892-900 (lines=9) @@
889
        }
890
    }
891
892
    public static function readable($value, $message = '')
893
    {
894
        if (!is_readable($value)) {
895
            static::reportInvalidArgument(sprintf(
896
                $message ?: 'The path %s is not readable.',
897
                static::valueToString($value)
898
            ));
899
        }
900
    }
901
902
    public static function writable($value, $message = '')
903
    {
@@ 902-910 (lines=9) @@
899
        }
900
    }
901
902
    public static function writable($value, $message = '')
903
    {
904
        if (!is_writable($value)) {
905
            static::reportInvalidArgument(sprintf(
906
                $message ?: 'The path %s is not writable.',
907
                static::valueToString($value)
908
            ));
909
        }
910
    }
911
912
    public static function classExists($value, $message = '')
913
    {
@@ 912-920 (lines=9) @@
909
        }
910
    }
911
912
    public static function classExists($value, $message = '')
913
    {
914
        if (!class_exists($value)) {
915
            static::reportInvalidArgument(sprintf(
916
                $message ?: 'Expected an existing class name. Got: %s',
917
                static::valueToString($value)
918
            ));
919
        }
920
    }
921
922
    public static function subclassOf($value, $class, $message = '')
923
    {
@@ 933-941 (lines=9) @@
930
        }
931
    }
932
933
    public static function interfaceExists($value, $message = '')
934
    {
935
        if (!interface_exists($value)) {
936
            static::reportInvalidArgument(sprintf(
937
                $message ?: 'Expected an existing interface name. got %s',
938
                static::valueToString($value)
939
            ));
940
        }
941
    }
942
943
    public static function implementsInterface($value, $interface, $message = '')
944
    {