Code Duplication    Length = 10-11 lines in 7 locations

src/Assert.php 7 locations

@@ 468-477 (lines=10) @@
465
        }
466
    }
467
468
    public static function contains($value, $subString, $message = '')
469
    {
470
        if (false === strpos($value, $subString)) {
471
            throw new InvalidArgumentException(sprintf(
472
                $message ?: 'Expected a value to contain %2$s. Got: %s',
473
                self::valueToString($value),
474
                self::valueToString($subString)
475
            ));
476
        }
477
    }
478
479
    public static function startsWith($value, $prefix, $message = '')
480
    {
@@ 479-488 (lines=10) @@
476
        }
477
    }
478
479
    public static function startsWith($value, $prefix, $message = '')
480
    {
481
        if (0 !== strpos($value, $prefix)) {
482
            throw new InvalidArgumentException(sprintf(
483
                $message ?: 'Expected a value to start with %2$s. Got: %s',
484
                self::valueToString($value),
485
                self::valueToString($prefix)
486
            ));
487
        }
488
    }
489
490
    public static function startsWithLetter($value, $message = '')
491
    {
@@ 509-518 (lines=10) @@
506
        }
507
    }
508
509
    public static function endsWith($value, $suffix, $message = '')
510
    {
511
        if ($suffix !== substr($value, -self::strlen($suffix))) {
512
            throw new InvalidArgumentException(sprintf(
513
                $message ?: 'Expected a value to end with %2$s. Got: %s',
514
                self::valueToString($value),
515
                self::valueToString($suffix)
516
            ));
517
        }
518
    }
519
520
    public static function regex($value, $pattern, $message = '')
521
    {
@@ 664-674 (lines=11) @@
661
        }
662
    }
663
664
    public static function file($value, $message = '')
665
    {
666
        self::fileExists($value, $message);
667
668
        if (!is_file($value)) {
669
            throw new InvalidArgumentException(sprintf(
670
                $message ?: 'The path %s is not a file.',
671
                self::valueToString($value)
672
            ));
673
        }
674
    }
675
676
    public static function directory($value, $message = '')
677
    {
@@ 676-686 (lines=11) @@
673
        }
674
    }
675
676
    public static function directory($value, $message = '')
677
    {
678
        self::fileExists($value, $message);
679
680
        if (!is_dir($value)) {
681
            throw new InvalidArgumentException(sprintf(
682
                $message ?: 'The path %s is no directory.',
683
                self::valueToString($value)
684
            ));
685
        }
686
    }
687
688
    public static function readable($value, $message = '')
689
    {
@@ 718-727 (lines=10) @@
715
        }
716
    }
717
718
    public static function subclassOf($value, $class, $message = '')
719
    {
720
        if (!is_subclass_of($value, $class)) {
721
            throw new InvalidArgumentException(sprintf(
722
                $message ?: 'Expected a sub-class of %2$s. Got: %s',
723
                self::valueToString($value),
724
                self::valueToString($class)
725
            ));
726
        }
727
    }
728
729
    public static function implementsInterface($value, $interface, $message = '')
730
    {
@@ 729-738 (lines=10) @@
726
        }
727
    }
728
729
    public static function implementsInterface($value, $interface, $message = '')
730
    {
731
        if (!in_array($interface, class_implements($value))) {
732
            throw new InvalidArgumentException(sprintf(
733
                $message ?: 'Expected an implementation of %2$s. Got: %s',
734
                self::valueToString($value),
735
                self::valueToString($interface)
736
            ));
737
        }
738
    }
739
740
    public static function propertyExists($classOrObject, $property, $message = '')
741
    {