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 |
||
152 | class Assertion |
||
153 | { |
||
154 | const INVALID_FLOAT = 9; |
||
155 | const INVALID_INTEGER = 10; |
||
156 | const INVALID_DIGIT = 11; |
||
157 | const INVALID_INTEGERISH = 12; |
||
158 | const INVALID_BOOLEAN = 13; |
||
159 | const VALUE_EMPTY = 14; |
||
160 | const VALUE_NULL = 15; |
||
161 | const VALUE_NOT_NULL = 16; |
||
162 | const INVALID_STRING = 17; |
||
163 | const INVALID_REGEX = 18; |
||
164 | const INVALID_MIN_LENGTH = 19; |
||
165 | const INVALID_MAX_LENGTH = 20; |
||
166 | const INVALID_STRING_START = 21; |
||
167 | const INVALID_STRING_CONTAINS = 22; |
||
168 | const INVALID_CHOICE = 23; |
||
169 | const INVALID_NUMERIC = 24; |
||
170 | const INVALID_ARRAY = 25; |
||
171 | const INVALID_KEY_EXISTS = 26; |
||
172 | const INVALID_NOT_BLANK = 27; |
||
173 | const INVALID_INSTANCE_OF = 28; |
||
174 | const INVALID_SUBCLASS_OF = 29; |
||
175 | const INVALID_RANGE = 30; |
||
176 | const INVALID_ALNUM = 31; |
||
177 | const INVALID_TRUE = 32; |
||
178 | const INVALID_EQ = 33; |
||
179 | const INVALID_SAME = 34; |
||
180 | const INVALID_MIN = 35; |
||
181 | const INVALID_MAX = 36; |
||
182 | const INVALID_LENGTH = 37; |
||
183 | const INVALID_FALSE = 38; |
||
184 | const INVALID_STRING_END = 39; |
||
185 | const INVALID_UUID = 40; |
||
186 | const INVALID_COUNT = 41; |
||
187 | const INVALID_NOT_EQ = 42; |
||
188 | const INVALID_NOT_SAME = 43; |
||
189 | const INVALID_TRAVERSABLE = 44; |
||
190 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
191 | const INVALID_KEY_ISSET = 46; |
||
192 | const INVALID_VALUE_IN_ARRAY = 47; |
||
193 | const INVALID_DIRECTORY = 101; |
||
194 | const INVALID_FILE = 102; |
||
195 | const INVALID_READABLE = 103; |
||
196 | const INVALID_WRITEABLE = 104; |
||
197 | const INVALID_CLASS = 105; |
||
198 | const INVALID_EMAIL = 201; |
||
199 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
200 | const INVALID_URL = 203; |
||
201 | const INVALID_NOT_INSTANCE_OF = 204; |
||
202 | const VALUE_NOT_EMPTY = 205; |
||
203 | const INVALID_JSON_STRING = 206; |
||
204 | const INVALID_OBJECT = 207; |
||
205 | const INVALID_METHOD = 208; |
||
206 | const INVALID_SCALAR = 209; |
||
207 | const INVALID_LESS = 210; |
||
208 | const INVALID_LESS_OR_EQUAL = 211; |
||
209 | const INVALID_GREATER = 212; |
||
210 | const INVALID_GREATER_OR_EQUAL = 213; |
||
211 | const INVALID_DATE = 214; |
||
212 | const INVALID_CALLABLE = 215; |
||
213 | const INVALID_KEY_NOT_EXISTS = 216; |
||
214 | |||
215 | /** |
||
216 | * Exception to throw when an assertion failed. |
||
217 | * |
||
218 | * @var string |
||
219 | */ |
||
220 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
221 | |||
222 | /** |
||
223 | * Helper method that handles building the assertion failure exceptions. |
||
224 | * They are returned from this method so that the stack trace still shows |
||
225 | * the assertions method. |
||
226 | */ |
||
227 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
232 | |||
233 | /** |
||
234 | * Assert that two values are equal (using == ). |
||
235 | * |
||
236 | * @param mixed $value |
||
237 | * @param mixed $value2 |
||
238 | * @param string|null $message |
||
239 | * @param string|null $propertyPath |
||
240 | * @return void |
||
241 | * @throws \Assert\AssertionFailedException |
||
242 | */ |
||
243 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
255 | |||
256 | /** |
||
257 | * Assert that two values are the same (using ===). |
||
258 | * |
||
259 | * @param mixed $value |
||
260 | * @param mixed $value2 |
||
261 | * @param string|null $message |
||
262 | * @param string|null $propertyPath |
||
263 | * @return void |
||
264 | * @throws \Assert\AssertionFailedException |
||
265 | */ |
||
266 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
278 | |||
279 | /** |
||
280 | * Assert that two values are not equal (using == ). |
||
281 | * |
||
282 | * @param mixed $value1 |
||
283 | * @param mixed $value2 |
||
284 | * @param string|null $message |
||
285 | * @param string|null $propertyPath |
||
286 | * @return void |
||
287 | * @throws \Assert\AssertionFailedException |
||
288 | */ |
||
289 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
300 | |||
301 | /** |
||
302 | * Assert that two values are not the same (using === ). |
||
303 | * |
||
304 | * @param mixed $value1 |
||
305 | * @param mixed $value2 |
||
306 | * @param string|null $message |
||
307 | * @param string|null $propertyPath |
||
308 | * @return void |
||
309 | * @throws \Assert\AssertionFailedException |
||
310 | */ |
||
311 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
322 | |||
323 | /** |
||
324 | * Assert that value is not in array of choices. |
||
325 | * |
||
326 | * @param mixed $value |
||
327 | * @param array $choices |
||
328 | * @param string|null $message |
||
329 | * @param string|null $propertyPath |
||
330 | * @return void |
||
331 | * @throws \Assert\AssertionFailedException |
||
332 | */ |
||
333 | public static function notInArray($value, array $choices, $message = null, $propertyPath = null) |
||
344 | |||
345 | /** |
||
346 | * Assert that value is a php integer. |
||
347 | * |
||
348 | * @param mixed $value |
||
349 | * @param string|null $message |
||
350 | * @param string|null $propertyPath |
||
351 | * @return void |
||
352 | * @throws \Assert\AssertionFailedException |
||
353 | */ |
||
354 | public static function integer($value, $message = null, $propertyPath = null) |
||
365 | |||
366 | /** |
||
367 | * Assert that value is a php float. |
||
368 | * |
||
369 | * @param mixed $value |
||
370 | * @param string|null $message |
||
371 | * @param string|null $propertyPath |
||
372 | * @return void |
||
373 | * @throws \Assert\AssertionFailedException |
||
374 | */ |
||
375 | public static function float($value, $message = null, $propertyPath = null) |
||
386 | |||
387 | /** |
||
388 | * Validates if an integer or integerish is a digit. |
||
389 | * |
||
390 | * @param mixed $value |
||
391 | * @param string|null $message |
||
392 | * @param string|null $propertyPath |
||
393 | * @return void |
||
394 | * @throws \Assert\AssertionFailedException |
||
395 | */ |
||
396 | public static function digit($value, $message = null, $propertyPath = null) |
||
407 | |||
408 | /** |
||
409 | * Assert that value is a php integer'ish. |
||
410 | * |
||
411 | * @param mixed $value |
||
412 | * @param string|null $message |
||
413 | * @param string|null $propertyPath |
||
414 | * @return void |
||
415 | * @throws \Assert\AssertionFailedException |
||
416 | */ |
||
417 | public static function integerish($value, $message = null, $propertyPath = null) |
||
428 | |||
429 | /** |
||
430 | * Assert that value is php boolean |
||
431 | * |
||
432 | * @param mixed $value |
||
433 | * @param string|null $message |
||
434 | * @param string|null $propertyPath |
||
435 | * @return void |
||
436 | * @throws \Assert\AssertionFailedException |
||
437 | */ |
||
438 | public static function boolean($value, $message = null, $propertyPath = null) |
||
449 | |||
450 | /** |
||
451 | * Assert that value is a PHP scalar |
||
452 | * |
||
453 | * @param mixed $value |
||
454 | * @param string|null $message |
||
455 | * @param string|null $propertyPath |
||
456 | * @return void |
||
457 | * @throws \Assert\AssertionFailedException |
||
458 | */ |
||
459 | public static function scalar($value, $message = null, $propertyPath = null) |
||
470 | |||
471 | /** |
||
472 | * Assert that value is not empty |
||
473 | * |
||
474 | * @param mixed $value |
||
475 | * @param string|null $message |
||
476 | * @param string|null $propertyPath |
||
477 | * @return void |
||
478 | * @throws \Assert\AssertionFailedException |
||
479 | */ |
||
480 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
491 | |||
492 | /** |
||
493 | * Assert that value is empty |
||
494 | * |
||
495 | * @param mixed $value |
||
496 | * @param string|null $message |
||
497 | * @param string|null $propertyPath |
||
498 | * @return void |
||
499 | * @throws \Assert\AssertionFailedException |
||
500 | */ |
||
501 | public static function noContent($value, $message = null, $propertyPath = null) |
||
512 | |||
513 | /** |
||
514 | * Assert that value is null |
||
515 | * |
||
516 | * @param mixed $value |
||
517 | * @param string|null $message |
||
518 | * @param string|null $propertyPath |
||
519 | * @return void |
||
520 | * @throws \Assert\AssertionFailedException |
||
521 | */ |
||
522 | public static function null($value, $message = null, $propertyPath = null) |
||
533 | |||
534 | /** |
||
535 | * Assert that value is not null |
||
536 | * |
||
537 | * @param mixed $value |
||
538 | * @param string|null $message |
||
539 | * @param string|null $propertyPath |
||
540 | * @return void |
||
541 | * @throws \Assert\AssertionFailedException |
||
542 | */ |
||
543 | public static function notNull($value, $message = null, $propertyPath = null) |
||
554 | |||
555 | /** |
||
556 | * Assert that value is a string |
||
557 | * |
||
558 | * @param mixed $value |
||
559 | * @param string|null $message |
||
560 | * @param string|null $propertyPath |
||
561 | * @return void |
||
562 | * @throws \Assert\AssertionFailedException |
||
563 | */ |
||
564 | public static function string($value, $message = null, $propertyPath = null) |
||
576 | |||
577 | /** |
||
578 | * Assert that value matches a regex |
||
579 | * |
||
580 | * @param mixed $value |
||
581 | * @param string $pattern |
||
582 | * @param string|null $message |
||
583 | * @param string|null $propertyPath |
||
584 | * @return void |
||
585 | * @throws \Assert\AssertionFailedException |
||
586 | */ |
||
587 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
600 | |||
601 | /** |
||
602 | * Assert that string has a given length. |
||
603 | * |
||
604 | * @param mixed $value |
||
605 | * @param int $length |
||
606 | * @param string|null $message |
||
607 | * @param string|null $propertyPath |
||
608 | * @param string $encoding |
||
609 | * @return void |
||
610 | * @throws \Assert\AssertionFailedException |
||
611 | */ |
||
612 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
628 | |||
629 | /** |
||
630 | * Assert that a string is at least $minLength chars long. |
||
631 | * |
||
632 | * @param mixed $value |
||
633 | * @param int $minLength |
||
634 | * @param string|null $message |
||
635 | * @param string|null $propertyPath |
||
636 | * @param string $encoding |
||
637 | * @return void |
||
638 | * @throws \Assert\AssertionFailedException |
||
639 | */ |
||
640 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
656 | |||
657 | /** |
||
658 | * Assert that string value is not longer than $maxLength chars. |
||
659 | * |
||
660 | * @param mixed $value |
||
661 | * @param integer $maxLength |
||
662 | * @param string|null $message |
||
663 | * @param string|null $propertyPath |
||
664 | * @param string $encoding |
||
665 | * @return void |
||
666 | * @throws \Assert\AssertionFailedException |
||
667 | */ |
||
668 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
684 | |||
685 | /** |
||
686 | * Assert that string length is between min,max lengths. |
||
687 | * |
||
688 | * @param mixed $value |
||
689 | * @param integer $minLength |
||
690 | * @param integer $maxLength |
||
691 | * @param string|null $message |
||
692 | * @param string|null $propertyPath |
||
693 | * @param string $encoding |
||
694 | * @return void |
||
695 | * @throws \Assert\AssertionFailedException |
||
696 | */ |
||
697 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
725 | |||
726 | /** |
||
727 | * Assert that string starts with a sequence of chars. |
||
728 | * |
||
729 | * @param mixed $string |
||
730 | * @param string $needle |
||
731 | * @param string|null $message |
||
732 | * @param string|null $propertyPath |
||
733 | * @param string $encoding |
||
734 | * @return void |
||
735 | * @throws \Assert\AssertionFailedException |
||
736 | */ |
||
737 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
752 | |||
753 | /** |
||
754 | * Assert that string ends with a sequence of chars. |
||
755 | * |
||
756 | * @param mixed $string |
||
757 | * @param string $needle |
||
758 | * @param string|null $message |
||
759 | * @param string|null $propertyPath |
||
760 | * @param string $encoding |
||
761 | * @return void |
||
762 | * @throws \Assert\AssertionFailedException |
||
763 | */ |
||
764 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
781 | |||
782 | /** |
||
783 | * Assert that string contains a sequence of chars. |
||
784 | * |
||
785 | * @param mixed $string |
||
786 | * @param string $needle |
||
787 | * @param string|null $message |
||
788 | * @param string|null $propertyPath |
||
789 | * @param string $encoding |
||
790 | * @return void |
||
791 | * @throws \Assert\AssertionFailedException |
||
792 | */ |
||
793 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
808 | |||
809 | /** |
||
810 | * Assert that value is in array of choices. |
||
811 | * |
||
812 | * @param mixed $value |
||
813 | * @param array $choices |
||
814 | * @param string|null $message |
||
815 | * @param string|null $propertyPath |
||
816 | * @return void |
||
817 | * @throws \Assert\AssertionFailedException |
||
818 | */ |
||
819 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
831 | |||
832 | /** |
||
833 | * Alias of {@see choice()} |
||
834 | * |
||
835 | * @throws \Assert\AssertionFailedException |
||
836 | */ |
||
837 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
841 | |||
842 | /** |
||
843 | * Assert that value is numeric. |
||
844 | * |
||
845 | * @param mixed $value |
||
846 | * @param string|null $message |
||
847 | * @param string|null $propertyPath |
||
848 | * @return void |
||
849 | * @throws \Assert\AssertionFailedException |
||
850 | */ |
||
851 | public static function numeric($value, $message = null, $propertyPath = null) |
||
862 | |||
863 | /** |
||
864 | * Assert that value is an array. |
||
865 | * |
||
866 | * @param mixed $value |
||
867 | * @param string|null $message |
||
868 | * @param string|null $propertyPath |
||
869 | * @return void |
||
870 | * @throws \Assert\AssertionFailedException |
||
871 | */ |
||
872 | public static function isArray($value, $message = null, $propertyPath = null) |
||
883 | |||
884 | /** |
||
885 | * Assert that value is an array or a traversable object. |
||
886 | * |
||
887 | * @param mixed $value |
||
888 | * @param string|null $message |
||
889 | * @param string|null $propertyPath |
||
890 | * @return void |
||
891 | * @throws \Assert\AssertionFailedException |
||
892 | */ |
||
893 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
904 | |||
905 | /** |
||
906 | * Assert that value is an array or an array-accessible object. |
||
907 | * |
||
908 | * @param mixed $value |
||
909 | * @param string|null $message |
||
910 | * @param string|null $propertyPath |
||
911 | * @return void |
||
912 | * @throws \Assert\AssertionFailedException |
||
913 | */ |
||
914 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
925 | |||
926 | /** |
||
927 | * Assert that key exists in an array |
||
928 | * |
||
929 | * @param mixed $value |
||
930 | * @param string|integer $key |
||
931 | * @param string|null $message |
||
932 | * @param string|null $propertyPath |
||
933 | * @return void |
||
934 | * @throws \Assert\AssertionFailedException |
||
935 | */ |
||
936 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
949 | |||
950 | /** |
||
951 | * Assert that key does not exist in an array |
||
952 | * |
||
953 | * @param mixed $value |
||
954 | * @param string|integer $key |
||
955 | * @param string|null $message |
||
956 | * @param string|null $propertyPath |
||
957 | * @return void |
||
958 | * @throws \Assert\AssertionFailedException |
||
959 | */ |
||
960 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null) |
||
973 | |||
974 | /** |
||
975 | * Assert that key exists in an array/array-accessible object using isset() |
||
976 | * |
||
977 | * @param mixed $value |
||
978 | * @param string|integer $key |
||
979 | * @param string|null $message |
||
980 | * @param string|null $propertyPath |
||
981 | * @return void |
||
982 | * @throws \Assert\AssertionFailedException |
||
983 | */ |
||
984 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
997 | |||
998 | /** |
||
999 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
1000 | * |
||
1001 | * @param mixed $value |
||
1002 | * @param string|integer $key |
||
1003 | * @param string|null $message |
||
1004 | * @param string|null $propertyPath |
||
1005 | * @return void |
||
1006 | * @throws \Assert\AssertionFailedException |
||
1007 | */ |
||
1008 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
1013 | |||
1014 | /** |
||
1015 | * Assert that value is not blank |
||
1016 | * |
||
1017 | * @param mixed $value |
||
1018 | * @param string|null $message |
||
1019 | * @param string|null $propertyPath |
||
1020 | * @return void |
||
1021 | * @throws \Assert\AssertionFailedException |
||
1022 | */ |
||
1023 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
1034 | |||
1035 | /** |
||
1036 | * Assert that value is 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 isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1057 | |||
1058 | /** |
||
1059 | * Assert that value is not instance 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 notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1080 | |||
1081 | /** |
||
1082 | * Assert that value is subclass of given class-name. |
||
1083 | * |
||
1084 | * @param mixed $value |
||
1085 | * @param string $className |
||
1086 | * @param string|null $message |
||
1087 | * @param string|null $propertyPath |
||
1088 | * @return void |
||
1089 | * @throws \Assert\AssertionFailedException |
||
1090 | */ |
||
1091 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
1103 | |||
1104 | /** |
||
1105 | * Assert that value is in range of numbers. |
||
1106 | * |
||
1107 | * @param mixed $value |
||
1108 | * @param integer $minValue |
||
1109 | * @param integer $maxValue |
||
1110 | * @param string|null $message |
||
1111 | * @param string|null $propertyPath |
||
1112 | * @return void |
||
1113 | * @throws \Assert\AssertionFailedException |
||
1114 | */ |
||
1115 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
1130 | |||
1131 | /** |
||
1132 | * Assert that a value is at least as big as a given limit |
||
1133 | * |
||
1134 | * @param mixed $value |
||
1135 | * @param mixed $minValue |
||
1136 | * @param string|null $message |
||
1137 | * @param string|null $propertyPath |
||
1138 | * @return void |
||
1139 | * @throws \Assert\AssertionFailedException |
||
1140 | */ |
||
1141 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
1155 | |||
1156 | /** |
||
1157 | * Assert that a number is smaller as a given limit |
||
1158 | * |
||
1159 | * @param mixed $value |
||
1160 | * @param mixed $maxValue |
||
1161 | * @param string|null $message |
||
1162 | * @param string|null $propertyPath |
||
1163 | * @return void |
||
1164 | * @throws \Assert\AssertionFailedException |
||
1165 | */ |
||
1166 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
1180 | |||
1181 | /** |
||
1182 | * Assert that a file exists |
||
1183 | * |
||
1184 | * @param string $value |
||
1185 | * @param string|null $message |
||
1186 | * @param string|null $propertyPath |
||
1187 | * @return void |
||
1188 | * @throws \Assert\AssertionFailedException |
||
1189 | */ |
||
1190 | public static function file($value, $message = null, $propertyPath = null) |
||
1204 | |||
1205 | /** |
||
1206 | * Assert that a directory exists |
||
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 directory($value, $message = null, $propertyPath = null) |
||
1227 | |||
1228 | /** |
||
1229 | * Assert that the value is something readable |
||
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 readable($value, $message = null, $propertyPath = null) |
||
1250 | |||
1251 | /** |
||
1252 | * Assert that the value is something writeable |
||
1253 | * |
||
1254 | * @param string $value |
||
1255 | * @param string|null $message |
||
1256 | * @param string|null $propertyPath |
||
1257 | * @return void |
||
1258 | * @throws \Assert\AssertionFailedException |
||
1259 | */ |
||
1260 | public static function writeable($value, $message = null, $propertyPath = null) |
||
1273 | |||
1274 | /** |
||
1275 | * Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL). |
||
1276 | * |
||
1277 | * @param mixed $value |
||
1278 | * @param string|null $message |
||
1279 | * @param string|null $propertyPath |
||
1280 | * @return void |
||
1281 | * @throws \Assert\AssertionFailedException |
||
1282 | */ |
||
1283 | public static function email($value, $message = null, $propertyPath = null) |
||
1308 | |||
1309 | /** |
||
1310 | * Assert that value is an URL. |
||
1311 | * |
||
1312 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
1313 | * |
||
1314 | * @param mixed $value |
||
1315 | * @param string|null $message |
||
1316 | * @param string|null $propertyPath |
||
1317 | * @return void |
||
1318 | * @throws \Assert\AssertionFailedException |
||
1319 | * |
||
1320 | * |
||
1321 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
1322 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
1323 | */ |
||
1324 | public static function url($value, $message = null, $propertyPath = null) |
||
1357 | |||
1358 | /** |
||
1359 | * Assert that value is alphanumeric. |
||
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 alnum($value, $message = null, $propertyPath = null) |
||
1380 | |||
1381 | /** |
||
1382 | * Assert that the value is boolean True. |
||
1383 | * |
||
1384 | * @param mixed $value |
||
1385 | * @param string|null $message |
||
1386 | * @param string|null $propertyPath |
||
1387 | * @return void |
||
1388 | * @throws \Assert\AssertionFailedException |
||
1389 | */ |
||
1390 | public static function true($value, $message = null, $propertyPath = null) |
||
1401 | |||
1402 | /** |
||
1403 | * Assert that the value is boolean False. |
||
1404 | * |
||
1405 | * @param mixed $value |
||
1406 | * @param string|null $message |
||
1407 | * @param string|null $propertyPath |
||
1408 | * @return void |
||
1409 | * @throws \Assert\AssertionFailedException |
||
1410 | */ |
||
1411 | public static function false($value, $message = null, $propertyPath = null) |
||
1422 | |||
1423 | /** |
||
1424 | * Assert that the class exists. |
||
1425 | * |
||
1426 | * @param mixed $value |
||
1427 | * @param string|null $message |
||
1428 | * @param string|null $propertyPath |
||
1429 | * @return void |
||
1430 | * @throws \Assert\AssertionFailedException |
||
1431 | */ |
||
1432 | public static function classExists($value, $message = null, $propertyPath = null) |
||
1443 | |||
1444 | /** |
||
1445 | * Assert that the class implements the interface |
||
1446 | * |
||
1447 | * @param mixed $class |
||
1448 | * @param string $interfaceName |
||
1449 | * @param string|null $message |
||
1450 | * @param string|null $propertyPath |
||
1451 | * @return void |
||
1452 | * @throws \Assert\AssertionFailedException |
||
1453 | */ |
||
1454 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
1467 | |||
1468 | /** |
||
1469 | * Assert that the given string is a valid json string. |
||
1470 | * |
||
1471 | * NOTICE: |
||
1472 | * Since this does a json_decode to determine its validity |
||
1473 | * you probably should consider, when using the variable |
||
1474 | * content afterwards, just to decode and check for yourself instead |
||
1475 | * of using this assertion. |
||
1476 | * |
||
1477 | * @param mixed $value |
||
1478 | * @param string|null $message |
||
1479 | * @param string|null $propertyPath |
||
1480 | * @return void |
||
1481 | * @throws \Assert\AssertionFailedException |
||
1482 | */ |
||
1483 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
1494 | |||
1495 | /** |
||
1496 | * Assert that the given string is a valid UUID |
||
1497 | * |
||
1498 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
1499 | * |
||
1500 | * @param string $value |
||
1501 | * @param string|null $message |
||
1502 | * @param string|null $propertyPath |
||
1503 | * @return void |
||
1504 | * @throws \Assert\AssertionFailedException |
||
1505 | */ |
||
1506 | public static function uuid($value, $message = null, $propertyPath = null) |
||
1523 | |||
1524 | /** |
||
1525 | * Assert that the count of countable is equal to count. |
||
1526 | * |
||
1527 | * @param array|\Countable $countable |
||
1528 | * @param int $count |
||
1529 | * @param string $message |
||
1530 | * @param string $propertyPath |
||
1531 | * @return void |
||
1532 | * @throws \Assert\AssertionFailedException |
||
1533 | */ |
||
1534 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
1545 | |||
1546 | /** |
||
1547 | * static call handler to implement: |
||
1548 | * - "null or assertion" delegation |
||
1549 | * - "all" delegation |
||
1550 | */ |
||
1551 | public static function __callStatic($method, $args) |
||
1587 | |||
1588 | /** |
||
1589 | * Determines if the values array has every choice as key and that this choice has content. |
||
1590 | * |
||
1591 | * @param array $values |
||
1592 | * @param array $choices |
||
1593 | * @param null $message |
||
1594 | * @param null $propertyPath |
||
1595 | */ |
||
1596 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
1605 | |||
1606 | /** |
||
1607 | * Determines that the named method is defined in the provided object. |
||
1608 | * |
||
1609 | * @param string $value |
||
1610 | * @param mixed $object |
||
1611 | * @param null $message |
||
1612 | * @param null $propertyPath |
||
1613 | * |
||
1614 | * @throws |
||
1615 | */ |
||
1616 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
1629 | |||
1630 | /** |
||
1631 | * Determines that the provided value is an object. |
||
1632 | * |
||
1633 | * @param mixed $value |
||
1634 | * @param null $message |
||
1635 | * @param null $propertyPath |
||
1636 | */ |
||
1637 | public static function isObject($value, $message = null, $propertyPath = null) |
||
1649 | |||
1650 | /** |
||
1651 | * Determines if the value is less than given limit. |
||
1652 | * |
||
1653 | * @param mixed $value |
||
1654 | * @param mixed $limit |
||
1655 | * @param null $message |
||
1656 | * @param null $propertyPath |
||
1657 | */ |
||
1658 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
1670 | |||
1671 | /** |
||
1672 | * Determines if the value is less or than given limit. |
||
1673 | * |
||
1674 | * @param mixed $value |
||
1675 | * @param mixed $limit |
||
1676 | * @param null $message |
||
1677 | * @param null $propertyPath |
||
1678 | */ |
||
1679 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1691 | |||
1692 | /** |
||
1693 | * Determines if the value is greater than given limit. |
||
1694 | * |
||
1695 | * @param mixed $value |
||
1696 | * @param mixed $limit |
||
1697 | * @param null $message |
||
1698 | * @param null $propertyPath |
||
1699 | */ |
||
1700 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
1712 | |||
1713 | /** |
||
1714 | * Determines if the value is greater or equal than given limit. |
||
1715 | * |
||
1716 | * @param mixed $value |
||
1717 | * @param mixed $limit |
||
1718 | * @param null $message |
||
1719 | * @param null $propertyPath |
||
1720 | */ |
||
1721 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1733 | |||
1734 | /** |
||
1735 | * Assert that date is valid and corresponds to the given format. |
||
1736 | * |
||
1737 | * @param string $value |
||
1738 | * @param string $format supports all of the options date(), except for the following: |
||
1739 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
1740 | * @param string|null $message |
||
1741 | * @param string|null $propertyPath |
||
1742 | * |
||
1743 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
1744 | */ |
||
1745 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
1762 | |||
1763 | /** |
||
1764 | * Determines that the provided value is callable. |
||
1765 | * |
||
1766 | * @param mixed $value |
||
1767 | * @param null $message |
||
1768 | * @param null $propertyPath |
||
1769 | */ |
||
1770 | public static function isCallable($value, $message = null, $propertyPath = null) |
||
1781 | |||
1782 | /** |
||
1783 | * Make a string version of a value. |
||
1784 | * |
||
1785 | * @param mixed $value |
||
1786 | * @return string |
||
1787 | */ |
||
1788 | protected static function stringify($value) |
||
1822 | } |
||
1823 |