Code Duplication    Length = 20-20 lines in 2 locations

src/Assert.php 2 locations

@@ 1081-1100 (lines=20) @@
1078
     * @return Assert
1079
     * @throws AssertionFailedException
1080
     */
1081
    public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8')
1082
    {
1083
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1084
        {
1085
            return $this;
1086
        }
1087
        $this->string($message, $propertyPath);
1088
        if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 )
1089
        {
1090
            $message = $message ?: $this->overrideError;
1091
            $message     = sprintf(
1092
                $message ?: 'Value "%s" does not start with "%s".',
1093
                $this->stringify($this->value),
1094
                $this->stringify($needle)
1095
            );
1096
            $constraints = ['needle' => $needle, 'encoding' => $encoding];
1097
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints);
1098
        }
1099
        return $this;
1100
    }
1101
1102
    /**
1103
     * Assert that string ends with a sequence of chars.
@@ 1144-1163 (lines=20) @@
1141
     * @return Assert
1142
     * @throws AssertionFailedException
1143
     */
1144
    public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8')
1145
    {
1146
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1147
        {
1148
            return $this;
1149
        }
1150
        $this->string($message, $propertyPath);
1151
        if ( mb_strpos($this->value, $needle, null, $encoding) === false )
1152
        {
1153
            $message = $message ?: $this->overrideError;
1154
            $message     = sprintf(
1155
                $message ?: 'Value "%s" does not contain "%s".',
1156
                $this->stringify($this->value),
1157
                $this->stringify($needle)
1158
            );
1159
            $constraints = ['needle' => $needle, 'encoding' => $encoding];
1160
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints);
1161
        }
1162
        return $this;
1163
    }
1164
1165
    /**
1166
     * Assert that value is in array of choices.