Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1214-1229 (lines=16) @@
1211
     *
1212
     * @throws InvalidArgumentException
1213
     */
1214
    public static function alpha($value, $message = '')
1215
    {
1216
        static::string($value);
1217
1218
        $locale = \setlocale(LC_CTYPE, 0);
1219
        \setlocale(LC_CTYPE, 'C');
1220
        $valid = !\ctype_alpha($value);
1221
        \setlocale(LC_CTYPE, $locale);
1222
1223
        if ($valid) {
1224
            static::reportInvalidArgument(\sprintf(
1225
                $message ?: 'Expected a value to contain only letters. Got: %s',
1226
                static::valueToString($value)
1227
            ));
1228
        }
1229
    }
1230
1231
    /**
1232
     * @psalm-pure
@@ 1239-1252 (lines=14) @@
1236
     *
1237
     * @throws InvalidArgumentException
1238
     */
1239
    public static function digits($value, $message = '')
1240
    {
1241
        $locale = \setlocale(LC_CTYPE, 0);
1242
        \setlocale(LC_CTYPE, 'C');
1243
        $valid = !\ctype_digit($value);
1244
        \setlocale(LC_CTYPE, $locale);
1245
1246
        if ($valid) {
1247
            static::reportInvalidArgument(\sprintf(
1248
                $message ?: 'Expected a value to contain digits only. Got: %s',
1249
                static::valueToString($value)
1250
            ));
1251
        }
1252
    }
1253
1254
    /**
1255
     * @psalm-pure
@@ 1262-1275 (lines=14) @@
1259
     *
1260
     * @throws InvalidArgumentException
1261
     */
1262
    public static function alnum($value, $message = '')
1263
    {
1264
        $locale = \setlocale(LC_CTYPE, 0);
1265
        \setlocale(LC_CTYPE, 'C');
1266
        $valid = !\ctype_alnum($value);
1267
        \setlocale(LC_CTYPE, $locale);
1268
1269
        if ($valid) {
1270
            static::reportInvalidArgument(\sprintf(
1271
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1272
                static::valueToString($value)
1273
            ));
1274
        }
1275
    }
1276
1277
    /**
1278
     * @psalm-pure
@@ 1286-1299 (lines=14) @@
1283
     *
1284
     * @throws InvalidArgumentException
1285
     */
1286
    public static function lower($value, $message = '')
1287
    {
1288
        $locale = \setlocale(LC_CTYPE, 0);
1289
        \setlocale(LC_CTYPE, 'C');
1290
        $valid = !\ctype_lower($value);
1291
        \setlocale(LC_CTYPE, $locale);
1292
1293
        if ($valid) {
1294
            static::reportInvalidArgument(\sprintf(
1295
                $message ?: 'Expected a value to contain lowercase characters 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 upper($value, $message = '')
1311
    {
1312
        $locale = \setlocale(LC_CTYPE, 0);
1313
        \setlocale(LC_CTYPE, 'C');
1314
        $valid = !\ctype_upper($value);
1315
        \setlocale(LC_CTYPE, $locale);
1316
1317
        if ($valid) {
1318
            static::reportInvalidArgument(\sprintf(
1319
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1320
                static::valueToString($value)
1321
            ));
1322
        }
1323
    }
1324
1325
    /**
1326
     * @psalm-pure