Code Duplication    Length = 9-11 lines in 5 locations

src/Assert.php 5 locations

@@ 1331-1341 (lines=11) @@
1328
     * @param null $exception
1329
     * @throws Exception
1330
     */
1331
    public static function fileExists($value, $message = '', $exception = null)
1332
    {
1333
        static::string($value);
1334
1335
        if (!\file_exists($value)) {
1336
            static::throwException(\sprintf(
1337
                $message ?: 'The file %s does not exist.',
1338
                static::valueToString($value)
1339
            ), $exception);
1340
        }
1341
    }
1342
1343
    /**
1344
     * @param mixed $value
@@ 1349-1359 (lines=11) @@
1346
     * @param null $exception
1347
     * @throws Exception
1348
     */
1349
    public static function file($value, $message = '', $exception = null)
1350
    {
1351
        static::fileExists($value, $message, $exception);
1352
1353
        if (!\is_file($value)) {
1354
            static::throwException(\sprintf(
1355
                $message ?: 'The path %s is not a file.',
1356
                static::valueToString($value)
1357
            ), $exception);
1358
        }
1359
    }
1360
1361
    /**
1362
     * @param mixed $value
@@ 1367-1377 (lines=11) @@
1364
     * @param null $exception
1365
     * @throws Exception
1366
     */
1367
    public static function directory($value, $message = '', $exception = null)
1368
    {
1369
        static::fileExists($value, $message, $exception);
1370
1371
        if (!\is_dir($value)) {
1372
            static::throwException(\sprintf(
1373
                $message ?: 'The path %s is no directory.',
1374
                static::valueToString($value)
1375
            ), $exception);
1376
        }
1377
    }
1378
1379
    /**
1380
     * @param mixed $value
@@ 1558-1566 (lines=9) @@
1555
     * @param null $exception
1556
     * @throws Exception
1557
     */
1558
    public static function keyExists($array, $key, $message = '', $exception = null)
1559
    {
1560
        if (!(isset($array[$key]) || \array_key_exists($key, $array))) {
1561
            static::throwException(\sprintf(
1562
                $message ?: 'Expected the key %s to exist.',
1563
                static::valueToString($key)
1564
            ), $exception);
1565
        }
1566
    }
1567
1568
    /**
1569
     * @param array $array
@@ 1575-1583 (lines=9) @@
1572
     * @param null $exception
1573
     * @throws Exception
1574
     */
1575
    public static function keyNotExists($array, $key, $message = '', $exception = null)
1576
    {
1577
        if (isset($array[$key]) || \array_key_exists($key, $array)) {
1578
            static::throwException(\sprintf(
1579
                $message ?: 'Expected the key %s to not exist.',
1580
                static::valueToString($key)
1581
            ), $exception);
1582
        }
1583
    }
1584
1585
    /**
1586
     * Does not check if $array is countable, this can generate a warning on php versions after 7.2.