Code Duplication    Length = 14-16 lines in 5 locations

src/Assert.php 5 locations

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