Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1164-1179 (lines=16) @@
1161
     *
1162
     * @throws InvalidArgumentException
1163
     */
1164
    public static function alpha($value, $message = '')
1165
    {
1166
        static::string($value);
1167
1168
        $locale = \setlocale(LC_CTYPE, 0);
1169
        \setlocale(LC_CTYPE, 'C');
1170
        $valid = !\ctype_alpha($value);
1171
        \setlocale(LC_CTYPE, $locale);
1172
1173
        if ($valid) {
1174
            static::reportInvalidArgument(\sprintf(
1175
                $message ?: 'Expected a value to contain only letters. Got: %s',
1176
                static::valueToString($value)
1177
            ));
1178
        }
1179
    }
1180
1181
    /**
1182
     * @param mixed  $value
@@ 1187-1200 (lines=14) @@
1184
     *
1185
     * @throws InvalidArgumentException
1186
     */
1187
    public static function digits($value, $message = '')
1188
    {
1189
        $locale = \setlocale(LC_CTYPE, 0);
1190
        \setlocale(LC_CTYPE, 'C');
1191
        $valid = !\ctype_digit($value);
1192
        \setlocale(LC_CTYPE, $locale);
1193
1194
        if ($valid) {
1195
            static::reportInvalidArgument(\sprintf(
1196
                $message ?: 'Expected a value to contain digits only. Got: %s',
1197
                static::valueToString($value)
1198
            ));
1199
        }
1200
    }
1201
1202
    /**
1203
     * @param mixed  $value
@@ 1208-1221 (lines=14) @@
1205
     *
1206
     * @throws InvalidArgumentException
1207
     */
1208
    public static function alnum($value, $message = '')
1209
    {
1210
        $locale = \setlocale(LC_CTYPE, 0);
1211
        \setlocale(LC_CTYPE, 'C');
1212
        $valid = !\ctype_alnum($value);
1213
        \setlocale(LC_CTYPE, $locale);
1214
1215
        if ($valid) {
1216
            static::reportInvalidArgument(\sprintf(
1217
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1218
                static::valueToString($value)
1219
            ));
1220
        }
1221
    }
1222
1223
    /**
1224
     * @param mixed  $value
@@ 1229-1242 (lines=14) @@
1226
     *
1227
     * @throws InvalidArgumentException
1228
     */
1229
    public static function lower($value, $message = '')
1230
    {
1231
        $locale = \setlocale(LC_CTYPE, 0);
1232
        \setlocale(LC_CTYPE, 'C');
1233
        $valid = !\ctype_lower($value);
1234
        \setlocale(LC_CTYPE, $locale);
1235
1236
        if ($valid) {
1237
            static::reportInvalidArgument(\sprintf(
1238
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1239
                static::valueToString($value)
1240
            ));
1241
        }
1242
    }
1243
1244
    /**
1245
     * @param mixed  $value
@@ 1250-1263 (lines=14) @@
1247
     *
1248
     * @throws InvalidArgumentException
1249
     */
1250
    public static function upper($value, $message = '')
1251
    {
1252
        $locale = \setlocale(LC_CTYPE, 0);
1253
        \setlocale(LC_CTYPE, 'C');
1254
        $valid = !\ctype_upper($value);
1255
        \setlocale(LC_CTYPE, $locale);
1256
1257
        if ($valid) {
1258
            static::reportInvalidArgument(\sprintf(
1259
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1260
                static::valueToString($value)
1261
            ));
1262
        }
1263
    }
1264
1265
    /**
1266
     * @param mixed  $value