Code Duplication    Length = 16-16 lines in 5 locations

src/Assert.php 5 locations

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