Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

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