Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1259-1274 (lines=16) @@
1256
     *
1257
     * @throws InvalidArgumentException
1258
     */
1259
    public static function alpha($value, $message = '')
1260
    {
1261
        static::string($value);
1262
1263
        $locale = \setlocale(LC_CTYPE, 0);
1264
        \setlocale(LC_CTYPE, 'C');
1265
        $valid = !\ctype_alpha($value);
1266
        \setlocale(LC_CTYPE, $locale);
1267
1268
        if ($valid) {
1269
            static::reportInvalidArgument(\sprintf(
1270
                $message ?: 'Expected a value to contain only letters. Got: %s',
1271
                static::valueToString($value)
1272
            ));
1273
        }
1274
    }
1275
1276
    /**
1277
     * @psalm-pure
@@ 1284-1297 (lines=14) @@
1281
     *
1282
     * @throws InvalidArgumentException
1283
     */
1284
    public static function digits($value, $message = '')
1285
    {
1286
        $locale = \setlocale(LC_CTYPE, 0);
1287
        \setlocale(LC_CTYPE, 'C');
1288
        $valid = !\ctype_digit($value);
1289
        \setlocale(LC_CTYPE, $locale);
1290
1291
        if ($valid) {
1292
            static::reportInvalidArgument(\sprintf(
1293
                $message ?: 'Expected a value to contain digits only. Got: %s',
1294
                static::valueToString($value)
1295
            ));
1296
        }
1297
    }
1298
1299
    /**
1300
     * @psalm-pure
@@ 1307-1320 (lines=14) @@
1304
     *
1305
     * @throws InvalidArgumentException
1306
     */
1307
    public static function alnum($value, $message = '')
1308
    {
1309
        $locale = \setlocale(LC_CTYPE, 0);
1310
        \setlocale(LC_CTYPE, 'C');
1311
        $valid = !\ctype_alnum($value);
1312
        \setlocale(LC_CTYPE, $locale);
1313
1314
        if ($valid) {
1315
            static::reportInvalidArgument(\sprintf(
1316
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1317
                static::valueToString($value)
1318
            ));
1319
        }
1320
    }
1321
1322
    /**
1323
     * @psalm-pure
@@ 1331-1344 (lines=14) @@
1328
     *
1329
     * @throws InvalidArgumentException
1330
     */
1331
    public static function lower($value, $message = '')
1332
    {
1333
        $locale = \setlocale(LC_CTYPE, 0);
1334
        \setlocale(LC_CTYPE, 'C');
1335
        $valid = !\ctype_lower($value);
1336
        \setlocale(LC_CTYPE, $locale);
1337
1338
        if ($valid) {
1339
            static::reportInvalidArgument(\sprintf(
1340
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1341
                static::valueToString($value)
1342
            ));
1343
        }
1344
    }
1345
1346
    /**
1347
     * @psalm-pure
@@ 1355-1368 (lines=14) @@
1352
     *
1353
     * @throws InvalidArgumentException
1354
     */
1355
    public static function upper($value, $message = '')
1356
    {
1357
        $locale = \setlocale(LC_CTYPE, 0);
1358
        \setlocale(LC_CTYPE, 'C');
1359
        $valid = !\ctype_upper($value);
1360
        \setlocale(LC_CTYPE, $locale);
1361
1362
        if ($valid) {
1363
            static::reportInvalidArgument(\sprintf(
1364
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1365
                static::valueToString($value)
1366
            ));
1367
        }
1368
    }
1369
1370
    /**
1371
     * @psalm-pure