Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

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