Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

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