Code Duplication    Length = 20-20 lines in 2 locations

src/Assert.php 2 locations

@@ 1145-1164 (lines=20) @@
1142
     * @return Assert
1143
     * @throws AssertionFailedException
1144
     */
1145
    public function startsWith($needle, $message = null, $propertyPath = null, $encoding = 'utf8')
1146
    {
1147
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1148
        {
1149
            return $this;
1150
        }
1151
        $this->string($message, $propertyPath);
1152
        if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 )
1153
        {
1154
            $message = $message ?: $this->overrideError;
1155
            $message     = sprintf(
1156
                $message ?: 'Value "%s" does not start with "%s".',
1157
                $this->stringify($this->value),
1158
                $this->stringify($needle)
1159
            );
1160
            $constraints = ['needle' => $needle, 'encoding' => $encoding];
1161
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $propertyPath, $constraints);
1162
        }
1163
        return $this;
1164
    }
1165
1166
    /**
1167
     * Assert that string ends with a sequence of chars.
@@ 1208-1227 (lines=20) @@
1205
     * @return Assert
1206
     * @throws AssertionFailedException
1207
     */
1208
    public function contains($needle, $message = null, $propertyPath = null, $encoding = 'utf8')
1209
    {
1210
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1211
        {
1212
            return $this;
1213
        }
1214
        $this->string($message, $propertyPath);
1215
        if ( mb_strpos($this->value, $needle, null, $encoding) === false )
1216
        {
1217
            $message = $message ?: $this->overrideError;
1218
            $message     = sprintf(
1219
                $message ?: 'Value "%s" does not contain "%s".',
1220
                $this->stringify($this->value),
1221
                $this->stringify($needle)
1222
            );
1223
            $constraints = ['needle' => $needle, 'encoding' => $encoding];
1224
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $propertyPath, $constraints);
1225
        }
1226
        return $this;
1227
    }
1228
1229
    /**
1230
     * Assert that value is in array of choices.