Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1382-1397 (lines=16) @@
1379
     *
1380
     * @throws InvalidArgumentException
1381
     */
1382
    public static function alpha($value, $message = '')
1383
    {
1384
        static::string($value);
1385
1386
        $locale = \setlocale(LC_CTYPE, 0);
1387
        \setlocale(LC_CTYPE, 'C');
1388
        $valid = !\ctype_alpha($value);
1389
        \setlocale(LC_CTYPE, $locale);
1390
1391
        if ($valid) {
1392
            static::reportInvalidArgument(\sprintf(
1393
                $message ?: 'Expected a value to contain only letters. Got: %s',
1394
                static::valueToString($value)
1395
            ));
1396
        }
1397
    }
1398
1399
    /**
1400
     * @psalm-pure
@@ 1407-1420 (lines=14) @@
1404
     *
1405
     * @throws InvalidArgumentException
1406
     */
1407
    public static function digits($value, $message = '')
1408
    {
1409
        $locale = \setlocale(LC_CTYPE, 0);
1410
        \setlocale(LC_CTYPE, 'C');
1411
        $valid = !\ctype_digit($value);
1412
        \setlocale(LC_CTYPE, $locale);
1413
1414
        if ($valid) {
1415
            static::reportInvalidArgument(\sprintf(
1416
                $message ?: 'Expected a value to contain digits only. Got: %s',
1417
                static::valueToString($value)
1418
            ));
1419
        }
1420
    }
1421
1422
    /**
1423
     * @psalm-pure
@@ 1430-1443 (lines=14) @@
1427
     *
1428
     * @throws InvalidArgumentException
1429
     */
1430
    public static function alnum($value, $message = '')
1431
    {
1432
        $locale = \setlocale(LC_CTYPE, 0);
1433
        \setlocale(LC_CTYPE, 'C');
1434
        $valid = !\ctype_alnum($value);
1435
        \setlocale(LC_CTYPE, $locale);
1436
1437
        if ($valid) {
1438
            static::reportInvalidArgument(\sprintf(
1439
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1440
                static::valueToString($value)
1441
            ));
1442
        }
1443
    }
1444
1445
    /**
1446
     * @psalm-pure
@@ 1454-1467 (lines=14) @@
1451
     *
1452
     * @throws InvalidArgumentException
1453
     */
1454
    public static function lower($value, $message = '')
1455
    {
1456
        $locale = \setlocale(LC_CTYPE, 0);
1457
        \setlocale(LC_CTYPE, 'C');
1458
        $valid = !\ctype_lower($value);
1459
        \setlocale(LC_CTYPE, $locale);
1460
1461
        if ($valid) {
1462
            static::reportInvalidArgument(\sprintf(
1463
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1464
                static::valueToString($value)
1465
            ));
1466
        }
1467
    }
1468
1469
    /**
1470
     * @psalm-pure
@@ 1478-1491 (lines=14) @@
1475
     *
1476
     * @throws InvalidArgumentException
1477
     */
1478
    public static function upper($value, $message = '')
1479
    {
1480
        $locale = \setlocale(LC_CTYPE, 0);
1481
        \setlocale(LC_CTYPE, 'C');
1482
        $valid = !\ctype_upper($value);
1483
        \setlocale(LC_CTYPE, $locale);
1484
1485
        if ($valid) {
1486
            static::reportInvalidArgument(\sprintf(
1487
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1488
                static::valueToString($value)
1489
            ));
1490
        }
1491
    }
1492
1493
    /**
1494
     * @psalm-pure