Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1238-1253 (lines=16) @@
1235
     *
1236
     * @throws InvalidArgumentException
1237
     */
1238
    public static function alpha($value, $message = '')
1239
    {
1240
        static::string($value);
1241
1242
        $locale = \setlocale(LC_CTYPE, 0);
1243
        \setlocale(LC_CTYPE, 'C');
1244
        $valid = !\ctype_alpha($value);
1245
        \setlocale(LC_CTYPE, $locale);
1246
1247
        if ($valid) {
1248
            static::reportInvalidArgument(\sprintf(
1249
                $message ?: 'Expected a value to contain only letters. Got: %s',
1250
                static::valueToString($value)
1251
            ));
1252
        }
1253
    }
1254
1255
    /**
1256
     * @psalm-pure
@@ 1263-1276 (lines=14) @@
1260
     *
1261
     * @throws InvalidArgumentException
1262
     */
1263
    public static function digits($value, $message = '')
1264
    {
1265
        $locale = \setlocale(LC_CTYPE, 0);
1266
        \setlocale(LC_CTYPE, 'C');
1267
        $valid = !\ctype_digit($value);
1268
        \setlocale(LC_CTYPE, $locale);
1269
1270
        if ($valid) {
1271
            static::reportInvalidArgument(\sprintf(
1272
                $message ?: 'Expected a value to contain digits only. Got: %s',
1273
                static::valueToString($value)
1274
            ));
1275
        }
1276
    }
1277
1278
    /**
1279
     * @psalm-pure
@@ 1286-1299 (lines=14) @@
1283
     *
1284
     * @throws InvalidArgumentException
1285
     */
1286
    public static function alnum($value, $message = '')
1287
    {
1288
        $locale = \setlocale(LC_CTYPE, 0);
1289
        \setlocale(LC_CTYPE, 'C');
1290
        $valid = !\ctype_alnum($value);
1291
        \setlocale(LC_CTYPE, $locale);
1292
1293
        if ($valid) {
1294
            static::reportInvalidArgument(\sprintf(
1295
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1296
                static::valueToString($value)
1297
            ));
1298
        }
1299
    }
1300
1301
    /**
1302
     * @psalm-pure
@@ 1310-1323 (lines=14) @@
1307
     *
1308
     * @throws InvalidArgumentException
1309
     */
1310
    public static function lower($value, $message = '')
1311
    {
1312
        $locale = \setlocale(LC_CTYPE, 0);
1313
        \setlocale(LC_CTYPE, 'C');
1314
        $valid = !\ctype_lower($value);
1315
        \setlocale(LC_CTYPE, $locale);
1316
1317
        if ($valid) {
1318
            static::reportInvalidArgument(\sprintf(
1319
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1320
                static::valueToString($value)
1321
            ));
1322
        }
1323
    }
1324
1325
    /**
1326
     * @psalm-pure
@@ 1334-1347 (lines=14) @@
1331
     *
1332
     * @throws InvalidArgumentException
1333
     */
1334
    public static function upper($value, $message = '')
1335
    {
1336
        $locale = \setlocale(LC_CTYPE, 0);
1337
        \setlocale(LC_CTYPE, 'C');
1338
        $valid = !\ctype_upper($value);
1339
        \setlocale(LC_CTYPE, $locale);
1340
1341
        if ($valid) {
1342
            static::reportInvalidArgument(\sprintf(
1343
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1344
                static::valueToString($value)
1345
            ));
1346
        }
1347
    }
1348
1349
    /**
1350
     * @psalm-pure