Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1267-1280 (lines=14) @@
1264
     *
1265
     * @throws InvalidArgumentException
1266
     */
1267
    public static function alnum($value, $message = '')
1268
    {
1269
        $locale = \setlocale(LC_CTYPE, 0);
1270
        \setlocale(LC_CTYPE, 'C');
1271
        $valid = !\ctype_alnum($value);
1272
        \setlocale(LC_CTYPE, $locale);
1273
1274
        if ($valid) {
1275
            static::reportInvalidArgument(\sprintf(
1276
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1277
                static::valueToString($value)
1278
            ));
1279
        }
1280
    }
1281
1282
    /**
1283
     * @psalm-pure
@@ 1291-1304 (lines=14) @@
1288
     *
1289
     * @throws InvalidArgumentException
1290
     */
1291
    public static function lower($value, $message = '')
1292
    {
1293
        $locale = \setlocale(LC_CTYPE, 0);
1294
        \setlocale(LC_CTYPE, 'C');
1295
        $valid = !\ctype_lower($value);
1296
        \setlocale(LC_CTYPE, $locale);
1297
1298
        if ($valid) {
1299
            static::reportInvalidArgument(\sprintf(
1300
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1301
                static::valueToString($value)
1302
            ));
1303
        }
1304
    }
1305
1306
    /**
1307
     * @psalm-pure
@@ 1315-1328 (lines=14) @@
1312
     *
1313
     * @throws InvalidArgumentException
1314
     */
1315
    public static function upper($value, $message = '')
1316
    {
1317
        $locale = \setlocale(LC_CTYPE, 0);
1318
        \setlocale(LC_CTYPE, 'C');
1319
        $valid = !\ctype_upper($value);
1320
        \setlocale(LC_CTYPE, $locale);
1321
1322
        if ($valid) {
1323
            static::reportInvalidArgument(\sprintf(
1324
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1325
                static::valueToString($value)
1326
            ));
1327
        }
1328
    }
1329
1330
    /**
1331
     * @psalm-pure
@@ 1219-1234 (lines=16) @@
1216
     *
1217
     * @throws InvalidArgumentException
1218
     */
1219
    public static function alpha($value, $message = '')
1220
    {
1221
        static::string($value);
1222
1223
        $locale = \setlocale(LC_CTYPE, 0);
1224
        \setlocale(LC_CTYPE, 'C');
1225
        $valid = !\ctype_alpha($value);
1226
        \setlocale(LC_CTYPE, $locale);
1227
1228
        if ($valid) {
1229
            static::reportInvalidArgument(\sprintf(
1230
                $message ?: 'Expected a value to contain only letters. Got: %s',
1231
                static::valueToString($value)
1232
            ));
1233
        }
1234
    }
1235
1236
    /**
1237
     * @psalm-pure
@@ 1244-1257 (lines=14) @@
1241
     *
1242
     * @throws InvalidArgumentException
1243
     */
1244
    public static function digits($value, $message = '')
1245
    {
1246
        $locale = \setlocale(LC_CTYPE, 0);
1247
        \setlocale(LC_CTYPE, 'C');
1248
        $valid = !\ctype_digit($value);
1249
        \setlocale(LC_CTYPE, $locale);
1250
1251
        if ($valid) {
1252
            static::reportInvalidArgument(\sprintf(
1253
                $message ?: 'Expected a value to contain digits only. Got: %s',
1254
                static::valueToString($value)
1255
            ));
1256
        }
1257
    }
1258
1259
    /**
1260
     * @psalm-pure