Code Duplication    Length = 14-14 lines in 5 locations

src/Assert.php 5 locations

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