Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

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