Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1200-1215 (lines=16) @@
1197
     *
1198
     * @throws InvalidArgumentException
1199
     */
1200
    public static function alpha($value, $message = '')
1201
    {
1202
        static::string($value);
1203
1204
        $locale = \setlocale(LC_CTYPE, 0);
1205
        \setlocale(LC_CTYPE, 'C');
1206
        $valid = !\ctype_alpha($value);
1207
        \setlocale(LC_CTYPE, $locale);
1208
1209
        if ($valid) {
1210
            static::reportInvalidArgument(\sprintf(
1211
                $message ?: 'Expected a value to contain only letters. Got: %s',
1212
                static::valueToString($value)
1213
            ));
1214
        }
1215
    }
1216
1217
    /**
1218
     * @psalm-pure
@@ 1225-1238 (lines=14) @@
1222
     *
1223
     * @throws InvalidArgumentException
1224
     */
1225
    public static function digits($value, $message = '')
1226
    {
1227
        $locale = \setlocale(LC_CTYPE, 0);
1228
        \setlocale(LC_CTYPE, 'C');
1229
        $valid = !\ctype_digit($value);
1230
        \setlocale(LC_CTYPE, $locale);
1231
1232
        if ($valid) {
1233
            static::reportInvalidArgument(\sprintf(
1234
                $message ?: 'Expected a value to contain digits only. Got: %s',
1235
                static::valueToString($value)
1236
            ));
1237
        }
1238
    }
1239
1240
    /**
1241
     * @psalm-pure
@@ 1248-1261 (lines=14) @@
1245
     *
1246
     * @throws InvalidArgumentException
1247
     */
1248
    public static function alnum($value, $message = '')
1249
    {
1250
        $locale = \setlocale(LC_CTYPE, 0);
1251
        \setlocale(LC_CTYPE, 'C');
1252
        $valid = !\ctype_alnum($value);
1253
        \setlocale(LC_CTYPE, $locale);
1254
1255
        if ($valid) {
1256
            static::reportInvalidArgument(\sprintf(
1257
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1258
                static::valueToString($value)
1259
            ));
1260
        }
1261
    }
1262
1263
    /**
1264
     * @psalm-pure
@@ 1272-1285 (lines=14) @@
1269
     *
1270
     * @throws InvalidArgumentException
1271
     */
1272
    public static function lower($value, $message = '')
1273
    {
1274
        $locale = \setlocale(LC_CTYPE, 0);
1275
        \setlocale(LC_CTYPE, 'C');
1276
        $valid = !\ctype_lower($value);
1277
        \setlocale(LC_CTYPE, $locale);
1278
1279
        if ($valid) {
1280
            static::reportInvalidArgument(\sprintf(
1281
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1282
                static::valueToString($value)
1283
            ));
1284
        }
1285
    }
1286
1287
    /**
1288
     * @psalm-pure
@@ 1296-1309 (lines=14) @@
1293
     *
1294
     * @throws InvalidArgumentException
1295
     */
1296
    public static function upper($value, $message = '')
1297
    {
1298
        $locale = \setlocale(LC_CTYPE, 0);
1299
        \setlocale(LC_CTYPE, 'C');
1300
        $valid = !\ctype_upper($value);
1301
        \setlocale(LC_CTYPE, $locale);
1302
1303
        if ($valid) {
1304
            static::reportInvalidArgument(\sprintf(
1305
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1306
                static::valueToString($value)
1307
            ));
1308
        }
1309
    }
1310
1311
    /**
1312
     * @psalm-pure