Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

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