Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

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