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 |
||
150 | class Assertion |
||
151 | { |
||
152 | const INVALID_FLOAT = 9; |
||
153 | const INVALID_INTEGER = 10; |
||
154 | const INVALID_DIGIT = 11; |
||
155 | const INVALID_INTEGERISH = 12; |
||
156 | const INVALID_BOOLEAN = 13; |
||
157 | const VALUE_EMPTY = 14; |
||
158 | const VALUE_NULL = 15; |
||
159 | const INVALID_STRING = 16; |
||
160 | const INVALID_REGEX = 17; |
||
161 | const INVALID_MIN_LENGTH = 18; |
||
162 | const INVALID_MAX_LENGTH = 19; |
||
163 | const INVALID_STRING_START = 20; |
||
164 | const INVALID_STRING_CONTAINS = 21; |
||
165 | const INVALID_CHOICE = 22; |
||
166 | const INVALID_NUMERIC = 23; |
||
167 | const INVALID_ARRAY = 24; |
||
168 | const INVALID_KEY_EXISTS = 26; |
||
169 | const INVALID_NOT_BLANK = 27; |
||
170 | const INVALID_INSTANCE_OF = 28; |
||
171 | const INVALID_SUBCLASS_OF = 29; |
||
172 | const INVALID_RANGE = 30; |
||
173 | const INVALID_ALNUM = 31; |
||
174 | const INVALID_TRUE = 32; |
||
175 | const INVALID_EQ = 33; |
||
176 | const INVALID_SAME = 34; |
||
177 | const INVALID_MIN = 35; |
||
178 | const INVALID_MAX = 36; |
||
179 | const INVALID_LENGTH = 37; |
||
180 | const INVALID_FALSE = 38; |
||
181 | const INVALID_STRING_END = 39; |
||
182 | const INVALID_UUID = 40; |
||
183 | const INVALID_COUNT = 41; |
||
184 | const INVALID_NOT_EQ = 42; |
||
185 | const INVALID_NOT_SAME = 43; |
||
186 | const INVALID_TRAVERSABLE = 44; |
||
187 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
188 | const INVALID_KEY_ISSET = 46; |
||
189 | const INVALID_VALUE_IN_ARRAY = 47; |
||
190 | const INVALID_DIRECTORY = 101; |
||
191 | const INVALID_FILE = 102; |
||
192 | const INVALID_READABLE = 103; |
||
193 | const INVALID_WRITEABLE = 104; |
||
194 | const INVALID_CLASS = 105; |
||
195 | const INVALID_EMAIL = 201; |
||
196 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
197 | const INVALID_URL = 203; |
||
198 | const INVALID_NOT_INSTANCE_OF = 204; |
||
199 | const VALUE_NOT_EMPTY = 205; |
||
200 | const INVALID_JSON_STRING = 206; |
||
201 | const INVALID_OBJECT = 207; |
||
202 | const INVALID_METHOD = 208; |
||
203 | const INVALID_SCALAR = 209; |
||
204 | const INVALID_LESS = 210; |
||
205 | const INVALID_LESS_OR_EQUAL = 211; |
||
206 | const INVALID_GREATER = 212; |
||
207 | const INVALID_GREATER_OR_EQUAL = 213; |
||
208 | const INVALID_DATE = 214; |
||
209 | const INVALID_CALLABLE = 215; |
||
210 | const INVALID_KEY_NOT_EXISTS = 216; |
||
211 | const INVALID_CUSTOM = 217; |
||
212 | |||
213 | /** |
||
214 | * Exception to throw when an assertion failed. |
||
215 | * |
||
216 | * @var string |
||
217 | */ |
||
218 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
219 | |||
220 | /** |
||
221 | * Helper method that handles building the assertion failure exceptions. |
||
222 | * They are returned from this method so that the stack trace still shows |
||
223 | * the assertions method. |
||
224 | */ |
||
225 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
230 | |||
231 | /** |
||
232 | * Assert that two values are equal (using == ). |
||
233 | * |
||
234 | * @param mixed $value |
||
235 | * @param mixed $value2 |
||
236 | * @param string|null $message |
||
237 | * @param string|null $propertyPath |
||
238 | * @return void |
||
239 | * @throws \Assert\AssertionFailedException |
||
240 | */ |
||
241 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
253 | |||
254 | /** |
||
255 | * Assert that two values are the same (using ===). |
||
256 | * |
||
257 | * @param mixed $value |
||
258 | * @param mixed $value2 |
||
259 | * @param string|null $message |
||
260 | * @param string|null $propertyPath |
||
261 | * @return void |
||
262 | * @throws \Assert\AssertionFailedException |
||
263 | */ |
||
264 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
276 | |||
277 | /** |
||
278 | * Assert that two values are not equal (using == ). |
||
279 | * |
||
280 | * @param mixed $value1 |
||
281 | * @param mixed $value2 |
||
282 | * @param string|null $message |
||
283 | * @param string|null $propertyPath |
||
284 | * @return void |
||
285 | * @throws \Assert\AssertionFailedException |
||
286 | */ |
||
287 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
298 | |||
299 | /** |
||
300 | * Assert that two values are not the same (using === ). |
||
301 | * |
||
302 | * @param mixed $value1 |
||
303 | * @param mixed $value2 |
||
304 | * @param string|null $message |
||
305 | * @param string|null $propertyPath |
||
306 | * @return void |
||
307 | * @throws \Assert\AssertionFailedException |
||
308 | */ |
||
309 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
320 | |||
321 | /** |
||
322 | * Assert that value is not in array of choices. |
||
323 | * |
||
324 | * @param mixed $value |
||
325 | * @param array $choices |
||
326 | * @param string|null $message |
||
327 | * @param string|null $propertyPath |
||
328 | * @return void |
||
329 | * @throws \Assert\AssertionFailedException |
||
330 | */ |
||
331 | public static function notInArray($value, array $choices, $message = null, $propertyPath = null) |
||
342 | |||
343 | /** |
||
344 | * Assert that value is a php integer. |
||
345 | * |
||
346 | * @param mixed $value |
||
347 | * @param string|null $message |
||
348 | * @param string|null $propertyPath |
||
349 | * @return void |
||
350 | * @throws \Assert\AssertionFailedException |
||
351 | */ |
||
352 | public static function integer($value, $message = null, $propertyPath = null) |
||
363 | |||
364 | /** |
||
365 | * Assert that value is a php float. |
||
366 | * |
||
367 | * @param mixed $value |
||
368 | * @param string|null $message |
||
369 | * @param string|null $propertyPath |
||
370 | * @return void |
||
371 | * @throws \Assert\AssertionFailedException |
||
372 | */ |
||
373 | public static function float($value, $message = null, $propertyPath = null) |
||
384 | |||
385 | /** |
||
386 | * Validates if an integer or integerish is a digit. |
||
387 | * |
||
388 | * @param mixed $value |
||
389 | * @param string|null $message |
||
390 | * @param string|null $propertyPath |
||
391 | * @return void |
||
392 | * @throws \Assert\AssertionFailedException |
||
393 | */ |
||
394 | public static function digit($value, $message = null, $propertyPath = null) |
||
405 | |||
406 | /** |
||
407 | * Assert that value is a php integer'ish. |
||
408 | * |
||
409 | * @param mixed $value |
||
410 | * @param string|null $message |
||
411 | * @param string|null $propertyPath |
||
412 | * @return void |
||
413 | * @throws \Assert\AssertionFailedException |
||
414 | */ |
||
415 | public static function integerish($value, $message = null, $propertyPath = null) |
||
426 | |||
427 | /** |
||
428 | * Assert that value is php boolean |
||
429 | * |
||
430 | * @param mixed $value |
||
431 | * @param string|null $message |
||
432 | * @param string|null $propertyPath |
||
433 | * @return void |
||
434 | * @throws \Assert\AssertionFailedException |
||
435 | */ |
||
436 | public static function boolean($value, $message = null, $propertyPath = null) |
||
447 | |||
448 | /** |
||
449 | * Assert that value is a PHP scalar |
||
450 | * |
||
451 | * @param mixed $value |
||
452 | * @param string|null $message |
||
453 | * @param string|null $propertyPath |
||
454 | * @return void |
||
455 | * @throws \Assert\AssertionFailedException |
||
456 | */ |
||
457 | public static function scalar($value, $message = null, $propertyPath = null) |
||
468 | |||
469 | /** |
||
470 | * Assert that value is not empty |
||
471 | * |
||
472 | * @param mixed $value |
||
473 | * @param string|null $message |
||
474 | * @param string|null $propertyPath |
||
475 | * @return void |
||
476 | * @throws \Assert\AssertionFailedException |
||
477 | */ |
||
478 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
489 | |||
490 | /** |
||
491 | * Assert that value is empty |
||
492 | * |
||
493 | * @param mixed $value |
||
494 | * @param string|null $message |
||
495 | * @param string|null $propertyPath |
||
496 | * @return void |
||
497 | * @throws \Assert\AssertionFailedException |
||
498 | */ |
||
499 | public static function noContent($value, $message = null, $propertyPath = null) |
||
510 | |||
511 | /** |
||
512 | * Assert that value is not null |
||
513 | * |
||
514 | * @param mixed $value |
||
515 | * @param string|null $message |
||
516 | * @param string|null $propertyPath |
||
517 | * @return void |
||
518 | * @throws \Assert\AssertionFailedException |
||
519 | */ |
||
520 | public static function notNull($value, $message = null, $propertyPath = null) |
||
531 | |||
532 | /** |
||
533 | * Assert that value is a string |
||
534 | * |
||
535 | * @param mixed $value |
||
536 | * @param string|null $message |
||
537 | * @param string|null $propertyPath |
||
538 | * @return void |
||
539 | * @throws \Assert\AssertionFailedException |
||
540 | */ |
||
541 | public static function string($value, $message = null, $propertyPath = null) |
||
553 | |||
554 | /** |
||
555 | * Assert that value matches a regex |
||
556 | * |
||
557 | * @param mixed $value |
||
558 | * @param string $pattern |
||
559 | * @param string|null $message |
||
560 | * @param string|null $propertyPath |
||
561 | * @return void |
||
562 | * @throws \Assert\AssertionFailedException |
||
563 | */ |
||
564 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
577 | |||
578 | /** |
||
579 | * Assert that string has a given length. |
||
580 | * |
||
581 | * @param mixed $value |
||
582 | * @param int $length |
||
583 | * @param string|null $message |
||
584 | * @param string|null $propertyPath |
||
585 | * @param string $encoding |
||
586 | * @return void |
||
587 | * @throws \Assert\AssertionFailedException |
||
588 | */ |
||
589 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
605 | |||
606 | /** |
||
607 | * Assert that a string is at least $minLength chars long. |
||
608 | * |
||
609 | * @param mixed $value |
||
610 | * @param int $minLength |
||
611 | * @param string|null $message |
||
612 | * @param string|null $propertyPath |
||
613 | * @param string $encoding |
||
614 | * @return void |
||
615 | * @throws \Assert\AssertionFailedException |
||
616 | */ |
||
617 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
633 | |||
634 | /** |
||
635 | * Assert that string value is not longer than $maxLength chars. |
||
636 | * |
||
637 | * @param mixed $value |
||
638 | * @param integer $maxLength |
||
639 | * @param string|null $message |
||
640 | * @param string|null $propertyPath |
||
641 | * @param string $encoding |
||
642 | * @return void |
||
643 | * @throws \Assert\AssertionFailedException |
||
644 | */ |
||
645 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
661 | |||
662 | /** |
||
663 | * Assert that string length is between min,max lengths. |
||
664 | * |
||
665 | * @param mixed $value |
||
666 | * @param integer $minLength |
||
667 | * @param integer $maxLength |
||
668 | * @param string|null $message |
||
669 | * @param string|null $propertyPath |
||
670 | * @param string $encoding |
||
671 | * @return void |
||
672 | * @throws \Assert\AssertionFailedException |
||
673 | */ |
||
674 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
702 | |||
703 | /** |
||
704 | * Assert that string starts with a sequence of chars. |
||
705 | * |
||
706 | * @param mixed $string |
||
707 | * @param string $needle |
||
708 | * @param string|null $message |
||
709 | * @param string|null $propertyPath |
||
710 | * @param string $encoding |
||
711 | * @return void |
||
712 | * @throws \Assert\AssertionFailedException |
||
713 | */ |
||
714 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
729 | |||
730 | /** |
||
731 | * Assert that string ends with a sequence of chars. |
||
732 | * |
||
733 | * @param mixed $string |
||
734 | * @param string $needle |
||
735 | * @param string|null $message |
||
736 | * @param string|null $propertyPath |
||
737 | * @param string $encoding |
||
738 | * @return void |
||
739 | * @throws \Assert\AssertionFailedException |
||
740 | */ |
||
741 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
758 | |||
759 | /** |
||
760 | * Assert that string contains a sequence of chars. |
||
761 | * |
||
762 | * @param mixed $string |
||
763 | * @param string $needle |
||
764 | * @param string|null $message |
||
765 | * @param string|null $propertyPath |
||
766 | * @param string $encoding |
||
767 | * @return void |
||
768 | * @throws \Assert\AssertionFailedException |
||
769 | */ |
||
770 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
785 | |||
786 | /** |
||
787 | * Assert that value is in array of choices. |
||
788 | * |
||
789 | * @param mixed $value |
||
790 | * @param array $choices |
||
791 | * @param string|null $message |
||
792 | * @param string|null $propertyPath |
||
793 | * @return void |
||
794 | * @throws \Assert\AssertionFailedException |
||
795 | */ |
||
796 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
808 | |||
809 | /** |
||
810 | * Alias of {@see choice()} |
||
811 | * |
||
812 | * @throws \Assert\AssertionFailedException |
||
813 | */ |
||
814 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
818 | |||
819 | /** |
||
820 | * Assert that value is numeric. |
||
821 | * |
||
822 | * @param mixed $value |
||
823 | * @param string|null $message |
||
824 | * @param string|null $propertyPath |
||
825 | * @return void |
||
826 | * @throws \Assert\AssertionFailedException |
||
827 | */ |
||
828 | public static function numeric($value, $message = null, $propertyPath = null) |
||
839 | |||
840 | /** |
||
841 | * Assert that value is an array. |
||
842 | * |
||
843 | * @param mixed $value |
||
844 | * @param string|null $message |
||
845 | * @param string|null $propertyPath |
||
846 | * @return void |
||
847 | * @throws \Assert\AssertionFailedException |
||
848 | */ |
||
849 | public static function isArray($value, $message = null, $propertyPath = null) |
||
860 | |||
861 | /** |
||
862 | * Assert that value is an array or a traversable object. |
||
863 | * |
||
864 | * @param mixed $value |
||
865 | * @param string|null $message |
||
866 | * @param string|null $propertyPath |
||
867 | * @return void |
||
868 | * @throws \Assert\AssertionFailedException |
||
869 | */ |
||
870 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
881 | |||
882 | /** |
||
883 | * Assert that value is an array or an array-accessible object. |
||
884 | * |
||
885 | * @param mixed $value |
||
886 | * @param string|null $message |
||
887 | * @param string|null $propertyPath |
||
888 | * @return void |
||
889 | * @throws \Assert\AssertionFailedException |
||
890 | */ |
||
891 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
902 | |||
903 | /** |
||
904 | * Assert that key exists in an array |
||
905 | * |
||
906 | * @param mixed $value |
||
907 | * @param string|integer $key |
||
908 | * @param string|null $message |
||
909 | * @param string|null $propertyPath |
||
910 | * @return void |
||
911 | * @throws \Assert\AssertionFailedException |
||
912 | */ |
||
913 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
926 | |||
927 | /** |
||
928 | * Assert that key does not exist in an array |
||
929 | * |
||
930 | * @param mixed $value |
||
931 | * @param string|integer $key |
||
932 | * @param string|null $message |
||
933 | * @param string|null $propertyPath |
||
934 | * @return void |
||
935 | * @throws \Assert\AssertionFailedException |
||
936 | */ |
||
937 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null) |
||
950 | |||
951 | /** |
||
952 | * Assert that key exists in an array/array-accessible object using isset() |
||
953 | * |
||
954 | * @param mixed $value |
||
955 | * @param string|integer $key |
||
956 | * @param string|null $message |
||
957 | * @param string|null $propertyPath |
||
958 | * @return void |
||
959 | * @throws \Assert\AssertionFailedException |
||
960 | */ |
||
961 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
974 | |||
975 | /** |
||
976 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
977 | * |
||
978 | * @param mixed $value |
||
979 | * @param string|integer $key |
||
980 | * @param string|null $message |
||
981 | * @param string|null $propertyPath |
||
982 | * @return void |
||
983 | * @throws \Assert\AssertionFailedException |
||
984 | */ |
||
985 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
990 | |||
991 | /** |
||
992 | * Assert that value is not blank |
||
993 | * |
||
994 | * @param mixed $value |
||
995 | * @param string|null $message |
||
996 | * @param string|null $propertyPath |
||
997 | * @return void |
||
998 | * @throws \Assert\AssertionFailedException |
||
999 | */ |
||
1000 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
1011 | |||
1012 | /** |
||
1013 | * Assert that value is instance of given class-name. |
||
1014 | * |
||
1015 | * @param mixed $value |
||
1016 | * @param string $className |
||
1017 | * @param string|null $message |
||
1018 | * @param string|null $propertyPath |
||
1019 | * @return void |
||
1020 | * @throws \Assert\AssertionFailedException |
||
1021 | */ |
||
1022 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1034 | |||
1035 | /** |
||
1036 | * Assert that value is not instance of given class-name. |
||
1037 | * |
||
1038 | * @param mixed $value |
||
1039 | * @param string $className |
||
1040 | * @param string|null $message |
||
1041 | * @param string|null $propertyPath |
||
1042 | * @return void |
||
1043 | * @throws \Assert\AssertionFailedException |
||
1044 | */ |
||
1045 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1057 | |||
1058 | /** |
||
1059 | * Assert that value is subclass of given class-name. |
||
1060 | * |
||
1061 | * @param mixed $value |
||
1062 | * @param string $className |
||
1063 | * @param string|null $message |
||
1064 | * @param string|null $propertyPath |
||
1065 | * @return void |
||
1066 | * @throws \Assert\AssertionFailedException |
||
1067 | */ |
||
1068 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
1080 | |||
1081 | /** |
||
1082 | * Assert that value is in range of numbers. |
||
1083 | * |
||
1084 | * @param mixed $value |
||
1085 | * @param integer $minValue |
||
1086 | * @param integer $maxValue |
||
1087 | * @param string|null $message |
||
1088 | * @param string|null $propertyPath |
||
1089 | * @return void |
||
1090 | * @throws \Assert\AssertionFailedException |
||
1091 | */ |
||
1092 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
1107 | |||
1108 | /** |
||
1109 | * Assert that a value is at least as big as a given limit |
||
1110 | * |
||
1111 | * @param mixed $value |
||
1112 | * @param mixed $minValue |
||
1113 | * @param string|null $message |
||
1114 | * @param string|null $propertyPath |
||
1115 | * @return void |
||
1116 | * @throws \Assert\AssertionFailedException |
||
1117 | */ |
||
1118 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
1132 | |||
1133 | /** |
||
1134 | * Assert that a number is smaller as a given limit |
||
1135 | * |
||
1136 | * @param mixed $value |
||
1137 | * @param mixed $maxValue |
||
1138 | * @param string|null $message |
||
1139 | * @param string|null $propertyPath |
||
1140 | * @return void |
||
1141 | * @throws \Assert\AssertionFailedException |
||
1142 | */ |
||
1143 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
1157 | |||
1158 | /** |
||
1159 | * Assert that a file exists |
||
1160 | * |
||
1161 | * @param string $value |
||
1162 | * @param string|null $message |
||
1163 | * @param string|null $propertyPath |
||
1164 | * @return void |
||
1165 | * @throws \Assert\AssertionFailedException |
||
1166 | */ |
||
1167 | public static function file($value, $message = null, $propertyPath = null) |
||
1181 | |||
1182 | /** |
||
1183 | * Assert that a directory exists |
||
1184 | * |
||
1185 | * @param string $value |
||
1186 | * @param string|null $message |
||
1187 | * @param string|null $propertyPath |
||
1188 | * @return void |
||
1189 | * @throws \Assert\AssertionFailedException |
||
1190 | */ |
||
1191 | public static function directory($value, $message = null, $propertyPath = null) |
||
1204 | |||
1205 | /** |
||
1206 | * Assert that the value is something readable |
||
1207 | * |
||
1208 | * @param string $value |
||
1209 | * @param string|null $message |
||
1210 | * @param string|null $propertyPath |
||
1211 | * @return void |
||
1212 | * @throws \Assert\AssertionFailedException |
||
1213 | */ |
||
1214 | public static function readable($value, $message = null, $propertyPath = null) |
||
1227 | |||
1228 | /** |
||
1229 | * Assert that the value is something writeable |
||
1230 | * |
||
1231 | * @param string $value |
||
1232 | * @param string|null $message |
||
1233 | * @param string|null $propertyPath |
||
1234 | * @return void |
||
1235 | * @throws \Assert\AssertionFailedException |
||
1236 | */ |
||
1237 | public static function writeable($value, $message = null, $propertyPath = null) |
||
1250 | |||
1251 | /** |
||
1252 | * Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL). |
||
1253 | * |
||
1254 | * @param mixed $value |
||
1255 | * @param string|null $message |
||
1256 | * @param string|null $propertyPath |
||
1257 | * @return void |
||
1258 | * @throws \Assert\AssertionFailedException |
||
1259 | */ |
||
1260 | public static function email($value, $message = null, $propertyPath = null) |
||
1285 | |||
1286 | /** |
||
1287 | * Assert that value is an URL. |
||
1288 | * |
||
1289 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
1290 | * |
||
1291 | * @param mixed $value |
||
1292 | * @param string|null $message |
||
1293 | * @param string|null $propertyPath |
||
1294 | * @return void |
||
1295 | * @throws \Assert\AssertionFailedException |
||
1296 | * |
||
1297 | * |
||
1298 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
1299 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
1300 | */ |
||
1301 | public static function url($value, $message = null, $propertyPath = null) |
||
1334 | |||
1335 | /** |
||
1336 | * Assert that value is alphanumeric. |
||
1337 | * |
||
1338 | * @param mixed $value |
||
1339 | * @param string|null $message |
||
1340 | * @param string|null $propertyPath |
||
1341 | * @return void |
||
1342 | * @throws \Assert\AssertionFailedException |
||
1343 | */ |
||
1344 | public static function alnum($value, $message = null, $propertyPath = null) |
||
1357 | |||
1358 | /** |
||
1359 | * Assert that the value is boolean True. |
||
1360 | * |
||
1361 | * @param mixed $value |
||
1362 | * @param string|null $message |
||
1363 | * @param string|null $propertyPath |
||
1364 | * @return void |
||
1365 | * @throws \Assert\AssertionFailedException |
||
1366 | */ |
||
1367 | public static function true($value, $message = null, $propertyPath = null) |
||
1378 | |||
1379 | /** |
||
1380 | * Assert that the value is boolean False. |
||
1381 | * |
||
1382 | * @param mixed $value |
||
1383 | * @param string|null $message |
||
1384 | * @param string|null $propertyPath |
||
1385 | * @return void |
||
1386 | * @throws \Assert\AssertionFailedException |
||
1387 | */ |
||
1388 | public static function false($value, $message = null, $propertyPath = null) |
||
1399 | |||
1400 | /** |
||
1401 | * Assert that the class exists. |
||
1402 | * |
||
1403 | * @param mixed $value |
||
1404 | * @param string|null $message |
||
1405 | * @param string|null $propertyPath |
||
1406 | * @return void |
||
1407 | * @throws \Assert\AssertionFailedException |
||
1408 | */ |
||
1409 | public static function classExists($value, $message = null, $propertyPath = null) |
||
1420 | |||
1421 | /** |
||
1422 | * Assert that the class implements the interface |
||
1423 | * |
||
1424 | * @param mixed $class |
||
1425 | * @param string $interfaceName |
||
1426 | * @param string|null $message |
||
1427 | * @param string|null $propertyPath |
||
1428 | * @return void |
||
1429 | * @throws \Assert\AssertionFailedException |
||
1430 | */ |
||
1431 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
1444 | |||
1445 | /** |
||
1446 | * Assert that the given string is a valid json string. |
||
1447 | * |
||
1448 | * NOTICE: |
||
1449 | * Since this does a json_decode to determine its validity |
||
1450 | * you probably should consider, when using the variable |
||
1451 | * content afterwards, just to decode and check for yourself instead |
||
1452 | * of using this assertion. |
||
1453 | * |
||
1454 | * @param mixed $value |
||
1455 | * @param string|null $message |
||
1456 | * @param string|null $propertyPath |
||
1457 | * @return void |
||
1458 | * @throws \Assert\AssertionFailedException |
||
1459 | */ |
||
1460 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
1471 | |||
1472 | /** |
||
1473 | * Assert that the given string is a valid UUID |
||
1474 | * |
||
1475 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
1476 | * |
||
1477 | * @param string $value |
||
1478 | * @param string|null $message |
||
1479 | * @param string|null $propertyPath |
||
1480 | * @return void |
||
1481 | * @throws \Assert\AssertionFailedException |
||
1482 | */ |
||
1483 | public static function uuid($value, $message = null, $propertyPath = null) |
||
1500 | |||
1501 | /** |
||
1502 | * Assert that the count of countable is equal to count. |
||
1503 | * |
||
1504 | * @param array|\Countable $countable |
||
1505 | * @param int $count |
||
1506 | * @param string $message |
||
1507 | * @param string $propertyPath |
||
1508 | * @return void |
||
1509 | * @throws \Assert\AssertionFailedException |
||
1510 | */ |
||
1511 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
1522 | |||
1523 | /** |
||
1524 | * static call handler to implement: |
||
1525 | * - "null or assertion" delegation |
||
1526 | * - "all" delegation |
||
1527 | */ |
||
1528 | public static function __callStatic($method, $args) |
||
1564 | |||
1565 | /** |
||
1566 | * Determines if the values array has every choice as key and that this choice has content. |
||
1567 | * |
||
1568 | * @param array $values |
||
1569 | * @param array $choices |
||
1570 | * @param null $message |
||
1571 | * @param null $propertyPath |
||
1572 | */ |
||
1573 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
1582 | |||
1583 | /** |
||
1584 | * Determines that the named method is defined in the provided object. |
||
1585 | * |
||
1586 | * @param string $value |
||
1587 | * @param mixed $object |
||
1588 | * @param null $message |
||
1589 | * @param null $propertyPath |
||
1590 | * |
||
1591 | * @throws |
||
1592 | */ |
||
1593 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
1606 | |||
1607 | /** |
||
1608 | * Determines that the provided value is an object. |
||
1609 | * |
||
1610 | * @param mixed $value |
||
1611 | * @param null $message |
||
1612 | * @param null $propertyPath |
||
1613 | */ |
||
1614 | public static function isObject($value, $message = null, $propertyPath = null) |
||
1626 | |||
1627 | /** |
||
1628 | * Determines if the value is less than given limit. |
||
1629 | * |
||
1630 | * @param mixed $value |
||
1631 | * @param mixed $limit |
||
1632 | * @param null $message |
||
1633 | * @param null $propertyPath |
||
1634 | */ |
||
1635 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
1647 | |||
1648 | /** |
||
1649 | * Determines if the value is less or than given limit. |
||
1650 | * |
||
1651 | * @param mixed $value |
||
1652 | * @param mixed $limit |
||
1653 | * @param null $message |
||
1654 | * @param null $propertyPath |
||
1655 | */ |
||
1656 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1668 | |||
1669 | /** |
||
1670 | * Determines if the value is greater than given limit. |
||
1671 | * |
||
1672 | * @param mixed $value |
||
1673 | * @param mixed $limit |
||
1674 | * @param null $message |
||
1675 | * @param null $propertyPath |
||
1676 | */ |
||
1677 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
1689 | |||
1690 | /** |
||
1691 | * Determines if the value is greater or equal than given limit. |
||
1692 | * |
||
1693 | * @param mixed $value |
||
1694 | * @param mixed $limit |
||
1695 | * @param null $message |
||
1696 | * @param null $propertyPath |
||
1697 | */ |
||
1698 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1710 | |||
1711 | /** |
||
1712 | * Assert that date is valid and corresponds to the given format. |
||
1713 | * |
||
1714 | * @param string $value |
||
1715 | * @param string $format supports all of the options date(), except for the following: |
||
1716 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
1717 | * @param string|null $message |
||
1718 | * @param string|null $propertyPath |
||
1719 | * |
||
1720 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
1721 | */ |
||
1722 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
1739 | |||
1740 | /** |
||
1741 | * Determines that the provided value is callable. |
||
1742 | * |
||
1743 | * @param mixed $value |
||
1744 | * @param null $message |
||
1745 | * @param null $propertyPath |
||
1746 | */ |
||
1747 | public static function isCallable($value, $message = null, $propertyPath = null) |
||
1758 | |||
1759 | /** |
||
1760 | * Assert that the provided value is valid according to a custom rule. |
||
1761 | * |
||
1762 | * @param mixed $value |
||
1763 | * @param callable $callback |
||
1764 | * @param string|null $message |
||
1765 | * @param string|null $propertyPath |
||
1766 | */ |
||
1767 | public static function custom($value, $callback, $message = null, $propertyPath = null) |
||
1778 | |||
1779 | /** |
||
1780 | * Make a string version of a value. |
||
1781 | * |
||
1782 | * @param mixed $value |
||
1783 | * @return string |
||
1784 | */ |
||
1785 | protected static function stringify($value) |
||
1819 | } |
||
1820 | |||
1821 |