Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1402-1417 (lines=16) @@
1399
     *
1400
     * @throws InvalidArgumentException
1401
     */
1402
    public static function alpha($value, $message = '')
1403
    {
1404
        static::string($value);
1405
1406
        $locale = \setlocale(LC_CTYPE, 0);
1407
        \setlocale(LC_CTYPE, 'C');
1408
        $valid = !\ctype_alpha($value);
1409
        \setlocale(LC_CTYPE, $locale);
1410
1411
        if ($valid) {
1412
            static::reportInvalidArgument(\sprintf(
1413
                $message ?: 'Expected a value to contain only letters. Got: %s',
1414
                static::valueToString($value)
1415
            ));
1416
        }
1417
    }
1418
1419
    /**
1420
     * @psalm-pure
@@ 1427-1440 (lines=14) @@
1424
     *
1425
     * @throws InvalidArgumentException
1426
     */
1427
    public static function digits($value, $message = '')
1428
    {
1429
        $locale = \setlocale(LC_CTYPE, 0);
1430
        \setlocale(LC_CTYPE, 'C');
1431
        $valid = !\ctype_digit($value);
1432
        \setlocale(LC_CTYPE, $locale);
1433
1434
        if ($valid) {
1435
            static::reportInvalidArgument(\sprintf(
1436
                $message ?: 'Expected a value to contain digits only. Got: %s',
1437
                static::valueToString($value)
1438
            ));
1439
        }
1440
    }
1441
1442
    /**
1443
     * @psalm-pure
@@ 1450-1463 (lines=14) @@
1447
     *
1448
     * @throws InvalidArgumentException
1449
     */
1450
    public static function alnum($value, $message = '')
1451
    {
1452
        $locale = \setlocale(LC_CTYPE, 0);
1453
        \setlocale(LC_CTYPE, 'C');
1454
        $valid = !\ctype_alnum($value);
1455
        \setlocale(LC_CTYPE, $locale);
1456
1457
        if ($valid) {
1458
            static::reportInvalidArgument(\sprintf(
1459
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1460
                static::valueToString($value)
1461
            ));
1462
        }
1463
    }
1464
1465
    /**
1466
     * @psalm-pure
@@ 1474-1487 (lines=14) @@
1471
     *
1472
     * @throws InvalidArgumentException
1473
     */
1474
    public static function lower($value, $message = '')
1475
    {
1476
        $locale = \setlocale(LC_CTYPE, 0);
1477
        \setlocale(LC_CTYPE, 'C');
1478
        $valid = !\ctype_lower($value);
1479
        \setlocale(LC_CTYPE, $locale);
1480
1481
        if ($valid) {
1482
            static::reportInvalidArgument(\sprintf(
1483
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1484
                static::valueToString($value)
1485
            ));
1486
        }
1487
    }
1488
1489
    /**
1490
     * @psalm-pure
@@ 1498-1511 (lines=14) @@
1495
     *
1496
     * @throws InvalidArgumentException
1497
     */
1498
    public static function upper($value, $message = '')
1499
    {
1500
        $locale = \setlocale(LC_CTYPE, 0);
1501
        \setlocale(LC_CTYPE, 'C');
1502
        $valid = !\ctype_upper($value);
1503
        \setlocale(LC_CTYPE, $locale);
1504
1505
        if ($valid) {
1506
            static::reportInvalidArgument(\sprintf(
1507
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1508
                static::valueToString($value)
1509
            ));
1510
        }
1511
    }
1512
1513
    /**
1514
     * @psalm-pure