Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

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