Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1234-1249 (lines=16) @@
1231
     *
1232
     * @throws InvalidArgumentException
1233
     */
1234
    public static function alpha($value, $message = '')
1235
    {
1236
        static::string($value);
1237
1238
        $locale = \setlocale(LC_CTYPE, 0);
1239
        \setlocale(LC_CTYPE, 'C');
1240
        $valid = !\ctype_alpha($value);
1241
        \setlocale(LC_CTYPE, $locale);
1242
1243
        if ($valid) {
1244
            static::reportInvalidArgument(\sprintf(
1245
                $message ?: 'Expected a value to contain only letters. Got: %s',
1246
                static::valueToString($value)
1247
            ));
1248
        }
1249
    }
1250
1251
    /**
1252
     * @param mixed  $value
@@ 1257-1270 (lines=14) @@
1254
     *
1255
     * @throws InvalidArgumentException
1256
     */
1257
    public static function digits($value, $message = '')
1258
    {
1259
        $locale = \setlocale(LC_CTYPE, 0);
1260
        \setlocale(LC_CTYPE, 'C');
1261
        $valid = !\ctype_digit($value);
1262
        \setlocale(LC_CTYPE, $locale);
1263
1264
        if ($valid) {
1265
            static::reportInvalidArgument(\sprintf(
1266
                $message ?: 'Expected a value to contain digits only. Got: %s',
1267
                static::valueToString($value)
1268
            ));
1269
        }
1270
    }
1271
1272
    /**
1273
     * @param mixed  $value
@@ 1278-1291 (lines=14) @@
1275
     *
1276
     * @throws InvalidArgumentException
1277
     */
1278
    public static function alnum($value, $message = '')
1279
    {
1280
        $locale = \setlocale(LC_CTYPE, 0);
1281
        \setlocale(LC_CTYPE, 'C');
1282
        $valid = !\ctype_alnum($value);
1283
        \setlocale(LC_CTYPE, $locale);
1284
1285
        if ($valid) {
1286
            static::reportInvalidArgument(\sprintf(
1287
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1288
                static::valueToString($value)
1289
            ));
1290
        }
1291
    }
1292
1293
    /**
1294
     * @param mixed  $value
@@ 1299-1312 (lines=14) @@
1296
     *
1297
     * @throws InvalidArgumentException
1298
     */
1299
    public static function lower($value, $message = '')
1300
    {
1301
        $locale = \setlocale(LC_CTYPE, 0);
1302
        \setlocale(LC_CTYPE, 'C');
1303
        $valid = !\ctype_lower($value);
1304
        \setlocale(LC_CTYPE, $locale);
1305
1306
        if ($valid) {
1307
            static::reportInvalidArgument(\sprintf(
1308
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1309
                static::valueToString($value)
1310
            ));
1311
        }
1312
    }
1313
1314
    /**
1315
     * @param mixed  $value
@@ 1320-1333 (lines=14) @@
1317
     *
1318
     * @throws InvalidArgumentException
1319
     */
1320
    public static function upper($value, $message = '')
1321
    {
1322
        $locale = \setlocale(LC_CTYPE, 0);
1323
        \setlocale(LC_CTYPE, 'C');
1324
        $valid = !\ctype_upper($value);
1325
        \setlocale(LC_CTYPE, $locale);
1326
1327
        if ($valid) {
1328
            static::reportInvalidArgument(\sprintf(
1329
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1330
                static::valueToString($value)
1331
            ));
1332
        }
1333
    }
1334
1335
    /**
1336
     * @param mixed  $value