Code Duplication    Length = 20-20 lines in 2 locations

src/Assert.php 2 locations

@@ 1241-1260 (lines=20) @@
1238
     * @return Assert
1239
     * @throws AssertionFailedException
1240
     */
1241
    public function startsWith($needle, $message = null, $fieldName = null, $encoding = 'utf8')
1242
    {
1243
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1244
        {
1245
            return $this;
1246
        }
1247
        $this->string($message, $fieldName);
1248
        if ( mb_strpos($this->value, $needle, null, $encoding) !== 0 )
1249
        {
1250
            $message = $message ?: $this->overrideError;
1251
            $message     = sprintf(
1252
                $message ?: 'Value "%s" does not start with "%s".',
1253
                $this->stringify($this->value),
1254
                $this->stringify($needle)
1255
            );
1256
            $constraints = ['needle' => $needle, 'encoding' => $encoding];
1257
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_START, $fieldName, $constraints);
1258
        }
1259
        return $this;
1260
    }
1261
1262
    /**
1263
     * Assert that value ends with a sequence of chars.
@@ 1304-1323 (lines=20) @@
1301
     * @return Assert
1302
     * @throws AssertionFailedException
1303
     */
1304
    public function contains($needle, $message = null, $fieldName = null, $encoding = 'utf8')
1305
    {
1306
        if ( $this->doAllOrNullOr(__FUNCTION__, func_get_args()) )
1307
        {
1308
            return $this;
1309
        }
1310
        $this->string($message, $fieldName);
1311
        if ( mb_strpos($this->value, $needle, null, $encoding) === false )
1312
        {
1313
            $message = $message ?: $this->overrideError;
1314
            $message     = sprintf(
1315
                $message ?: 'Value "%s" does not contain "%s".',
1316
                $this->stringify($this->value),
1317
                $this->stringify($needle)
1318
            );
1319
            $constraints = ['needle' => $needle, 'encoding' => $encoding];
1320
            throw $this->createException($message, $this->overrideCode ?: self::INVALID_STRING_CONTAINS, $fieldName, $constraints);
1321
        }
1322
        return $this;
1323
    }
1324
1325
    /**
1326
     * Assert that value is in an array of choices.