Code Duplication    Length = 9-10 lines in 17 locations

src/Assert.php 17 locations

@@ 235-243 (lines=9) @@
232
        }
233
    }
234
235
    public static function natural($value, $message = '')
236
    {
237
        if (!is_int($value) || $value < 0) {
238
            static::reportInvalidArgument(sprintf(
239
                $message ?: 'Expected a non-negative integer. Got %s',
240
                static::valueToString($value)
241
            ));
242
        }
243
    }
244
245
    public static function boolean($value, $message = '')
246
    {
@@ 418-426 (lines=9) @@
415
        }
416
    }
417
418
    public static function null($value, $message = '')
419
    {
420
        if (null !== $value) {
421
            static::reportInvalidArgument(sprintf(
422
                $message ?: 'Expected null. Got: %s',
423
                static::valueToString($value)
424
            ));
425
        }
426
    }
427
428
    public static function notNull($value, $message = '')
429
    {
@@ 437-445 (lines=9) @@
434
        }
435
    }
436
437
    public static function true($value, $message = '')
438
    {
439
        if (true !== $value) {
440
            static::reportInvalidArgument(sprintf(
441
                $message ?: 'Expected a value to be true. Got: %s',
442
                static::valueToString($value)
443
            ));
444
        }
445
    }
446
447
    public static function false($value, $message = '')
448
    {
@@ 447-455 (lines=9) @@
444
        }
445
    }
446
447
    public static function false($value, $message = '')
448
    {
449
        if (false !== $value) {
450
            static::reportInvalidArgument(sprintf(
451
                $message ?: 'Expected a value to be false. Got: %s',
452
                static::valueToString($value)
453
            ));
454
        }
455
    }
456
457
    public static function ip($value, $message = '')
458
    {
@@ 487-496 (lines=10) @@
484
        }
485
    }
486
487
    public static function eq($value, $value2, $message = '')
488
    {
489
        if ($value2 != $value) {
490
            static::reportInvalidArgument(sprintf(
491
                $message ?: 'Expected a value equal to %2$s. Got: %s',
492
                static::valueToString($value),
493
                static::valueToString($value2)
494
            ));
495
        }
496
    }
497
498
    public static function notEq($value, $value2, $message = '')
499
    {
@@ 508-517 (lines=10) @@
505
        }
506
    }
507
508
    public static function same($value, $value2, $message = '')
509
    {
510
        if ($value2 !== $value) {
511
            static::reportInvalidArgument(sprintf(
512
                $message ?: 'Expected a value identical to %2$s. Got: %s',
513
                static::valueToString($value),
514
                static::valueToString($value2)
515
            ));
516
        }
517
    }
518
519
    public static function notSame($value, $value2, $message = '')
520
    {
@@ 529-538 (lines=10) @@
526
        }
527
    }
528
529
    public static function greaterThan($value, $limit, $message = '')
530
    {
531
        if ($value <= $limit) {
532
            static::reportInvalidArgument(sprintf(
533
                $message ?: 'Expected a value greater than %2$s. Got: %s',
534
                static::valueToString($value),
535
                static::valueToString($limit)
536
            ));
537
        }
538
    }
539
540
    public static function greaterThanEq($value, $limit, $message = '')
541
    {
@@ 540-549 (lines=10) @@
537
        }
538
    }
539
540
    public static function greaterThanEq($value, $limit, $message = '')
541
    {
542
        if ($value < $limit) {
543
            static::reportInvalidArgument(sprintf(
544
                $message ?: 'Expected a value greater than or equal to %2$s. Got: %s',
545
                static::valueToString($value),
546
                static::valueToString($limit)
547
            ));
548
        }
549
    }
550
551
    public static function lessThan($value, $limit, $message = '')
552
    {
@@ 551-560 (lines=10) @@
548
        }
549
    }
550
551
    public static function lessThan($value, $limit, $message = '')
552
    {
553
        if ($value >= $limit) {
554
            static::reportInvalidArgument(sprintf(
555
                $message ?: 'Expected a value less than %2$s. Got: %s',
556
                static::valueToString($value),
557
                static::valueToString($limit)
558
            ));
559
        }
560
    }
561
562
    public static function lessThanEq($value, $limit, $message = '')
563
    {
@@ 562-571 (lines=10) @@
559
        }
560
    }
561
562
    public static function lessThanEq($value, $limit, $message = '')
563
    {
564
        if ($value > $limit) {
565
            static::reportInvalidArgument(sprintf(
566
                $message ?: 'Expected a value less than or equal to %2$s. Got: %s',
567
                static::valueToString($value),
568
                static::valueToString($limit)
569
            ));
570
        }
571
    }
572
573
    public static function range($value, $min, $max, $message = '')
574
    {
@@ 618-626 (lines=9) @@
615
        }
616
    }
617
618
    public static function notWhitespaceOnly($value, $message = '')
619
    {
620
        if (preg_match('/^\s*$/', $value)) {
621
            static::reportInvalidArgument(sprintf(
622
                $message ?: 'Expected a non-whitespace string. Got: %s',
623
                static::valueToString($value)
624
            ));
625
        }
626
    }
627
628
    public static function startsWith($value, $prefix, $message = '')
629
    {
@@ 777-786 (lines=10) @@
774
        }
775
    }
776
777
    public static function minLength($value, $min, $message = '')
778
    {
779
        if (static::strlen($value) < $min) {
780
            static::reportInvalidArgument(sprintf(
781
                $message ?: 'Expected a value to contain at least %2$s characters. Got: %s',
782
                static::valueToString($value),
783
                $min
784
            ));
785
        }
786
    }
787
788
    public static function maxLength($value, $max, $message = '')
789
    {
@@ 788-797 (lines=10) @@
785
        }
786
    }
787
788
    public static function maxLength($value, $max, $message = '')
789
    {
790
        if (static::strlen($value) > $max) {
791
            static::reportInvalidArgument(sprintf(
792
                $message ?: 'Expected a value to contain at most %2$s characters. Got: %s',
793
                static::valueToString($value),
794
                $max
795
            ));
796
        }
797
    }
798
799
    public static function lengthBetween($value, $min, $max, $message = '')
800
    {
@@ 849-857 (lines=9) @@
846
        }
847
    }
848
849
    public static function readable($value, $message = '')
850
    {
851
        if (!is_readable($value)) {
852
            static::reportInvalidArgument(sprintf(
853
                $message ?: 'The path %s is not readable.',
854
                static::valueToString($value)
855
            ));
856
        }
857
    }
858
859
    public static function writable($value, $message = '')
860
    {
@@ 859-867 (lines=9) @@
856
        }
857
    }
858
859
    public static function writable($value, $message = '')
860
    {
861
        if (!is_writable($value)) {
862
            static::reportInvalidArgument(sprintf(
863
                $message ?: 'The path %s is not writable.',
864
                static::valueToString($value)
865
            ));
866
        }
867
    }
868
869
    public static function classExists($value, $message = '')
870
    {
@@ 869-877 (lines=9) @@
866
        }
867
    }
868
869
    public static function classExists($value, $message = '')
870
    {
871
        if (!class_exists($value)) {
872
            static::reportInvalidArgument(sprintf(
873
                $message ?: 'Expected an existing class name. Got: %s',
874
                static::valueToString($value)
875
            ));
876
        }
877
    }
878
879
    public static function subclassOf($value, $class, $message = '')
880
    {
@@ 890-898 (lines=9) @@
887
        }
888
    }
889
890
    public static function interfaceExists($value, $message = '')
891
    {
892
        if (!interface_exists($value)) {
893
            static::reportInvalidArgument(sprintf(
894
                $message ?: 'Expected an existing interface name. got %s',
895
                static::valueToString($value)
896
            ));
897
        }
898
    }
899
900
    public static function implementsInterface($value, $interface, $message = '')
901
    {