Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

@@ 1169-1184 (lines=16) @@
1166
     *
1167
     * @throws InvalidArgumentException
1168
     */
1169
    public static function alpha($value, $message = '')
1170
    {
1171
        static::string($value);
1172
1173
        $locale = \setlocale(LC_CTYPE, 0);
1174
        \setlocale(LC_CTYPE, 'C');
1175
        $valid = !\ctype_alpha($value);
1176
        \setlocale(LC_CTYPE, $locale);
1177
1178
        if ($valid) {
1179
            static::reportInvalidArgument(\sprintf(
1180
                $message ?: 'Expected a value to contain only letters. Got: %s',
1181
                static::valueToString($value)
1182
            ));
1183
        }
1184
    }
1185
1186
    /**
1187
     * @param mixed  $value
@@ 1192-1205 (lines=14) @@
1189
     *
1190
     * @throws InvalidArgumentException
1191
     */
1192
    public static function digits($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-1226 (lines=14) @@
1210
     *
1211
     * @throws InvalidArgumentException
1212
     */
1213
    public static function alnum($value, $message = '')
1214
    {
1215
        $locale = \setlocale(LC_CTYPE, 0);
1216
        \setlocale(LC_CTYPE, 'C');
1217
        $valid = !\ctype_alnum($value);
1218
        \setlocale(LC_CTYPE, $locale);
1219
1220
        if ($valid) {
1221
            static::reportInvalidArgument(\sprintf(
1222
                $message ?: 'Expected a value to contain letters and digits only. Got: %s',
1223
                static::valueToString($value)
1224
            ));
1225
        }
1226
    }
1227
1228
    /**
1229
     * @param mixed  $value
@@ 1234-1247 (lines=14) @@
1231
     *
1232
     * @throws InvalidArgumentException
1233
     */
1234
    public static function lower($value, $message = '')
1235
    {
1236
        $locale = \setlocale(LC_CTYPE, 0);
1237
        \setlocale(LC_CTYPE, 'C');
1238
        $valid = !\ctype_lower($value);
1239
        \setlocale(LC_CTYPE, $locale);
1240
1241
        if ($valid) {
1242
            static::reportInvalidArgument(\sprintf(
1243
                $message ?: 'Expected a value to contain lowercase characters only. Got: %s',
1244
                static::valueToString($value)
1245
            ));
1246
        }
1247
    }
1248
1249
    /**
1250
     * @param mixed  $value
@@ 1255-1268 (lines=14) @@
1252
     *
1253
     * @throws InvalidArgumentException
1254
     */
1255
    public static function upper($value, $message = '')
1256
    {
1257
        $locale = \setlocale(LC_CTYPE, 0);
1258
        \setlocale(LC_CTYPE, 'C');
1259
        $valid = !\ctype_upper($value);
1260
        \setlocale(LC_CTYPE, $locale);
1261
1262
        if ($valid) {
1263
            static::reportInvalidArgument(\sprintf(
1264
                $message ?: 'Expected a value to contain uppercase characters only. Got: %s',
1265
                static::valueToString($value)
1266
            ));
1267
        }
1268
    }
1269
1270
    /**
1271
     * @param mixed  $value