Complex classes like Assertion often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Assertion, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
154 | class Assertion |
||
155 | { |
||
156 | const INVALID_FLOAT = 9; |
||
157 | const INVALID_INTEGER = 10; |
||
158 | const INVALID_DIGIT = 11; |
||
159 | const INVALID_INTEGERISH = 12; |
||
160 | const INVALID_BOOLEAN = 13; |
||
161 | const VALUE_EMPTY = 14; |
||
162 | const VALUE_NULL = 15; |
||
163 | const INVALID_STRING = 16; |
||
164 | const INVALID_REGEX = 17; |
||
165 | const INVALID_MIN_LENGTH = 18; |
||
166 | const INVALID_MAX_LENGTH = 19; |
||
167 | const INVALID_STRING_START = 20; |
||
168 | const INVALID_STRING_CONTAINS = 21; |
||
169 | const INVALID_CHOICE = 22; |
||
170 | const INVALID_NUMERIC = 23; |
||
171 | const INVALID_ARRAY = 24; |
||
172 | const INVALID_KEY_EXISTS = 26; |
||
173 | const INVALID_NOT_BLANK = 27; |
||
174 | const INVALID_INSTANCE_OF = 28; |
||
175 | const INVALID_SUBCLASS_OF = 29; |
||
176 | const INVALID_RANGE = 30; |
||
177 | const INVALID_ALNUM = 31; |
||
178 | const INVALID_TRUE = 32; |
||
179 | const INVALID_EQ = 33; |
||
180 | const INVALID_SAME = 34; |
||
181 | const INVALID_MIN = 35; |
||
182 | const INVALID_MAX = 36; |
||
183 | const INVALID_LENGTH = 37; |
||
184 | const INVALID_FALSE = 38; |
||
185 | const INVALID_STRING_END = 39; |
||
186 | const INVALID_UUID = 40; |
||
187 | const INVALID_COUNT = 41; |
||
188 | const INVALID_NOT_EQ = 42; |
||
189 | const INVALID_NOT_SAME = 43; |
||
190 | const INVALID_TRAVERSABLE = 44; |
||
191 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
192 | const INVALID_KEY_ISSET = 46; |
||
193 | const INVALID_VALUE_IN_ARRAY = 47; |
||
194 | const INVALID_DIRECTORY = 101; |
||
195 | const INVALID_FILE = 102; |
||
196 | const INVALID_READABLE = 103; |
||
197 | const INVALID_WRITEABLE = 104; |
||
198 | const INVALID_CLASS = 105; |
||
199 | const INVALID_INTERFACE = 106; |
||
200 | const INVALID_EMAIL = 201; |
||
201 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
202 | const INVALID_URL = 203; |
||
203 | const INVALID_NOT_INSTANCE_OF = 204; |
||
204 | const VALUE_NOT_EMPTY = 205; |
||
205 | const INVALID_JSON_STRING = 206; |
||
206 | const INVALID_OBJECT = 207; |
||
207 | const INVALID_METHOD = 208; |
||
208 | const INVALID_SCALAR = 209; |
||
209 | const INVALID_LESS = 210; |
||
210 | const INVALID_LESS_OR_EQUAL = 211; |
||
211 | const INVALID_GREATER = 212; |
||
212 | const INVALID_GREATER_OR_EQUAL = 213; |
||
213 | const INVALID_DATE = 214; |
||
214 | const INVALID_CALLABLE = 215; |
||
215 | const INVALID_KEY_NOT_EXISTS = 216; |
||
216 | const INVALID_SATISFY = 217; |
||
217 | |||
218 | /** |
||
219 | * Exception to throw when an assertion failed. |
||
220 | * |
||
221 | * @var string |
||
222 | */ |
||
223 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
224 | |||
225 | /** |
||
226 | * Helper method that handles building the assertion failure exceptions. |
||
227 | * They are returned from this method so that the stack trace still shows |
||
228 | * the assertions method. |
||
229 | */ |
||
230 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
235 | |||
236 | /** |
||
237 | * Assert that two values are equal (using == ). |
||
238 | * |
||
239 | * @param mixed $value |
||
240 | * @param mixed $value2 |
||
241 | * @param string|null $message |
||
242 | * @param string|null $propertyPath |
||
243 | * @return void |
||
244 | * @throws \Assert\AssertionFailedException |
||
245 | */ |
||
246 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
258 | |||
259 | /** |
||
260 | * Assert that two values are the same (using ===). |
||
261 | * |
||
262 | * @param mixed $value |
||
263 | * @param mixed $value2 |
||
264 | * @param string|null $message |
||
265 | * @param string|null $propertyPath |
||
266 | * @return void |
||
267 | * @throws \Assert\AssertionFailedException |
||
268 | */ |
||
269 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
281 | |||
282 | /** |
||
283 | * Assert that two values are not equal (using == ). |
||
284 | * |
||
285 | * @param mixed $value1 |
||
286 | * @param mixed $value2 |
||
287 | * @param string|null $message |
||
288 | * @param string|null $propertyPath |
||
289 | * @return void |
||
290 | * @throws \Assert\AssertionFailedException |
||
291 | */ |
||
292 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
303 | |||
304 | /** |
||
305 | * Assert that two values are not the same (using === ). |
||
306 | * |
||
307 | * @param mixed $value1 |
||
308 | * @param mixed $value2 |
||
309 | * @param string|null $message |
||
310 | * @param string|null $propertyPath |
||
311 | * @return void |
||
312 | * @throws \Assert\AssertionFailedException |
||
313 | */ |
||
314 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
325 | |||
326 | /** |
||
327 | * Assert that value is not in array of choices. |
||
328 | * |
||
329 | * @param mixed $value |
||
330 | * @param array $choices |
||
331 | * @param string|null $message |
||
332 | * @param string|null $propertyPath |
||
333 | * @return void |
||
334 | * @throws \Assert\AssertionFailedException |
||
335 | */ |
||
336 | public static function notInArray($value, array $choices, $message = null, $propertyPath = null) |
||
347 | |||
348 | /** |
||
349 | * Assert that value is a php integer. |
||
350 | * |
||
351 | * @param mixed $value |
||
352 | * @param string|null $message |
||
353 | * @param string|null $propertyPath |
||
354 | * @return void |
||
355 | * @throws \Assert\AssertionFailedException |
||
356 | */ |
||
357 | public static function integer($value, $message = null, $propertyPath = null) |
||
368 | |||
369 | /** |
||
370 | * Assert that value is a php float. |
||
371 | * |
||
372 | * @param mixed $value |
||
373 | * @param string|null $message |
||
374 | * @param string|null $propertyPath |
||
375 | * @return void |
||
376 | * @throws \Assert\AssertionFailedException |
||
377 | */ |
||
378 | public static function float($value, $message = null, $propertyPath = null) |
||
389 | |||
390 | /** |
||
391 | * Validates if an integer or integerish is a digit. |
||
392 | * |
||
393 | * @param mixed $value |
||
394 | * @param string|null $message |
||
395 | * @param string|null $propertyPath |
||
396 | * @return void |
||
397 | * @throws \Assert\AssertionFailedException |
||
398 | */ |
||
399 | public static function digit($value, $message = null, $propertyPath = null) |
||
410 | |||
411 | /** |
||
412 | * Assert that value is a php integer'ish. |
||
413 | * |
||
414 | * @param mixed $value |
||
415 | * @param string|null $message |
||
416 | * @param string|null $propertyPath |
||
417 | * @return void |
||
418 | * @throws \Assert\AssertionFailedException |
||
419 | */ |
||
420 | public static function integerish($value, $message = null, $propertyPath = null) |
||
431 | |||
432 | /** |
||
433 | * Assert that value is php boolean |
||
434 | * |
||
435 | * @param mixed $value |
||
436 | * @param string|null $message |
||
437 | * @param string|null $propertyPath |
||
438 | * @return void |
||
439 | * @throws \Assert\AssertionFailedException |
||
440 | */ |
||
441 | public static function boolean($value, $message = null, $propertyPath = null) |
||
452 | |||
453 | /** |
||
454 | * Assert that value is a PHP scalar |
||
455 | * |
||
456 | * @param mixed $value |
||
457 | * @param string|null $message |
||
458 | * @param string|null $propertyPath |
||
459 | * @return void |
||
460 | * @throws \Assert\AssertionFailedException |
||
461 | */ |
||
462 | public static function scalar($value, $message = null, $propertyPath = null) |
||
473 | |||
474 | /** |
||
475 | * Assert that value is not empty |
||
476 | * |
||
477 | * @param mixed $value |
||
478 | * @param string|null $message |
||
479 | * @param string|null $propertyPath |
||
480 | * @return void |
||
481 | * @throws \Assert\AssertionFailedException |
||
482 | */ |
||
483 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
494 | |||
495 | /** |
||
496 | * Assert that value is empty |
||
497 | * |
||
498 | * @param mixed $value |
||
499 | * @param string|null $message |
||
500 | * @param string|null $propertyPath |
||
501 | * @return void |
||
502 | * @throws \Assert\AssertionFailedException |
||
503 | */ |
||
504 | public static function noContent($value, $message = null, $propertyPath = null) |
||
515 | |||
516 | /** |
||
517 | * Assert that value is not null |
||
518 | * |
||
519 | * @param mixed $value |
||
520 | * @param string|null $message |
||
521 | * @param string|null $propertyPath |
||
522 | * @return void |
||
523 | * @throws \Assert\AssertionFailedException |
||
524 | */ |
||
525 | public static function notNull($value, $message = null, $propertyPath = null) |
||
536 | |||
537 | /** |
||
538 | * Assert that value is a string |
||
539 | * |
||
540 | * @param mixed $value |
||
541 | * @param string|null $message |
||
542 | * @param string|null $propertyPath |
||
543 | * @return void |
||
544 | * @throws \Assert\AssertionFailedException |
||
545 | */ |
||
546 | public static function string($value, $message = null, $propertyPath = null) |
||
558 | |||
559 | /** |
||
560 | * Assert that value matches a regex |
||
561 | * |
||
562 | * @param mixed $value |
||
563 | * @param string $pattern |
||
564 | * @param string|null $message |
||
565 | * @param string|null $propertyPath |
||
566 | * @return void |
||
567 | * @throws \Assert\AssertionFailedException |
||
568 | */ |
||
569 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
582 | |||
583 | /** |
||
584 | * Assert that string has a given length. |
||
585 | * |
||
586 | * @param mixed $value |
||
587 | * @param int $length |
||
588 | * @param string|null $message |
||
589 | * @param string|null $propertyPath |
||
590 | * @param string $encoding |
||
591 | * @return void |
||
592 | * @throws \Assert\AssertionFailedException |
||
593 | */ |
||
594 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
610 | |||
611 | /** |
||
612 | * Assert that a string is at least $minLength chars long. |
||
613 | * |
||
614 | * @param mixed $value |
||
615 | * @param int $minLength |
||
616 | * @param string|null $message |
||
617 | * @param string|null $propertyPath |
||
618 | * @param string $encoding |
||
619 | * @return void |
||
620 | * @throws \Assert\AssertionFailedException |
||
621 | */ |
||
622 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
638 | |||
639 | /** |
||
640 | * Assert that string value is not longer than $maxLength chars. |
||
641 | * |
||
642 | * @param mixed $value |
||
643 | * @param integer $maxLength |
||
644 | * @param string|null $message |
||
645 | * @param string|null $propertyPath |
||
646 | * @param string $encoding |
||
647 | * @return void |
||
648 | * @throws \Assert\AssertionFailedException |
||
649 | */ |
||
650 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
666 | |||
667 | /** |
||
668 | * Assert that string length is between min,max lengths. |
||
669 | * |
||
670 | * @param mixed $value |
||
671 | * @param integer $minLength |
||
672 | * @param integer $maxLength |
||
673 | * @param string|null $message |
||
674 | * @param string|null $propertyPath |
||
675 | * @param string $encoding |
||
676 | * @return void |
||
677 | * @throws \Assert\AssertionFailedException |
||
678 | */ |
||
679 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
707 | |||
708 | /** |
||
709 | * Assert that string starts with a sequence of chars. |
||
710 | * |
||
711 | * @param mixed $string |
||
712 | * @param string $needle |
||
713 | * @param string|null $message |
||
714 | * @param string|null $propertyPath |
||
715 | * @param string $encoding |
||
716 | * @return void |
||
717 | * @throws \Assert\AssertionFailedException |
||
718 | */ |
||
719 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
734 | |||
735 | /** |
||
736 | * Assert that string ends with a sequence of chars. |
||
737 | * |
||
738 | * @param mixed $string |
||
739 | * @param string $needle |
||
740 | * @param string|null $message |
||
741 | * @param string|null $propertyPath |
||
742 | * @param string $encoding |
||
743 | * @return void |
||
744 | * @throws \Assert\AssertionFailedException |
||
745 | */ |
||
746 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
763 | |||
764 | /** |
||
765 | * Assert that string contains a sequence of chars. |
||
766 | * |
||
767 | * @param mixed $string |
||
768 | * @param string $needle |
||
769 | * @param string|null $message |
||
770 | * @param string|null $propertyPath |
||
771 | * @param string $encoding |
||
772 | * @return void |
||
773 | * @throws \Assert\AssertionFailedException |
||
774 | */ |
||
775 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
790 | |||
791 | /** |
||
792 | * Assert that value is in array of choices. |
||
793 | * |
||
794 | * @param mixed $value |
||
795 | * @param array $choices |
||
796 | * @param string|null $message |
||
797 | * @param string|null $propertyPath |
||
798 | * @return void |
||
799 | * @throws \Assert\AssertionFailedException |
||
800 | */ |
||
801 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
813 | |||
814 | /** |
||
815 | * Alias of {@see choice()} |
||
816 | * |
||
817 | * @throws \Assert\AssertionFailedException |
||
818 | */ |
||
819 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
823 | |||
824 | /** |
||
825 | * Assert that value is numeric. |
||
826 | * |
||
827 | * @param mixed $value |
||
828 | * @param string|null $message |
||
829 | * @param string|null $propertyPath |
||
830 | * @return void |
||
831 | * @throws \Assert\AssertionFailedException |
||
832 | */ |
||
833 | public static function numeric($value, $message = null, $propertyPath = null) |
||
844 | |||
845 | /** |
||
846 | * Assert that value is an array. |
||
847 | * |
||
848 | * @param mixed $value |
||
849 | * @param string|null $message |
||
850 | * @param string|null $propertyPath |
||
851 | * @return void |
||
852 | * @throws \Assert\AssertionFailedException |
||
853 | */ |
||
854 | public static function isArray($value, $message = null, $propertyPath = null) |
||
865 | |||
866 | /** |
||
867 | * Assert that value is an array or a traversable object. |
||
868 | * |
||
869 | * @param mixed $value |
||
870 | * @param string|null $message |
||
871 | * @param string|null $propertyPath |
||
872 | * @return void |
||
873 | * @throws \Assert\AssertionFailedException |
||
874 | */ |
||
875 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
886 | |||
887 | /** |
||
888 | * Assert that value is an array or an array-accessible object. |
||
889 | * |
||
890 | * @param mixed $value |
||
891 | * @param string|null $message |
||
892 | * @param string|null $propertyPath |
||
893 | * @return void |
||
894 | * @throws \Assert\AssertionFailedException |
||
895 | */ |
||
896 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
907 | |||
908 | /** |
||
909 | * Assert that key exists in an array |
||
910 | * |
||
911 | * @param mixed $value |
||
912 | * @param string|integer $key |
||
913 | * @param string|null $message |
||
914 | * @param string|null $propertyPath |
||
915 | * @return void |
||
916 | * @throws \Assert\AssertionFailedException |
||
917 | */ |
||
918 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
931 | |||
932 | /** |
||
933 | * Assert that key does not exist in an array |
||
934 | * |
||
935 | * @param mixed $value |
||
936 | * @param string|integer $key |
||
937 | * @param string|null $message |
||
938 | * @param string|null $propertyPath |
||
939 | * @return void |
||
940 | * @throws \Assert\AssertionFailedException |
||
941 | */ |
||
942 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null) |
||
955 | |||
956 | /** |
||
957 | * Assert that key exists in an array/array-accessible object using isset() |
||
958 | * |
||
959 | * @param mixed $value |
||
960 | * @param string|integer $key |
||
961 | * @param string|null $message |
||
962 | * @param string|null $propertyPath |
||
963 | * @return void |
||
964 | * @throws \Assert\AssertionFailedException |
||
965 | */ |
||
966 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
979 | |||
980 | /** |
||
981 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
982 | * |
||
983 | * @param mixed $value |
||
984 | * @param string|integer $key |
||
985 | * @param string|null $message |
||
986 | * @param string|null $propertyPath |
||
987 | * @return void |
||
988 | * @throws \Assert\AssertionFailedException |
||
989 | */ |
||
990 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
995 | |||
996 | /** |
||
997 | * Assert that value is not blank |
||
998 | * |
||
999 | * @param mixed $value |
||
1000 | * @param string|null $message |
||
1001 | * @param string|null $propertyPath |
||
1002 | * @return void |
||
1003 | * @throws \Assert\AssertionFailedException |
||
1004 | */ |
||
1005 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
1016 | |||
1017 | /** |
||
1018 | * Assert that value is instance of given class-name. |
||
1019 | * |
||
1020 | * @param mixed $value |
||
1021 | * @param string $className |
||
1022 | * @param string|null $message |
||
1023 | * @param string|null $propertyPath |
||
1024 | * @return void |
||
1025 | * @throws \Assert\AssertionFailedException |
||
1026 | */ |
||
1027 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1039 | |||
1040 | /** |
||
1041 | * Assert that value is not instance of given class-name. |
||
1042 | * |
||
1043 | * @param mixed $value |
||
1044 | * @param string $className |
||
1045 | * @param string|null $message |
||
1046 | * @param string|null $propertyPath |
||
1047 | * @return void |
||
1048 | * @throws \Assert\AssertionFailedException |
||
1049 | */ |
||
1050 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1062 | |||
1063 | /** |
||
1064 | * Assert that value is subclass of given class-name. |
||
1065 | * |
||
1066 | * @param mixed $value |
||
1067 | * @param string $className |
||
1068 | * @param string|null $message |
||
1069 | * @param string|null $propertyPath |
||
1070 | * @return void |
||
1071 | * @throws \Assert\AssertionFailedException |
||
1072 | */ |
||
1073 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
1085 | |||
1086 | /** |
||
1087 | * Assert that value is in range of numbers. |
||
1088 | * |
||
1089 | * @param mixed $value |
||
1090 | * @param integer $minValue |
||
1091 | * @param integer $maxValue |
||
1092 | * @param string|null $message |
||
1093 | * @param string|null $propertyPath |
||
1094 | * @return void |
||
1095 | * @throws \Assert\AssertionFailedException |
||
1096 | */ |
||
1097 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
1112 | |||
1113 | /** |
||
1114 | * Assert that a value is at least as big as a given limit |
||
1115 | * |
||
1116 | * @param mixed $value |
||
1117 | * @param mixed $minValue |
||
1118 | * @param string|null $message |
||
1119 | * @param string|null $propertyPath |
||
1120 | * @return void |
||
1121 | * @throws \Assert\AssertionFailedException |
||
1122 | */ |
||
1123 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
1137 | |||
1138 | /** |
||
1139 | * Assert that a number is smaller as a given limit |
||
1140 | * |
||
1141 | * @param mixed $value |
||
1142 | * @param mixed $maxValue |
||
1143 | * @param string|null $message |
||
1144 | * @param string|null $propertyPath |
||
1145 | * @return void |
||
1146 | * @throws \Assert\AssertionFailedException |
||
1147 | */ |
||
1148 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
1162 | |||
1163 | /** |
||
1164 | * Assert that a file exists |
||
1165 | * |
||
1166 | * @param string $value |
||
1167 | * @param string|null $message |
||
1168 | * @param string|null $propertyPath |
||
1169 | * @return void |
||
1170 | * @throws \Assert\AssertionFailedException |
||
1171 | */ |
||
1172 | public static function file($value, $message = null, $propertyPath = null) |
||
1186 | |||
1187 | /** |
||
1188 | * Assert that a directory exists |
||
1189 | * |
||
1190 | * @param string $value |
||
1191 | * @param string|null $message |
||
1192 | * @param string|null $propertyPath |
||
1193 | * @return void |
||
1194 | * @throws \Assert\AssertionFailedException |
||
1195 | */ |
||
1196 | public static function directory($value, $message = null, $propertyPath = null) |
||
1209 | |||
1210 | /** |
||
1211 | * Assert that the value is something readable |
||
1212 | * |
||
1213 | * @param string $value |
||
1214 | * @param string|null $message |
||
1215 | * @param string|null $propertyPath |
||
1216 | * @return void |
||
1217 | * @throws \Assert\AssertionFailedException |
||
1218 | */ |
||
1219 | public static function readable($value, $message = null, $propertyPath = null) |
||
1232 | |||
1233 | /** |
||
1234 | * Assert that the value is something writeable |
||
1235 | * |
||
1236 | * @param string $value |
||
1237 | * @param string|null $message |
||
1238 | * @param string|null $propertyPath |
||
1239 | * @return void |
||
1240 | * @throws \Assert\AssertionFailedException |
||
1241 | */ |
||
1242 | public static function writeable($value, $message = null, $propertyPath = null) |
||
1255 | |||
1256 | /** |
||
1257 | * Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL). |
||
1258 | * |
||
1259 | * @param mixed $value |
||
1260 | * @param string|null $message |
||
1261 | * @param string|null $propertyPath |
||
1262 | * @return void |
||
1263 | * @throws \Assert\AssertionFailedException |
||
1264 | */ |
||
1265 | public static function email($value, $message = null, $propertyPath = null) |
||
1290 | |||
1291 | /** |
||
1292 | * Assert that value is an URL. |
||
1293 | * |
||
1294 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
1295 | * |
||
1296 | * @param mixed $value |
||
1297 | * @param string|null $message |
||
1298 | * @param string|null $propertyPath |
||
1299 | * @return void |
||
1300 | * @throws \Assert\AssertionFailedException |
||
1301 | * |
||
1302 | * |
||
1303 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
1304 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
1305 | */ |
||
1306 | public static function url($value, $message = null, $propertyPath = null) |
||
1339 | |||
1340 | /** |
||
1341 | * Assert that value is alphanumeric. |
||
1342 | * |
||
1343 | * @param mixed $value |
||
1344 | * @param string|null $message |
||
1345 | * @param string|null $propertyPath |
||
1346 | * @return void |
||
1347 | * @throws \Assert\AssertionFailedException |
||
1348 | */ |
||
1349 | public static function alnum($value, $message = null, $propertyPath = null) |
||
1362 | |||
1363 | /** |
||
1364 | * Assert that the value is boolean True. |
||
1365 | * |
||
1366 | * @param mixed $value |
||
1367 | * @param string|null $message |
||
1368 | * @param string|null $propertyPath |
||
1369 | * @return void |
||
1370 | * @throws \Assert\AssertionFailedException |
||
1371 | */ |
||
1372 | public static function true($value, $message = null, $propertyPath = null) |
||
1383 | |||
1384 | /** |
||
1385 | * Assert that the value is boolean False. |
||
1386 | * |
||
1387 | * @param mixed $value |
||
1388 | * @param string|null $message |
||
1389 | * @param string|null $propertyPath |
||
1390 | * @return void |
||
1391 | * @throws \Assert\AssertionFailedException |
||
1392 | */ |
||
1393 | public static function false($value, $message = null, $propertyPath = null) |
||
1404 | |||
1405 | /** |
||
1406 | * Assert that the class exists. |
||
1407 | * |
||
1408 | * @param mixed $value |
||
1409 | * @param string|null $message |
||
1410 | * @param string|null $propertyPath |
||
1411 | * @return void |
||
1412 | * @throws \Assert\AssertionFailedException |
||
1413 | */ |
||
1414 | public static function classExists($value, $message = null, $propertyPath = null) |
||
1425 | |||
1426 | /** |
||
1427 | * Assert that the interface exists. |
||
1428 | * |
||
1429 | * @param mixed $value |
||
1430 | * @param string|null $message |
||
1431 | * @param string|null $propertyPath |
||
1432 | * @return void |
||
1433 | * @throws \Assert\AssertionFailedException |
||
1434 | */ |
||
1435 | public static function interfaceExists($value, $message = null, $propertyPath = null) |
||
1446 | |||
1447 | /** |
||
1448 | * Assert that the class implements the interface |
||
1449 | * |
||
1450 | * @param mixed $class |
||
1451 | * @param string $interfaceName |
||
1452 | * @param string|null $message |
||
1453 | * @param string|null $propertyPath |
||
1454 | * @return void |
||
1455 | * @throws \Assert\AssertionFailedException |
||
1456 | */ |
||
1457 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
1470 | |||
1471 | /** |
||
1472 | * Assert that the given string is a valid json string. |
||
1473 | * |
||
1474 | * NOTICE: |
||
1475 | * Since this does a json_decode to determine its validity |
||
1476 | * you probably should consider, when using the variable |
||
1477 | * content afterwards, just to decode and check for yourself instead |
||
1478 | * of using this assertion. |
||
1479 | * |
||
1480 | * @param mixed $value |
||
1481 | * @param string|null $message |
||
1482 | * @param string|null $propertyPath |
||
1483 | * @return void |
||
1484 | * @throws \Assert\AssertionFailedException |
||
1485 | */ |
||
1486 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
1497 | |||
1498 | /** |
||
1499 | * Assert that the given string is a valid UUID |
||
1500 | * |
||
1501 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
1502 | * |
||
1503 | * @param string $value |
||
1504 | * @param string|null $message |
||
1505 | * @param string|null $propertyPath |
||
1506 | * @return void |
||
1507 | * @throws \Assert\AssertionFailedException |
||
1508 | */ |
||
1509 | public static function uuid($value, $message = null, $propertyPath = null) |
||
1526 | |||
1527 | /** |
||
1528 | * Assert that the count of countable is equal to count. |
||
1529 | * |
||
1530 | * @param array|\Countable $countable |
||
1531 | * @param int $count |
||
1532 | * @param string $message |
||
1533 | * @param string $propertyPath |
||
1534 | * @return void |
||
1535 | * @throws \Assert\AssertionFailedException |
||
1536 | */ |
||
1537 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
1548 | |||
1549 | /** |
||
1550 | * static call handler to implement: |
||
1551 | * - "null or assertion" delegation |
||
1552 | * - "all" delegation |
||
1553 | */ |
||
1554 | public static function __callStatic($method, $args) |
||
1590 | |||
1591 | /** |
||
1592 | * Determines if the values array has every choice as key and that this choice has content. |
||
1593 | * |
||
1594 | * @param array $values |
||
1595 | * @param array $choices |
||
1596 | * @param null $message |
||
1597 | * @param null $propertyPath |
||
1598 | */ |
||
1599 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
1608 | |||
1609 | /** |
||
1610 | * Determines that the named method is defined in the provided object. |
||
1611 | * |
||
1612 | * @param string $value |
||
1613 | * @param mixed $object |
||
1614 | * @param null $message |
||
1615 | * @param null $propertyPath |
||
1616 | * |
||
1617 | * @throws |
||
1618 | */ |
||
1619 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
1632 | |||
1633 | /** |
||
1634 | * Determines that the provided value is an object. |
||
1635 | * |
||
1636 | * @param mixed $value |
||
1637 | * @param null $message |
||
1638 | * @param null $propertyPath |
||
1639 | */ |
||
1640 | public static function isObject($value, $message = null, $propertyPath = null) |
||
1652 | |||
1653 | /** |
||
1654 | * Determines if the value is less than given limit. |
||
1655 | * |
||
1656 | * @param mixed $value |
||
1657 | * @param mixed $limit |
||
1658 | * @param null $message |
||
1659 | * @param null $propertyPath |
||
1660 | */ |
||
1661 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
1673 | |||
1674 | /** |
||
1675 | * Determines if the value is less or than given limit. |
||
1676 | * |
||
1677 | * @param mixed $value |
||
1678 | * @param mixed $limit |
||
1679 | * @param null $message |
||
1680 | * @param null $propertyPath |
||
1681 | */ |
||
1682 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1694 | |||
1695 | /** |
||
1696 | * Determines if the value is greater than given limit. |
||
1697 | * |
||
1698 | * @param mixed $value |
||
1699 | * @param mixed $limit |
||
1700 | * @param null $message |
||
1701 | * @param null $propertyPath |
||
1702 | */ |
||
1703 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
1715 | |||
1716 | /** |
||
1717 | * Determines if the value is greater or equal than given limit. |
||
1718 | * |
||
1719 | * @param mixed $value |
||
1720 | * @param mixed $limit |
||
1721 | * @param null $message |
||
1722 | * @param null $propertyPath |
||
1723 | */ |
||
1724 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1736 | |||
1737 | /** |
||
1738 | * Assert that date is valid and corresponds to the given format. |
||
1739 | * |
||
1740 | * @param string $value |
||
1741 | * @param string $format supports all of the options date(), except for the following: |
||
1742 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
1743 | * @param string|null $message |
||
1744 | * @param string|null $propertyPath |
||
1745 | * |
||
1746 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
1747 | */ |
||
1748 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
1765 | |||
1766 | /** |
||
1767 | * Determines that the provided value is callable. |
||
1768 | * |
||
1769 | * @param mixed $value |
||
1770 | * @param null $message |
||
1771 | * @param null $propertyPath |
||
1772 | */ |
||
1773 | public static function isCallable($value, $message = null, $propertyPath = null) |
||
1784 | |||
1785 | /** |
||
1786 | * Assert that the provided value is valid according to a callback. |
||
1787 | * |
||
1788 | * If the callback returns `false` the assertion will fail. |
||
1789 | * |
||
1790 | * @param mixed $value |
||
1791 | * @param callable $callback |
||
1792 | * @param string|null $message |
||
1793 | * @param string|null $propertyPath |
||
1794 | */ |
||
1795 | public static function satisfy($value, $callback, $message = null, $propertyPath = null) |
||
1808 | |||
1809 | /** |
||
1810 | * Make a string version of a value. |
||
1811 | * |
||
1812 | * @param mixed $value |
||
1813 | * @return string |
||
1814 | */ |
||
1815 | protected static function stringify($value) |
||
1849 | } |
||
1850 | |||
1851 |