Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1422-1437 (lines=16) @@
1419
     *
1420
     * @throws InvalidArgumentException
1421
     */
1422
    public static function alpha($value, $message = '')
1423
    {
1424
        static::string($value);
1425
1426
        $locale = \setlocale(LC_CTYPE, 0);
1427
        \setlocale(LC_CTYPE, 'C');
1428
        $valid = !\ctype_alpha($value);
1429
        \setlocale(LC_CTYPE, $locale);
1430
1431
        if ($valid) {
1432
            static::reportInvalidArgument(\sprintf(
1433
                $message ?: 'Expected a value to contain only letters. Got: %s',
1434
                static::valueToString($value)
1435
            ));
1436
        }
1437
    }
1438
1439
    /**
1440
     * @psalm-pure
@@ 1447-1460 (lines=14) @@
1444
     *
1445
     * @throws InvalidArgumentException
1446
     */
1447
    public static function digits($value, $message = '')
1448
    {
1449
        $locale = \setlocale(LC_CTYPE, 0);
1450
        \setlocale(LC_CTYPE, 'C');
1451
        $valid = !\ctype_digit($value);
1452
        \setlocale(LC_CTYPE, $locale);
1453
1454
        if ($valid) {
1455
            static::reportInvalidArgument(\sprintf(
1456
                $message ?: 'Expected a value to contain digits only. Got: %s',
1457
                static::valueToString($value)
1458
            ));
1459
        }
1460
    }
1461
1462
    /**
1463
     * @psalm-pure
@@ 1470-1483 (lines=14) @@
1467
     *
1468
     * @throws InvalidArgumentException
1469
     */
1470
    public static function alnum($value, $message = '')
1471
    {
1472
        $locale = \setlocale(LC_CTYPE, 0);
1473
        \setlocale(LC_CTYPE, 'C');
1474
        $valid = !\ctype_alnum($value);
1475
        \setlocale(LC_CTYPE, $locale);
1476
1477
        if ($valid) {
1478
            static::reportInvalidArgument(\sprintf(
1479
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1480
                static::valueToString($value)
1481
            ));
1482
        }
1483
    }
1484
1485
    /**
1486
     * @psalm-pure
@@ 1494-1507 (lines=14) @@
1491
     *
1492
     * @throws InvalidArgumentException
1493
     */
1494
    public static function lower($value, $message = '')
1495
    {
1496
        $locale = \setlocale(LC_CTYPE, 0);
1497
        \setlocale(LC_CTYPE, 'C');
1498
        $valid = !\ctype_lower($value);
1499
        \setlocale(LC_CTYPE, $locale);
1500
1501
        if ($valid) {
1502
            static::reportInvalidArgument(\sprintf(
1503
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1504
                static::valueToString($value)
1505
            ));
1506
        }
1507
    }
1508
1509
    /**
1510
     * @psalm-pure
@@ 1518-1531 (lines=14) @@
1515
     *
1516
     * @throws InvalidArgumentException
1517
     */
1518
    public static function upper($value, $message = '')
1519
    {
1520
        $locale = \setlocale(LC_CTYPE, 0);
1521
        \setlocale(LC_CTYPE, 'C');
1522
        $valid = !\ctype_upper($value);
1523
        \setlocale(LC_CTYPE, $locale);
1524
1525
        if ($valid) {
1526
            static::reportInvalidArgument(\sprintf(
1527
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1528
                static::valueToString($value)
1529
            ));
1530
        }
1531
    }
1532
1533
    /**
1534
     * @psalm-pure