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 |
||
149 | class Assertion |
||
150 | { |
||
151 | const INVALID_FLOAT = 9; |
||
152 | const INVALID_INTEGER = 10; |
||
153 | const INVALID_DIGIT = 11; |
||
154 | const INVALID_INTEGERISH = 12; |
||
155 | const INVALID_BOOLEAN = 13; |
||
156 | const VALUE_EMPTY = 14; |
||
157 | const VALUE_NULL = 15; |
||
158 | const INVALID_STRING = 16; |
||
159 | const INVALID_REGEX = 17; |
||
160 | const INVALID_MIN_LENGTH = 18; |
||
161 | const INVALID_MAX_LENGTH = 19; |
||
162 | const INVALID_STRING_START = 20; |
||
163 | const INVALID_STRING_CONTAINS = 21; |
||
164 | const INVALID_CHOICE = 22; |
||
165 | const INVALID_NUMERIC = 23; |
||
166 | const INVALID_ARRAY = 24; |
||
167 | const INVALID_KEY_EXISTS = 26; |
||
168 | const INVALID_NOT_BLANK = 27; |
||
169 | const INVALID_INSTANCE_OF = 28; |
||
170 | const INVALID_SUBCLASS_OF = 29; |
||
171 | const INVALID_RANGE = 30; |
||
172 | const INVALID_ALNUM = 31; |
||
173 | const INVALID_TRUE = 32; |
||
174 | const INVALID_EQ = 33; |
||
175 | const INVALID_SAME = 34; |
||
176 | const INVALID_MIN = 35; |
||
177 | const INVALID_MAX = 36; |
||
178 | const INVALID_LENGTH = 37; |
||
179 | const INVALID_FALSE = 38; |
||
180 | const INVALID_STRING_END = 39; |
||
181 | const INVALID_UUID = 40; |
||
182 | const INVALID_COUNT = 41; |
||
183 | const INVALID_NOT_EQ = 42; |
||
184 | const INVALID_NOT_SAME = 43; |
||
185 | const INVALID_TRAVERSABLE = 44; |
||
186 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
187 | const INVALID_KEY_ISSET = 46; |
||
188 | const INVALID_VALUE_IN_ARRAY = 47; |
||
189 | const INVALID_DIRECTORY = 101; |
||
190 | const INVALID_FILE = 102; |
||
191 | const INVALID_READABLE = 103; |
||
192 | const INVALID_WRITEABLE = 104; |
||
193 | const INVALID_CLASS = 105; |
||
194 | const INVALID_EMAIL = 201; |
||
195 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
196 | const INVALID_URL = 203; |
||
197 | const INVALID_NOT_INSTANCE_OF = 204; |
||
198 | const VALUE_NOT_EMPTY = 205; |
||
199 | const INVALID_JSON_STRING = 206; |
||
200 | const INVALID_OBJECT = 207; |
||
201 | const INVALID_METHOD = 208; |
||
202 | const INVALID_SCALAR = 209; |
||
203 | const INVALID_LESS = 210; |
||
204 | const INVALID_LESS_OR_EQUAL = 211; |
||
205 | const INVALID_GREATER = 212; |
||
206 | const INVALID_GREATER_OR_EQUAL = 213; |
||
207 | const INVALID_DATE = 214; |
||
208 | const INVALID_CALLABLE = 215; |
||
209 | const INVALID_KEY_NOT_EXISTS = 216; |
||
210 | |||
211 | /** |
||
212 | * Exception to throw when an assertion failed. |
||
213 | * |
||
214 | * @var string |
||
215 | */ |
||
216 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
217 | |||
218 | /** |
||
219 | * Helper method that handles building the assertion failure exceptions. |
||
220 | * They are returned from this method so that the stack trace still shows |
||
221 | * the assertions method. |
||
222 | */ |
||
223 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
228 | |||
229 | /** |
||
230 | * Assert that two values are equal (using == ). |
||
231 | * |
||
232 | * @param mixed $value |
||
233 | * @param mixed $value2 |
||
234 | * @param string|null $message |
||
235 | * @param string|null $propertyPath |
||
236 | * @return void |
||
237 | * @throws \Assert\AssertionFailedException |
||
238 | */ |
||
239 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
251 | |||
252 | /** |
||
253 | * Assert that two values are the same (using ===). |
||
254 | * |
||
255 | * @param mixed $value |
||
256 | * @param mixed $value2 |
||
257 | * @param string|null $message |
||
258 | * @param string|null $propertyPath |
||
259 | * @return void |
||
260 | * @throws \Assert\AssertionFailedException |
||
261 | */ |
||
262 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
274 | |||
275 | /** |
||
276 | * Assert that two values are not equal (using == ). |
||
277 | * |
||
278 | * @param mixed $value1 |
||
279 | * @param mixed $value2 |
||
280 | * @param string|null $message |
||
281 | * @param string|null $propertyPath |
||
282 | * @return void |
||
283 | * @throws \Assert\AssertionFailedException |
||
284 | */ |
||
285 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
296 | |||
297 | /** |
||
298 | * Assert that two values are not the same (using === ). |
||
299 | * |
||
300 | * @param mixed $value1 |
||
301 | * @param mixed $value2 |
||
302 | * @param string|null $message |
||
303 | * @param string|null $propertyPath |
||
304 | * @return void |
||
305 | * @throws \Assert\AssertionFailedException |
||
306 | */ |
||
307 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
318 | |||
319 | /** |
||
320 | * Assert that value is not in array of choices. |
||
321 | * |
||
322 | * @param mixed $value |
||
323 | * @param array $choices |
||
324 | * @param string|null $message |
||
325 | * @param string|null $propertyPath |
||
326 | * @return void |
||
327 | * @throws \Assert\AssertionFailedException |
||
328 | */ |
||
329 | public static function notInArray($value, array $choices, $message = null, $propertyPath = null) |
||
340 | |||
341 | /** |
||
342 | * Assert that value is a php integer. |
||
343 | * |
||
344 | * @param mixed $value |
||
345 | * @param string|null $message |
||
346 | * @param string|null $propertyPath |
||
347 | * @return void |
||
348 | * @throws \Assert\AssertionFailedException |
||
349 | */ |
||
350 | public static function integer($value, $message = null, $propertyPath = null) |
||
361 | |||
362 | /** |
||
363 | * Assert that value is a php float. |
||
364 | * |
||
365 | * @param mixed $value |
||
366 | * @param string|null $message |
||
367 | * @param string|null $propertyPath |
||
368 | * @return void |
||
369 | * @throws \Assert\AssertionFailedException |
||
370 | */ |
||
371 | public static function float($value, $message = null, $propertyPath = null) |
||
382 | |||
383 | /** |
||
384 | * Validates if an integer or integerish is a digit. |
||
385 | * |
||
386 | * @param mixed $value |
||
387 | * @param string|null $message |
||
388 | * @param string|null $propertyPath |
||
389 | * @return void |
||
390 | * @throws \Assert\AssertionFailedException |
||
391 | */ |
||
392 | public static function digit($value, $message = null, $propertyPath = null) |
||
403 | |||
404 | /** |
||
405 | * Assert that value is a php integer'ish. |
||
406 | * |
||
407 | * @param mixed $value |
||
408 | * @param string|null $message |
||
409 | * @param string|null $propertyPath |
||
410 | * @return void |
||
411 | * @throws \Assert\AssertionFailedException |
||
412 | */ |
||
413 | public static function integerish($value, $message = null, $propertyPath = null) |
||
424 | |||
425 | /** |
||
426 | * Assert that value is php boolean |
||
427 | * |
||
428 | * @param mixed $value |
||
429 | * @param string|null $message |
||
430 | * @param string|null $propertyPath |
||
431 | * @return void |
||
432 | * @throws \Assert\AssertionFailedException |
||
433 | */ |
||
434 | public static function boolean($value, $message = null, $propertyPath = null) |
||
445 | |||
446 | /** |
||
447 | * Assert that value is a PHP scalar |
||
448 | * |
||
449 | * @param mixed $value |
||
450 | * @param string|null $message |
||
451 | * @param string|null $propertyPath |
||
452 | * @return void |
||
453 | * @throws \Assert\AssertionFailedException |
||
454 | */ |
||
455 | public static function scalar($value, $message = null, $propertyPath = null) |
||
466 | |||
467 | /** |
||
468 | * Assert that value is not empty |
||
469 | * |
||
470 | * @param mixed $value |
||
471 | * @param string|null $message |
||
472 | * @param string|null $propertyPath |
||
473 | * @return void |
||
474 | * @throws \Assert\AssertionFailedException |
||
475 | */ |
||
476 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
487 | |||
488 | /** |
||
489 | * Assert that value is empty |
||
490 | * |
||
491 | * @param mixed $value |
||
492 | * @param string|null $message |
||
493 | * @param string|null $propertyPath |
||
494 | * @return void |
||
495 | * @throws \Assert\AssertionFailedException |
||
496 | */ |
||
497 | public static function noContent($value, $message = null, $propertyPath = null) |
||
508 | |||
509 | /** |
||
510 | * Assert that value is not null |
||
511 | * |
||
512 | * @param mixed $value |
||
513 | * @param string|null $message |
||
514 | * @param string|null $propertyPath |
||
515 | * @return void |
||
516 | * @throws \Assert\AssertionFailedException |
||
517 | */ |
||
518 | public static function notNull($value, $message = null, $propertyPath = null) |
||
529 | |||
530 | /** |
||
531 | * Assert that value is a string |
||
532 | * |
||
533 | * @param mixed $value |
||
534 | * @param string|null $message |
||
535 | * @param string|null $propertyPath |
||
536 | * @return void |
||
537 | * @throws \Assert\AssertionFailedException |
||
538 | */ |
||
539 | public static function string($value, $message = null, $propertyPath = null) |
||
551 | |||
552 | /** |
||
553 | * Assert that value matches a regex |
||
554 | * |
||
555 | * @param mixed $value |
||
556 | * @param string $pattern |
||
557 | * @param string|null $message |
||
558 | * @param string|null $propertyPath |
||
559 | * @return void |
||
560 | * @throws \Assert\AssertionFailedException |
||
561 | */ |
||
562 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
575 | |||
576 | /** |
||
577 | * Assert that string has a given length. |
||
578 | * |
||
579 | * @param mixed $value |
||
580 | * @param int $length |
||
581 | * @param string|null $message |
||
582 | * @param string|null $propertyPath |
||
583 | * @param string $encoding |
||
584 | * @return void |
||
585 | * @throws \Assert\AssertionFailedException |
||
586 | */ |
||
587 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
603 | |||
604 | /** |
||
605 | * Assert that a string is at least $minLength chars long. |
||
606 | * |
||
607 | * @param mixed $value |
||
608 | * @param int $minLength |
||
609 | * @param string|null $message |
||
610 | * @param string|null $propertyPath |
||
611 | * @param string $encoding |
||
612 | * @return void |
||
613 | * @throws \Assert\AssertionFailedException |
||
614 | */ |
||
615 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
631 | |||
632 | /** |
||
633 | * Assert that string value is not longer than $maxLength chars. |
||
634 | * |
||
635 | * @param mixed $value |
||
636 | * @param integer $maxLength |
||
637 | * @param string|null $message |
||
638 | * @param string|null $propertyPath |
||
639 | * @param string $encoding |
||
640 | * @return void |
||
641 | * @throws \Assert\AssertionFailedException |
||
642 | */ |
||
643 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
659 | |||
660 | /** |
||
661 | * Assert that string length is between min,max lengths. |
||
662 | * |
||
663 | * @param mixed $value |
||
664 | * @param integer $minLength |
||
665 | * @param integer $maxLength |
||
666 | * @param string|null $message |
||
667 | * @param string|null $propertyPath |
||
668 | * @param string $encoding |
||
669 | * @return void |
||
670 | * @throws \Assert\AssertionFailedException |
||
671 | */ |
||
672 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
700 | |||
701 | /** |
||
702 | * Assert that string starts with a sequence of chars. |
||
703 | * |
||
704 | * @param mixed $string |
||
705 | * @param string $needle |
||
706 | * @param string|null $message |
||
707 | * @param string|null $propertyPath |
||
708 | * @param string $encoding |
||
709 | * @return void |
||
710 | * @throws \Assert\AssertionFailedException |
||
711 | */ |
||
712 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
727 | |||
728 | /** |
||
729 | * Assert that string ends with a sequence of chars. |
||
730 | * |
||
731 | * @param mixed $string |
||
732 | * @param string $needle |
||
733 | * @param string|null $message |
||
734 | * @param string|null $propertyPath |
||
735 | * @param string $encoding |
||
736 | * @return void |
||
737 | * @throws \Assert\AssertionFailedException |
||
738 | */ |
||
739 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
756 | |||
757 | /** |
||
758 | * Assert that string contains a sequence of chars. |
||
759 | * |
||
760 | * @param mixed $string |
||
761 | * @param string $needle |
||
762 | * @param string|null $message |
||
763 | * @param string|null $propertyPath |
||
764 | * @param string $encoding |
||
765 | * @return void |
||
766 | * @throws \Assert\AssertionFailedException |
||
767 | */ |
||
768 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
783 | |||
784 | /** |
||
785 | * Assert that value is in array of choices. |
||
786 | * |
||
787 | * @param mixed $value |
||
788 | * @param array $choices |
||
789 | * @param string|null $message |
||
790 | * @param string|null $propertyPath |
||
791 | * @return void |
||
792 | * @throws \Assert\AssertionFailedException |
||
793 | */ |
||
794 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
806 | |||
807 | /** |
||
808 | * Alias of {@see choice()} |
||
809 | * |
||
810 | * @throws \Assert\AssertionFailedException |
||
811 | */ |
||
812 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
816 | |||
817 | /** |
||
818 | * Assert that value is numeric. |
||
819 | * |
||
820 | * @param mixed $value |
||
821 | * @param string|null $message |
||
822 | * @param string|null $propertyPath |
||
823 | * @return void |
||
824 | * @throws \Assert\AssertionFailedException |
||
825 | */ |
||
826 | public static function numeric($value, $message = null, $propertyPath = null) |
||
837 | |||
838 | /** |
||
839 | * Assert that value is an array. |
||
840 | * |
||
841 | * @param mixed $value |
||
842 | * @param string|null $message |
||
843 | * @param string|null $propertyPath |
||
844 | * @return void |
||
845 | * @throws \Assert\AssertionFailedException |
||
846 | */ |
||
847 | public static function isArray($value, $message = null, $propertyPath = null) |
||
858 | |||
859 | /** |
||
860 | * Assert that value is an array or a traversable object. |
||
861 | * |
||
862 | * @param mixed $value |
||
863 | * @param string|null $message |
||
864 | * @param string|null $propertyPath |
||
865 | * @return void |
||
866 | * @throws \Assert\AssertionFailedException |
||
867 | */ |
||
868 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
879 | |||
880 | /** |
||
881 | * Assert that value is an array or an array-accessible object. |
||
882 | * |
||
883 | * @param mixed $value |
||
884 | * @param string|null $message |
||
885 | * @param string|null $propertyPath |
||
886 | * @return void |
||
887 | * @throws \Assert\AssertionFailedException |
||
888 | */ |
||
889 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
900 | |||
901 | /** |
||
902 | * Assert that key exists in an array |
||
903 | * |
||
904 | * @param mixed $value |
||
905 | * @param string|integer $key |
||
906 | * @param string|null $message |
||
907 | * @param string|null $propertyPath |
||
908 | * @return void |
||
909 | * @throws \Assert\AssertionFailedException |
||
910 | */ |
||
911 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
924 | |||
925 | /** |
||
926 | * Assert that key does not exist in an array |
||
927 | * |
||
928 | * @param mixed $value |
||
929 | * @param string|integer $key |
||
930 | * @param string|null $message |
||
931 | * @param string|null $propertyPath |
||
932 | * @return void |
||
933 | * @throws \Assert\AssertionFailedException |
||
934 | */ |
||
935 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null) |
||
948 | |||
949 | /** |
||
950 | * Assert that key exists in an array/array-accessible object using isset() |
||
951 | * |
||
952 | * @param mixed $value |
||
953 | * @param string|integer $key |
||
954 | * @param string|null $message |
||
955 | * @param string|null $propertyPath |
||
956 | * @return void |
||
957 | * @throws \Assert\AssertionFailedException |
||
958 | */ |
||
959 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
972 | |||
973 | /** |
||
974 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
975 | * |
||
976 | * @param mixed $value |
||
977 | * @param string|integer $key |
||
978 | * @param string|null $message |
||
979 | * @param string|null $propertyPath |
||
980 | * @return void |
||
981 | * @throws \Assert\AssertionFailedException |
||
982 | */ |
||
983 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
988 | |||
989 | /** |
||
990 | * Assert that value is not blank |
||
991 | * |
||
992 | * @param mixed $value |
||
993 | * @param string|null $message |
||
994 | * @param string|null $propertyPath |
||
995 | * @return void |
||
996 | * @throws \Assert\AssertionFailedException |
||
997 | */ |
||
998 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
1009 | |||
1010 | /** |
||
1011 | * Assert that value is instance of given class-name. |
||
1012 | * |
||
1013 | * @param mixed $value |
||
1014 | * @param string $className |
||
1015 | * @param string|null $message |
||
1016 | * @param string|null $propertyPath |
||
1017 | * @return void |
||
1018 | * @throws \Assert\AssertionFailedException |
||
1019 | */ |
||
1020 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1032 | |||
1033 | /** |
||
1034 | * Assert that value is not instance of given class-name. |
||
1035 | * |
||
1036 | * @param mixed $value |
||
1037 | * @param string $className |
||
1038 | * @param string|null $message |
||
1039 | * @param string|null $propertyPath |
||
1040 | * @return void |
||
1041 | * @throws \Assert\AssertionFailedException |
||
1042 | */ |
||
1043 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1055 | |||
1056 | /** |
||
1057 | * Assert that value is subclass of given class-name. |
||
1058 | * |
||
1059 | * @param mixed $value |
||
1060 | * @param string $className |
||
1061 | * @param string|null $message |
||
1062 | * @param string|null $propertyPath |
||
1063 | * @return void |
||
1064 | * @throws \Assert\AssertionFailedException |
||
1065 | */ |
||
1066 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
1078 | |||
1079 | /** |
||
1080 | * Assert that value is in range of numbers. |
||
1081 | * |
||
1082 | * @param mixed $value |
||
1083 | * @param integer $minValue |
||
1084 | * @param integer $maxValue |
||
1085 | * @param string|null $message |
||
1086 | * @param string|null $propertyPath |
||
1087 | * @return void |
||
1088 | * @throws \Assert\AssertionFailedException |
||
1089 | */ |
||
1090 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
1105 | |||
1106 | /** |
||
1107 | * Assert that a value is at least as big as a given limit |
||
1108 | * |
||
1109 | * @param mixed $value |
||
1110 | * @param mixed $minValue |
||
1111 | * @param string|null $message |
||
1112 | * @param string|null $propertyPath |
||
1113 | * @return void |
||
1114 | * @throws \Assert\AssertionFailedException |
||
1115 | */ |
||
1116 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
1130 | |||
1131 | /** |
||
1132 | * Assert that a number is smaller as a given limit |
||
1133 | * |
||
1134 | * @param mixed $value |
||
1135 | * @param mixed $maxValue |
||
1136 | * @param string|null $message |
||
1137 | * @param string|null $propertyPath |
||
1138 | * @return void |
||
1139 | * @throws \Assert\AssertionFailedException |
||
1140 | */ |
||
1141 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
1155 | |||
1156 | /** |
||
1157 | * Assert that a file exists |
||
1158 | * |
||
1159 | * @param string $value |
||
1160 | * @param string|null $message |
||
1161 | * @param string|null $propertyPath |
||
1162 | * @return void |
||
1163 | * @throws \Assert\AssertionFailedException |
||
1164 | */ |
||
1165 | public static function file($value, $message = null, $propertyPath = null) |
||
1179 | |||
1180 | /** |
||
1181 | * Assert that a directory exists |
||
1182 | * |
||
1183 | * @param string $value |
||
1184 | * @param string|null $message |
||
1185 | * @param string|null $propertyPath |
||
1186 | * @return void |
||
1187 | * @throws \Assert\AssertionFailedException |
||
1188 | */ |
||
1189 | public static function directory($value, $message = null, $propertyPath = null) |
||
1202 | |||
1203 | /** |
||
1204 | * Assert that the value is something readable |
||
1205 | * |
||
1206 | * @param string $value |
||
1207 | * @param string|null $message |
||
1208 | * @param string|null $propertyPath |
||
1209 | * @return void |
||
1210 | * @throws \Assert\AssertionFailedException |
||
1211 | */ |
||
1212 | public static function readable($value, $message = null, $propertyPath = null) |
||
1225 | |||
1226 | /** |
||
1227 | * Assert that the value is something writeable |
||
1228 | * |
||
1229 | * @param string $value |
||
1230 | * @param string|null $message |
||
1231 | * @param string|null $propertyPath |
||
1232 | * @return void |
||
1233 | * @throws \Assert\AssertionFailedException |
||
1234 | */ |
||
1235 | public static function writeable($value, $message = null, $propertyPath = null) |
||
1248 | |||
1249 | /** |
||
1250 | * Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL). |
||
1251 | * |
||
1252 | * @param mixed $value |
||
1253 | * @param string|null $message |
||
1254 | * @param string|null $propertyPath |
||
1255 | * @return void |
||
1256 | * @throws \Assert\AssertionFailedException |
||
1257 | */ |
||
1258 | public static function email($value, $message = null, $propertyPath = null) |
||
1283 | |||
1284 | /** |
||
1285 | * Assert that value is an URL. |
||
1286 | * |
||
1287 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
1288 | * |
||
1289 | * @param mixed $value |
||
1290 | * @param string|null $message |
||
1291 | * @param string|null $propertyPath |
||
1292 | * @return void |
||
1293 | * @throws \Assert\AssertionFailedException |
||
1294 | * |
||
1295 | * |
||
1296 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
1297 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
1298 | */ |
||
1299 | public static function url($value, $message = null, $propertyPath = null) |
||
1332 | |||
1333 | /** |
||
1334 | * Assert that value is alphanumeric. |
||
1335 | * |
||
1336 | * @param mixed $value |
||
1337 | * @param string|null $message |
||
1338 | * @param string|null $propertyPath |
||
1339 | * @return void |
||
1340 | * @throws \Assert\AssertionFailedException |
||
1341 | */ |
||
1342 | public static function alnum($value, $message = null, $propertyPath = null) |
||
1355 | |||
1356 | /** |
||
1357 | * Assert that the value is boolean True. |
||
1358 | * |
||
1359 | * @param mixed $value |
||
1360 | * @param string|null $message |
||
1361 | * @param string|null $propertyPath |
||
1362 | * @return void |
||
1363 | * @throws \Assert\AssertionFailedException |
||
1364 | */ |
||
1365 | public static function true($value, $message = null, $propertyPath = null) |
||
1376 | |||
1377 | /** |
||
1378 | * Assert that the value is boolean False. |
||
1379 | * |
||
1380 | * @param mixed $value |
||
1381 | * @param string|null $message |
||
1382 | * @param string|null $propertyPath |
||
1383 | * @return void |
||
1384 | * @throws \Assert\AssertionFailedException |
||
1385 | */ |
||
1386 | public static function false($value, $message = null, $propertyPath = null) |
||
1397 | |||
1398 | /** |
||
1399 | * Assert that the class exists. |
||
1400 | * |
||
1401 | * @param mixed $value |
||
1402 | * @param string|null $message |
||
1403 | * @param string|null $propertyPath |
||
1404 | * @return void |
||
1405 | * @throws \Assert\AssertionFailedException |
||
1406 | */ |
||
1407 | public static function classExists($value, $message = null, $propertyPath = null) |
||
1418 | |||
1419 | /** |
||
1420 | * Assert that the class implements the interface |
||
1421 | * |
||
1422 | * @param mixed $class |
||
1423 | * @param string $interfaceName |
||
1424 | * @param string|null $message |
||
1425 | * @param string|null $propertyPath |
||
1426 | * @return void |
||
1427 | * @throws \Assert\AssertionFailedException |
||
1428 | */ |
||
1429 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
1442 | |||
1443 | /** |
||
1444 | * Assert that the given string is a valid json string. |
||
1445 | * |
||
1446 | * NOTICE: |
||
1447 | * Since this does a json_decode to determine its validity |
||
1448 | * you probably should consider, when using the variable |
||
1449 | * content afterwards, just to decode and check for yourself instead |
||
1450 | * of using this assertion. |
||
1451 | * |
||
1452 | * @param mixed $value |
||
1453 | * @param string|null $message |
||
1454 | * @param string|null $propertyPath |
||
1455 | * @return void |
||
1456 | * @throws \Assert\AssertionFailedException |
||
1457 | */ |
||
1458 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
1469 | |||
1470 | /** |
||
1471 | * Assert that the given string is a valid UUID |
||
1472 | * |
||
1473 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
1474 | * |
||
1475 | * @param string $value |
||
1476 | * @param string|null $message |
||
1477 | * @param string|null $propertyPath |
||
1478 | * @return void |
||
1479 | * @throws \Assert\AssertionFailedException |
||
1480 | */ |
||
1481 | public static function uuid($value, $message = null, $propertyPath = null) |
||
1498 | |||
1499 | /** |
||
1500 | * Assert that the count of countable is equal to count. |
||
1501 | * |
||
1502 | * @param array|\Countable $countable |
||
1503 | * @param int $count |
||
1504 | * @param string $message |
||
1505 | * @param string $propertyPath |
||
1506 | * @return void |
||
1507 | * @throws \Assert\AssertionFailedException |
||
1508 | */ |
||
1509 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
1520 | |||
1521 | /** |
||
1522 | * static call handler to implement: |
||
1523 | * - "null or assertion" delegation |
||
1524 | * - "all" delegation |
||
1525 | */ |
||
1526 | public static function __callStatic($method, $args) |
||
1562 | |||
1563 | /** |
||
1564 | * Determines if the values array has every choice as key and that this choice has content. |
||
1565 | * |
||
1566 | * @param array $values |
||
1567 | * @param array $choices |
||
1568 | * @param null $message |
||
1569 | * @param null $propertyPath |
||
1570 | */ |
||
1571 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
1580 | |||
1581 | /** |
||
1582 | * Determines that the named method is defined in the provided object. |
||
1583 | * |
||
1584 | * @param string $value |
||
1585 | * @param mixed $object |
||
1586 | * @param null $message |
||
1587 | * @param null $propertyPath |
||
1588 | * |
||
1589 | * @throws |
||
1590 | */ |
||
1591 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
1604 | |||
1605 | /** |
||
1606 | * Determines that the provided value is an object. |
||
1607 | * |
||
1608 | * @param mixed $value |
||
1609 | * @param null $message |
||
1610 | * @param null $propertyPath |
||
1611 | */ |
||
1612 | public static function isObject($value, $message = null, $propertyPath = null) |
||
1624 | |||
1625 | /** |
||
1626 | * Determines if the value is less than given limit. |
||
1627 | * |
||
1628 | * @param mixed $value |
||
1629 | * @param mixed $limit |
||
1630 | * @param null $message |
||
1631 | * @param null $propertyPath |
||
1632 | */ |
||
1633 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
1645 | |||
1646 | /** |
||
1647 | * Determines if the value is less or than given limit. |
||
1648 | * |
||
1649 | * @param mixed $value |
||
1650 | * @param mixed $limit |
||
1651 | * @param null $message |
||
1652 | * @param null $propertyPath |
||
1653 | */ |
||
1654 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1666 | |||
1667 | /** |
||
1668 | * Determines if the value is greater than given limit. |
||
1669 | * |
||
1670 | * @param mixed $value |
||
1671 | * @param mixed $limit |
||
1672 | * @param null $message |
||
1673 | * @param null $propertyPath |
||
1674 | */ |
||
1675 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
1687 | |||
1688 | /** |
||
1689 | * Determines if the value is greater or equal than given limit. |
||
1690 | * |
||
1691 | * @param mixed $value |
||
1692 | * @param mixed $limit |
||
1693 | * @param null $message |
||
1694 | * @param null $propertyPath |
||
1695 | */ |
||
1696 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1708 | |||
1709 | /** |
||
1710 | * Assert that date is valid and corresponds to the given format. |
||
1711 | * |
||
1712 | * @param string $value |
||
1713 | * @param string $format supports all of the options date(), except for the following: |
||
1714 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
1715 | * @param string|null $message |
||
1716 | * @param string|null $propertyPath |
||
1717 | * |
||
1718 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
1719 | */ |
||
1720 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
1737 | |||
1738 | /** |
||
1739 | * Determines that the provided value is callable. |
||
1740 | * |
||
1741 | * @param mixed $value |
||
1742 | * @param null $message |
||
1743 | * @param null $propertyPath |
||
1744 | */ |
||
1745 | public static function isCallable($value, $message = null, $propertyPath = null) |
||
1756 | |||
1757 | /** |
||
1758 | * Make a string version of a value. |
||
1759 | * |
||
1760 | * @param mixed $value |
||
1761 | * @return string |
||
1762 | */ |
||
1763 | protected static function stringify($value) |
||
1797 | } |
||
1798 | |||
1799 |