Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1363-1378 (lines=16) @@
1360
     *
1361
     * @throws InvalidArgumentException
1362
     */
1363
    public static function alpha($value, $message = '')
1364
    {
1365
        static::string($value);
1366
1367
        $locale = \setlocale(LC_CTYPE, 0);
1368
        \setlocale(LC_CTYPE, 'C');
1369
        $valid = !\ctype_alpha($value);
1370
        \setlocale(LC_CTYPE, $locale);
1371
1372
        if ($valid) {
1373
            static::reportInvalidArgument(\sprintf(
1374
                $message ?: 'Expected a value to contain only letters. Got: %s',
1375
                static::valueToString($value)
1376
            ));
1377
        }
1378
    }
1379
1380
    /**
1381
     * @psalm-pure
@@ 1388-1401 (lines=14) @@
1385
     *
1386
     * @throws InvalidArgumentException
1387
     */
1388
    public static function digits($value, $message = '')
1389
    {
1390
        $locale = \setlocale(LC_CTYPE, 0);
1391
        \setlocale(LC_CTYPE, 'C');
1392
        $valid = !\ctype_digit($value);
1393
        \setlocale(LC_CTYPE, $locale);
1394
1395
        if ($valid) {
1396
            static::reportInvalidArgument(\sprintf(
1397
                $message ?: 'Expected a value to contain digits only. Got: %s',
1398
                static::valueToString($value)
1399
            ));
1400
        }
1401
    }
1402
1403
    /**
1404
     * @psalm-pure
@@ 1411-1424 (lines=14) @@
1408
     *
1409
     * @throws InvalidArgumentException
1410
     */
1411
    public static function alnum($value, $message = '')
1412
    {
1413
        $locale = \setlocale(LC_CTYPE, 0);
1414
        \setlocale(LC_CTYPE, 'C');
1415
        $valid = !\ctype_alnum($value);
1416
        \setlocale(LC_CTYPE, $locale);
1417
1418
        if ($valid) {
1419
            static::reportInvalidArgument(\sprintf(
1420
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1421
                static::valueToString($value)
1422
            ));
1423
        }
1424
    }
1425
1426
    /**
1427
     * @psalm-pure
@@ 1435-1448 (lines=14) @@
1432
     *
1433
     * @throws InvalidArgumentException
1434
     */
1435
    public static function lower($value, $message = '')
1436
    {
1437
        $locale = \setlocale(LC_CTYPE, 0);
1438
        \setlocale(LC_CTYPE, 'C');
1439
        $valid = !\ctype_lower($value);
1440
        \setlocale(LC_CTYPE, $locale);
1441
1442
        if ($valid) {
1443
            static::reportInvalidArgument(\sprintf(
1444
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1445
                static::valueToString($value)
1446
            ));
1447
        }
1448
    }
1449
1450
    /**
1451
     * @psalm-pure
@@ 1459-1472 (lines=14) @@
1456
     *
1457
     * @throws InvalidArgumentException
1458
     */
1459
    public static function upper($value, $message = '')
1460
    {
1461
        $locale = \setlocale(LC_CTYPE, 0);
1462
        \setlocale(LC_CTYPE, 'C');
1463
        $valid = !\ctype_upper($value);
1464
        \setlocale(LC_CTYPE, $locale);
1465
1466
        if ($valid) {
1467
            static::reportInvalidArgument(\sprintf(
1468
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1469
                static::valueToString($value)
1470
            ));
1471
        }
1472
    }
1473
1474
    /**
1475
     * @psalm-pure