Code Duplication    Length = 9-10 lines in 17 locations

src/Assert.php 17 locations

@@ 245-253 (lines=9) @@
242
        }
243
    }
244
245
    public static function natural($value, $message = '')
246
    {
247
        if (!is_int($value) || $value < 0) {
248
            static::reportInvalidArgument(sprintf(
249
                $message ?: 'Expected a non-negative integer. Got %s',
250
                static::valueToString($value)
251
            ));
252
        }
253
    }
254
255
    public static function boolean($value, $message = '')
256
    {
@@ 428-436 (lines=9) @@
425
        }
426
    }
427
428
    public static function null($value, $message = '')
429
    {
430
        if (null !== $value) {
431
            static::reportInvalidArgument(sprintf(
432
                $message ?: 'Expected null. Got: %s',
433
                static::valueToString($value)
434
            ));
435
        }
436
    }
437
438
    public static function notNull($value, $message = '')
439
    {
@@ 447-455 (lines=9) @@
444
        }
445
    }
446
447
    public static function true($value, $message = '')
448
    {
449
        if (true !== $value) {
450
            static::reportInvalidArgument(sprintf(
451
                $message ?: 'Expected a value to be true. Got: %s',
452
                static::valueToString($value)
453
            ));
454
        }
455
    }
456
457
    public static function false($value, $message = '')
458
    {
@@ 457-465 (lines=9) @@
454
        }
455
    }
456
457
    public static function false($value, $message = '')
458
    {
459
        if (false !== $value) {
460
            static::reportInvalidArgument(sprintf(
461
                $message ?: 'Expected a value to be false. Got: %s',
462
                static::valueToString($value)
463
            ));
464
        }
465
    }
466
467
    public static function ip($value, $message = '')
468
    {
@@ 497-506 (lines=10) @@
494
        }
495
    }
496
497
    public static function eq($value, $value2, $message = '')
498
    {
499
        if ($value2 != $value) {
500
            static::reportInvalidArgument(sprintf(
501
                $message ?: 'Expected a value equal to %2$s. Got: %s',
502
                static::valueToString($value),
503
                static::valueToString($value2)
504
            ));
505
        }
506
    }
507
508
    public static function notEq($value, $value2, $message = '')
509
    {
@@ 518-527 (lines=10) @@
515
        }
516
    }
517
518
    public static function same($value, $value2, $message = '')
519
    {
520
        if ($value2 !== $value) {
521
            static::reportInvalidArgument(sprintf(
522
                $message ?: 'Expected a value identical to %2$s. Got: %s',
523
                static::valueToString($value),
524
                static::valueToString($value2)
525
            ));
526
        }
527
    }
528
529
    public static function notSame($value, $value2, $message = '')
530
    {
@@ 539-548 (lines=10) @@
536
        }
537
    }
538
539
    public static function greaterThan($value, $limit, $message = '')
540
    {
541
        if ($value <= $limit) {
542
            static::reportInvalidArgument(sprintf(
543
                $message ?: 'Expected a value greater than %2$s. Got: %s',
544
                static::valueToString($value),
545
                static::valueToString($limit)
546
            ));
547
        }
548
    }
549
550
    public static function greaterThanEq($value, $limit, $message = '')
551
    {
@@ 550-559 (lines=10) @@
547
        }
548
    }
549
550
    public static function greaterThanEq($value, $limit, $message = '')
551
    {
552
        if ($value < $limit) {
553
            static::reportInvalidArgument(sprintf(
554
                $message ?: 'Expected a value greater than or equal to %2$s. Got: %s',
555
                static::valueToString($value),
556
                static::valueToString($limit)
557
            ));
558
        }
559
    }
560
561
    public static function lessThan($value, $limit, $message = '')
562
    {
@@ 561-570 (lines=10) @@
558
        }
559
    }
560
561
    public static function lessThan($value, $limit, $message = '')
562
    {
563
        if ($value >= $limit) {
564
            static::reportInvalidArgument(sprintf(
565
                $message ?: 'Expected a value less than %2$s. Got: %s',
566
                static::valueToString($value),
567
                static::valueToString($limit)
568
            ));
569
        }
570
    }
571
572
    public static function lessThanEq($value, $limit, $message = '')
573
    {
@@ 572-581 (lines=10) @@
569
        }
570
    }
571
572
    public static function lessThanEq($value, $limit, $message = '')
573
    {
574
        if ($value > $limit) {
575
            static::reportInvalidArgument(sprintf(
576
                $message ?: 'Expected a value less than or equal to %2$s. Got: %s',
577
                static::valueToString($value),
578
                static::valueToString($limit)
579
            ));
580
        }
581
    }
582
583
    public static function range($value, $min, $max, $message = '')
584
    {
@@ 628-636 (lines=9) @@
625
        }
626
    }
627
628
    public static function notWhitespaceOnly($value, $message = '')
629
    {
630
        if (preg_match('/^\s*$/', $value)) {
631
            static::reportInvalidArgument(sprintf(
632
                $message ?: 'Expected a non-whitespace string. Got: %s',
633
                static::valueToString($value)
634
            ));
635
        }
636
    }
637
638
    public static function startsWith($value, $prefix, $message = '')
639
    {
@@ 787-796 (lines=10) @@
784
        }
785
    }
786
787
    public static function minLength($value, $min, $message = '')
788
    {
789
        if (static::strlen($value) < $min) {
790
            static::reportInvalidArgument(sprintf(
791
                $message ?: 'Expected a value to contain at least %2$s characters. Got: %s',
792
                static::valueToString($value),
793
                $min
794
            ));
795
        }
796
    }
797
798
    public static function maxLength($value, $max, $message = '')
799
    {
@@ 798-807 (lines=10) @@
795
        }
796
    }
797
798
    public static function maxLength($value, $max, $message = '')
799
    {
800
        if (static::strlen($value) > $max) {
801
            static::reportInvalidArgument(sprintf(
802
                $message ?: 'Expected a value to contain at most %2$s characters. Got: %s',
803
                static::valueToString($value),
804
                $max
805
            ));
806
        }
807
    }
808
809
    public static function lengthBetween($value, $min, $max, $message = '')
810
    {
@@ 859-867 (lines=9) @@
856
        }
857
    }
858
859
    public static function readable($value, $message = '')
860
    {
861
        if (!is_readable($value)) {
862
            static::reportInvalidArgument(sprintf(
863
                $message ?: 'The path %s is not readable.',
864
                static::valueToString($value)
865
            ));
866
        }
867
    }
868
869
    public static function writable($value, $message = '')
870
    {
@@ 869-877 (lines=9) @@
866
        }
867
    }
868
869
    public static function writable($value, $message = '')
870
    {
871
        if (!is_writable($value)) {
872
            static::reportInvalidArgument(sprintf(
873
                $message ?: 'The path %s is not writable.',
874
                static::valueToString($value)
875
            ));
876
        }
877
    }
878
879
    public static function classExists($value, $message = '')
880
    {
@@ 879-887 (lines=9) @@
876
        }
877
    }
878
879
    public static function classExists($value, $message = '')
880
    {
881
        if (!class_exists($value)) {
882
            static::reportInvalidArgument(sprintf(
883
                $message ?: 'Expected an existing class name. Got: %s',
884
                static::valueToString($value)
885
            ));
886
        }
887
    }
888
889
    public static function subclassOf($value, $class, $message = '')
890
    {
@@ 900-908 (lines=9) @@
897
        }
898
    }
899
900
    public static function interfaceExists($value, $message = '')
901
    {
902
        if (!interface_exists($value)) {
903
            static::reportInvalidArgument(sprintf(
904
                $message ?: 'Expected an existing interface name. got %s',
905
                static::valueToString($value)
906
            ));
907
        }
908
    }
909
910
    public static function implementsInterface($value, $interface, $message = '')
911
    {