Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

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