Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1335-1350 (lines=16) @@
1332
     *
1333
     * @throws InvalidArgumentException
1334
     */
1335
    public static function alpha($value, $message = '')
1336
    {
1337
        static::string($value);
1338
1339
        $locale = \setlocale(LC_CTYPE, 0);
1340
        \setlocale(LC_CTYPE, 'C');
1341
        $valid = !\ctype_alpha($value);
1342
        \setlocale(LC_CTYPE, $locale);
1343
1344
        if ($valid) {
1345
            static::reportInvalidArgument(\sprintf(
1346
                $message ?: 'Expected a value to contain only letters. Got: %s',
1347
                static::valueToString($value)
1348
            ));
1349
        }
1350
    }
1351
1352
    /**
1353
     * @psalm-pure
@@ 1360-1373 (lines=14) @@
1357
     *
1358
     * @throws InvalidArgumentException
1359
     */
1360
    public static function digits($value, $message = '')
1361
    {
1362
        $locale = \setlocale(LC_CTYPE, 0);
1363
        \setlocale(LC_CTYPE, 'C');
1364
        $valid = !\ctype_digit($value);
1365
        \setlocale(LC_CTYPE, $locale);
1366
1367
        if ($valid) {
1368
            static::reportInvalidArgument(\sprintf(
1369
                $message ?: 'Expected a value to contain digits only. Got: %s',
1370
                static::valueToString($value)
1371
            ));
1372
        }
1373
    }
1374
1375
    /**
1376
     * @psalm-pure
@@ 1383-1396 (lines=14) @@
1380
     *
1381
     * @throws InvalidArgumentException
1382
     */
1383
    public static function alnum($value, $message = '')
1384
    {
1385
        $locale = \setlocale(LC_CTYPE, 0);
1386
        \setlocale(LC_CTYPE, 'C');
1387
        $valid = !\ctype_alnum($value);
1388
        \setlocale(LC_CTYPE, $locale);
1389
1390
        if ($valid) {
1391
            static::reportInvalidArgument(\sprintf(
1392
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1393
                static::valueToString($value)
1394
            ));
1395
        }
1396
    }
1397
1398
    /**
1399
     * @psalm-pure
@@ 1407-1420 (lines=14) @@
1404
     *
1405
     * @throws InvalidArgumentException
1406
     */
1407
    public static function lower($value, $message = '')
1408
    {
1409
        $locale = \setlocale(LC_CTYPE, 0);
1410
        \setlocale(LC_CTYPE, 'C');
1411
        $valid = !\ctype_lower($value);
1412
        \setlocale(LC_CTYPE, $locale);
1413
1414
        if ($valid) {
1415
            static::reportInvalidArgument(\sprintf(
1416
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1417
                static::valueToString($value)
1418
            ));
1419
        }
1420
    }
1421
1422
    /**
1423
     * @psalm-pure
@@ 1431-1444 (lines=14) @@
1428
     *
1429
     * @throws InvalidArgumentException
1430
     */
1431
    public static function upper($value, $message = '')
1432
    {
1433
        $locale = \setlocale(LC_CTYPE, 0);
1434
        \setlocale(LC_CTYPE, 'C');
1435
        $valid = !\ctype_upper($value);
1436
        \setlocale(LC_CTYPE, $locale);
1437
1438
        if ($valid) {
1439
            static::reportInvalidArgument(\sprintf(
1440
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1441
                static::valueToString($value)
1442
            ));
1443
        }
1444
    }
1445
1446
    /**
1447
     * @psalm-pure