Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1317-1332 (lines=16) @@
1314
     *
1315
     * @throws InvalidArgumentException
1316
     */
1317
    public static function alpha($value, $message = '')
1318
    {
1319
        static::string($value);
1320
1321
        $locale = \setlocale(LC_CTYPE, 0);
1322
        \setlocale(LC_CTYPE, 'C');
1323
        $valid = !\ctype_alpha($value);
1324
        \setlocale(LC_CTYPE, $locale);
1325
1326
        if ($valid) {
1327
            static::reportInvalidArgument(\sprintf(
1328
                $message ?: 'Expected a value to contain only letters. Got: %s',
1329
                static::valueToString($value)
1330
            ));
1331
        }
1332
    }
1333
1334
    /**
1335
     * @psalm-pure
@@ 1342-1355 (lines=14) @@
1339
     *
1340
     * @throws InvalidArgumentException
1341
     */
1342
    public static function digits($value, $message = '')
1343
    {
1344
        $locale = \setlocale(LC_CTYPE, 0);
1345
        \setlocale(LC_CTYPE, 'C');
1346
        $valid = !\ctype_digit($value);
1347
        \setlocale(LC_CTYPE, $locale);
1348
1349
        if ($valid) {
1350
            static::reportInvalidArgument(\sprintf(
1351
                $message ?: 'Expected a value to contain digits only. Got: %s',
1352
                static::valueToString($value)
1353
            ));
1354
        }
1355
    }
1356
1357
    /**
1358
     * @psalm-pure
@@ 1365-1378 (lines=14) @@
1362
     *
1363
     * @throws InvalidArgumentException
1364
     */
1365
    public static function alnum($value, $message = '')
1366
    {
1367
        $locale = \setlocale(LC_CTYPE, 0);
1368
        \setlocale(LC_CTYPE, 'C');
1369
        $valid = !\ctype_alnum($value);
1370
        \setlocale(LC_CTYPE, $locale);
1371
1372
        if ($valid) {
1373
            static::reportInvalidArgument(\sprintf(
1374
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1375
                static::valueToString($value)
1376
            ));
1377
        }
1378
    }
1379
1380
    /**
1381
     * @psalm-pure
@@ 1389-1402 (lines=14) @@
1386
     *
1387
     * @throws InvalidArgumentException
1388
     */
1389
    public static function lower($value, $message = '')
1390
    {
1391
        $locale = \setlocale(LC_CTYPE, 0);
1392
        \setlocale(LC_CTYPE, 'C');
1393
        $valid = !\ctype_lower($value);
1394
        \setlocale(LC_CTYPE, $locale);
1395
1396
        if ($valid) {
1397
            static::reportInvalidArgument(\sprintf(
1398
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1399
                static::valueToString($value)
1400
            ));
1401
        }
1402
    }
1403
1404
    /**
1405
     * @psalm-pure
@@ 1413-1426 (lines=14) @@
1410
     *
1411
     * @throws InvalidArgumentException
1412
     */
1413
    public static function upper($value, $message = '')
1414
    {
1415
        $locale = \setlocale(LC_CTYPE, 0);
1416
        \setlocale(LC_CTYPE, 'C');
1417
        $valid = !\ctype_upper($value);
1418
        \setlocale(LC_CTYPE, $locale);
1419
1420
        if ($valid) {
1421
            static::reportInvalidArgument(\sprintf(
1422
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1423
                static::valueToString($value)
1424
            ));
1425
        }
1426
    }
1427
1428
    /**
1429
     * @psalm-pure