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 |
||
156 | class Assertion |
||
157 | { |
||
158 | const INVALID_FLOAT = 9; |
||
159 | const INVALID_INTEGER = 10; |
||
160 | const INVALID_DIGIT = 11; |
||
161 | const INVALID_INTEGERISH = 12; |
||
162 | const INVALID_BOOLEAN = 13; |
||
163 | const VALUE_EMPTY = 14; |
||
164 | const VALUE_NULL = 15; |
||
165 | const VALUE_NOT_NULL = 25; |
||
166 | const INVALID_STRING = 16; |
||
167 | const INVALID_REGEX = 17; |
||
168 | const INVALID_MIN_LENGTH = 18; |
||
169 | const INVALID_MAX_LENGTH = 19; |
||
170 | const INVALID_STRING_START = 20; |
||
171 | const INVALID_STRING_CONTAINS = 21; |
||
172 | const INVALID_CHOICE = 22; |
||
173 | const INVALID_NUMERIC = 23; |
||
174 | const INVALID_ARRAY = 24; |
||
175 | const INVALID_KEY_EXISTS = 26; |
||
176 | const INVALID_NOT_BLANK = 27; |
||
177 | const INVALID_INSTANCE_OF = 28; |
||
178 | const INVALID_SUBCLASS_OF = 29; |
||
179 | const INVALID_RANGE = 30; |
||
180 | const INVALID_ALNUM = 31; |
||
181 | const INVALID_TRUE = 32; |
||
182 | const INVALID_EQ = 33; |
||
183 | const INVALID_SAME = 34; |
||
184 | const INVALID_MIN = 35; |
||
185 | const INVALID_MAX = 36; |
||
186 | const INVALID_LENGTH = 37; |
||
187 | const INVALID_FALSE = 38; |
||
188 | const INVALID_STRING_END = 39; |
||
189 | const INVALID_UUID = 40; |
||
190 | const INVALID_COUNT = 41; |
||
191 | const INVALID_NOT_EQ = 42; |
||
192 | const INVALID_NOT_SAME = 43; |
||
193 | const INVALID_TRAVERSABLE = 44; |
||
194 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
195 | const INVALID_KEY_ISSET = 46; |
||
196 | const INVALID_VALUE_IN_ARRAY = 47; |
||
197 | const INVALID_DIRECTORY = 101; |
||
198 | const INVALID_FILE = 102; |
||
199 | const INVALID_READABLE = 103; |
||
200 | const INVALID_WRITEABLE = 104; |
||
201 | const INVALID_CLASS = 105; |
||
202 | const INVALID_INTERFACE = 106; |
||
203 | const INVALID_EMAIL = 201; |
||
204 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
205 | const INVALID_URL = 203; |
||
206 | const INVALID_NOT_INSTANCE_OF = 204; |
||
207 | const VALUE_NOT_EMPTY = 205; |
||
208 | const INVALID_JSON_STRING = 206; |
||
209 | const INVALID_OBJECT = 207; |
||
210 | const INVALID_METHOD = 208; |
||
211 | const INVALID_SCALAR = 209; |
||
212 | const INVALID_LESS = 210; |
||
213 | const INVALID_LESS_OR_EQUAL = 211; |
||
214 | const INVALID_GREATER = 212; |
||
215 | const INVALID_GREATER_OR_EQUAL = 213; |
||
216 | const INVALID_DATE = 214; |
||
217 | const INVALID_CALLABLE = 215; |
||
218 | const INVALID_KEY_NOT_EXISTS = 216; |
||
219 | const INVALID_SATISFY = 217; |
||
220 | |||
221 | /** |
||
222 | * Exception to throw when an assertion failed. |
||
223 | * |
||
224 | * @var string |
||
225 | */ |
||
226 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
227 | |||
228 | /** |
||
229 | * Helper method that handles building the assertion failure exceptions. |
||
230 | * They are returned from this method so that the stack trace still shows |
||
231 | * the assertions method. |
||
232 | */ |
||
233 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
238 | |||
239 | /** |
||
240 | * Assert that two values are equal (using == ). |
||
241 | * |
||
242 | * @param mixed $value |
||
243 | * @param mixed $value2 |
||
244 | * @param string|null $message |
||
245 | * @param string|null $propertyPath |
||
246 | * @return void |
||
247 | * @throws \Assert\AssertionFailedException |
||
248 | */ |
||
249 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
261 | |||
262 | /** |
||
263 | * Assert that two values are the same (using ===). |
||
264 | * |
||
265 | * @param mixed $value |
||
266 | * @param mixed $value2 |
||
267 | * @param string|null $message |
||
268 | * @param string|null $propertyPath |
||
269 | * @return void |
||
270 | * @throws \Assert\AssertionFailedException |
||
271 | */ |
||
272 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
284 | |||
285 | /** |
||
286 | * Assert that two values are not equal (using == ). |
||
287 | * |
||
288 | * @param mixed $value1 |
||
289 | * @param mixed $value2 |
||
290 | * @param string|null $message |
||
291 | * @param string|null $propertyPath |
||
292 | * @return void |
||
293 | * @throws \Assert\AssertionFailedException |
||
294 | */ |
||
295 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
306 | |||
307 | /** |
||
308 | * Assert that two values are not the same (using === ). |
||
309 | * |
||
310 | * @param mixed $value1 |
||
311 | * @param mixed $value2 |
||
312 | * @param string|null $message |
||
313 | * @param string|null $propertyPath |
||
314 | * @return void |
||
315 | * @throws \Assert\AssertionFailedException |
||
316 | */ |
||
317 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
328 | |||
329 | /** |
||
330 | * Assert that value is not in array of choices. |
||
331 | * |
||
332 | * @param mixed $value |
||
333 | * @param array $choices |
||
334 | * @param string|null $message |
||
335 | * @param string|null $propertyPath |
||
336 | * @return void |
||
337 | * @throws \Assert\AssertionFailedException |
||
338 | */ |
||
339 | public static function notInArray($value, array $choices, $message = null, $propertyPath = null) |
||
350 | |||
351 | /** |
||
352 | * Assert that value is a php integer. |
||
353 | * |
||
354 | * @param mixed $value |
||
355 | * @param string|null $message |
||
356 | * @param string|null $propertyPath |
||
357 | * @return void |
||
358 | * @throws \Assert\AssertionFailedException |
||
359 | */ |
||
360 | public static function integer($value, $message = null, $propertyPath = null) |
||
371 | |||
372 | /** |
||
373 | * Assert that value is a php float. |
||
374 | * |
||
375 | * @param mixed $value |
||
376 | * @param string|null $message |
||
377 | * @param string|null $propertyPath |
||
378 | * @return void |
||
379 | * @throws \Assert\AssertionFailedException |
||
380 | */ |
||
381 | public static function float($value, $message = null, $propertyPath = null) |
||
392 | |||
393 | /** |
||
394 | * Validates if an integer or integerish is a digit. |
||
395 | * |
||
396 | * @param mixed $value |
||
397 | * @param string|null $message |
||
398 | * @param string|null $propertyPath |
||
399 | * @return void |
||
400 | * @throws \Assert\AssertionFailedException |
||
401 | */ |
||
402 | public static function digit($value, $message = null, $propertyPath = null) |
||
413 | |||
414 | /** |
||
415 | * Assert that value is a php integer'ish. |
||
416 | * |
||
417 | * @param mixed $value |
||
418 | * @param string|null $message |
||
419 | * @param string|null $propertyPath |
||
420 | * @return void |
||
421 | * @throws \Assert\AssertionFailedException |
||
422 | */ |
||
423 | public static function integerish($value, $message = null, $propertyPath = null) |
||
434 | |||
435 | /** |
||
436 | * Assert that value is php boolean |
||
437 | * |
||
438 | * @param mixed $value |
||
439 | * @param string|null $message |
||
440 | * @param string|null $propertyPath |
||
441 | * @return void |
||
442 | * @throws \Assert\AssertionFailedException |
||
443 | */ |
||
444 | public static function boolean($value, $message = null, $propertyPath = null) |
||
455 | |||
456 | /** |
||
457 | * Assert that value is a PHP scalar |
||
458 | * |
||
459 | * @param mixed $value |
||
460 | * @param string|null $message |
||
461 | * @param string|null $propertyPath |
||
462 | * @return void |
||
463 | * @throws \Assert\AssertionFailedException |
||
464 | */ |
||
465 | public static function scalar($value, $message = null, $propertyPath = null) |
||
476 | |||
477 | /** |
||
478 | * Assert that value is not empty |
||
479 | * |
||
480 | * @param mixed $value |
||
481 | * @param string|null $message |
||
482 | * @param string|null $propertyPath |
||
483 | * @return void |
||
484 | * @throws \Assert\AssertionFailedException |
||
485 | */ |
||
486 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
497 | |||
498 | /** |
||
499 | * Assert that value is empty |
||
500 | * |
||
501 | * @param mixed $value |
||
502 | * @param string|null $message |
||
503 | * @param string|null $propertyPath |
||
504 | * @return void |
||
505 | * @throws \Assert\AssertionFailedException |
||
506 | */ |
||
507 | public static function noContent($value, $message = null, $propertyPath = null) |
||
518 | |||
519 | /** |
||
520 | * Assert that value is null |
||
521 | * |
||
522 | * @param mixed $value |
||
523 | * @param string|null $message |
||
524 | * @param string|null $propertyPath |
||
525 | * @return void |
||
526 | * @throws \Assert\AssertionFailedException |
||
527 | */ |
||
528 | public static function null($value, $message = null, $propertyPath = null) |
||
539 | |||
540 | /** |
||
541 | * Assert that value is not null |
||
542 | * |
||
543 | * @param mixed $value |
||
544 | * @param string|null $message |
||
545 | * @param string|null $propertyPath |
||
546 | * @return void |
||
547 | * @throws \Assert\AssertionFailedException |
||
548 | */ |
||
549 | public static function notNull($value, $message = null, $propertyPath = null) |
||
560 | |||
561 | /** |
||
562 | * Assert that value is a string |
||
563 | * |
||
564 | * @param mixed $value |
||
565 | * @param string|null $message |
||
566 | * @param string|null $propertyPath |
||
567 | * @return void |
||
568 | * @throws \Assert\AssertionFailedException |
||
569 | */ |
||
570 | public static function string($value, $message = null, $propertyPath = null) |
||
582 | |||
583 | /** |
||
584 | * Assert that value matches a regex |
||
585 | * |
||
586 | * @param mixed $value |
||
587 | * @param string $pattern |
||
588 | * @param string|null $message |
||
589 | * @param string|null $propertyPath |
||
590 | * @return void |
||
591 | * @throws \Assert\AssertionFailedException |
||
592 | */ |
||
593 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
606 | |||
607 | /** |
||
608 | * Assert that string has a given length. |
||
609 | * |
||
610 | * @param mixed $value |
||
611 | * @param int $length |
||
612 | * @param string|null $message |
||
613 | * @param string|null $propertyPath |
||
614 | * @param string $encoding |
||
615 | * @return void |
||
616 | * @throws \Assert\AssertionFailedException |
||
617 | */ |
||
618 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
634 | |||
635 | /** |
||
636 | * Assert that a string is at least $minLength chars long. |
||
637 | * |
||
638 | * @param mixed $value |
||
639 | * @param int $minLength |
||
640 | * @param string|null $message |
||
641 | * @param string|null $propertyPath |
||
642 | * @param string $encoding |
||
643 | * @return void |
||
644 | * @throws \Assert\AssertionFailedException |
||
645 | */ |
||
646 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
662 | |||
663 | /** |
||
664 | * Assert that string value is not longer than $maxLength chars. |
||
665 | * |
||
666 | * @param mixed $value |
||
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 maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
690 | |||
691 | /** |
||
692 | * Assert that string length is between min,max lengths. |
||
693 | * |
||
694 | * @param mixed $value |
||
695 | * @param integer $minLength |
||
696 | * @param integer $maxLength |
||
697 | * @param string|null $message |
||
698 | * @param string|null $propertyPath |
||
699 | * @param string $encoding |
||
700 | * @return void |
||
701 | * @throws \Assert\AssertionFailedException |
||
702 | */ |
||
703 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
731 | |||
732 | /** |
||
733 | * Assert that string starts with a sequence of chars. |
||
734 | * |
||
735 | * @param mixed $string |
||
736 | * @param string $needle |
||
737 | * @param string|null $message |
||
738 | * @param string|null $propertyPath |
||
739 | * @param string $encoding |
||
740 | * @return void |
||
741 | * @throws \Assert\AssertionFailedException |
||
742 | */ |
||
743 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
758 | |||
759 | /** |
||
760 | * Assert that string ends with 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 endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
787 | |||
788 | /** |
||
789 | * Assert that string contains a sequence of chars. |
||
790 | * |
||
791 | * @param mixed $string |
||
792 | * @param string $needle |
||
793 | * @param string|null $message |
||
794 | * @param string|null $propertyPath |
||
795 | * @param string $encoding |
||
796 | * @return void |
||
797 | * @throws \Assert\AssertionFailedException |
||
798 | */ |
||
799 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
814 | |||
815 | /** |
||
816 | * Assert that value is in array of choices. |
||
817 | * |
||
818 | * @param mixed $value |
||
819 | * @param array $choices |
||
820 | * @param string|null $message |
||
821 | * @param string|null $propertyPath |
||
822 | * @return void |
||
823 | * @throws \Assert\AssertionFailedException |
||
824 | */ |
||
825 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
837 | |||
838 | /** |
||
839 | * Alias of {@see choice()} |
||
840 | * |
||
841 | * @throws \Assert\AssertionFailedException |
||
842 | */ |
||
843 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
847 | |||
848 | /** |
||
849 | * Assert that value is numeric. |
||
850 | * |
||
851 | * @param mixed $value |
||
852 | * @param string|null $message |
||
853 | * @param string|null $propertyPath |
||
854 | * @return void |
||
855 | * @throws \Assert\AssertionFailedException |
||
856 | */ |
||
857 | public static function numeric($value, $message = null, $propertyPath = null) |
||
868 | |||
869 | /** |
||
870 | * Assert that value is an array. |
||
871 | * |
||
872 | * @param mixed $value |
||
873 | * @param string|null $message |
||
874 | * @param string|null $propertyPath |
||
875 | * @return void |
||
876 | * @throws \Assert\AssertionFailedException |
||
877 | */ |
||
878 | public static function isArray($value, $message = null, $propertyPath = null) |
||
889 | |||
890 | /** |
||
891 | * Assert that value is an array or a traversable object. |
||
892 | * |
||
893 | * @param mixed $value |
||
894 | * @param string|null $message |
||
895 | * @param string|null $propertyPath |
||
896 | * @return void |
||
897 | * @throws \Assert\AssertionFailedException |
||
898 | */ |
||
899 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
910 | |||
911 | /** |
||
912 | * Assert that value is an array or an array-accessible object. |
||
913 | * |
||
914 | * @param mixed $value |
||
915 | * @param string|null $message |
||
916 | * @param string|null $propertyPath |
||
917 | * @return void |
||
918 | * @throws \Assert\AssertionFailedException |
||
919 | */ |
||
920 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
931 | |||
932 | /** |
||
933 | * Assert that key exists in an array |
||
934 | * |
||
935 | * @param mixed $value |
||
936 | * @param string|integer $key |
||
937 | * @param string|null $message |
||
938 | * @param string|null $propertyPath |
||
939 | * @return void |
||
940 | * @throws \Assert\AssertionFailedException |
||
941 | */ |
||
942 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
955 | |||
956 | /** |
||
957 | * Assert that key does not exist in an array |
||
958 | * |
||
959 | * @param mixed $value |
||
960 | * @param string|integer $key |
||
961 | * @param string|null $message |
||
962 | * @param string|null $propertyPath |
||
963 | * @return void |
||
964 | * @throws \Assert\AssertionFailedException |
||
965 | */ |
||
966 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null) |
||
979 | |||
980 | /** |
||
981 | * Assert that key exists in an array/array-accessible object using isset() |
||
982 | * |
||
983 | * @param mixed $value |
||
984 | * @param string|integer $key |
||
985 | * @param string|null $message |
||
986 | * @param string|null $propertyPath |
||
987 | * @return void |
||
988 | * @throws \Assert\AssertionFailedException |
||
989 | */ |
||
990 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
1003 | |||
1004 | /** |
||
1005 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
1006 | * |
||
1007 | * @param mixed $value |
||
1008 | * @param string|integer $key |
||
1009 | * @param string|null $message |
||
1010 | * @param string|null $propertyPath |
||
1011 | * @return void |
||
1012 | * @throws \Assert\AssertionFailedException |
||
1013 | */ |
||
1014 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
1019 | |||
1020 | /** |
||
1021 | * Assert that value is not blank |
||
1022 | * |
||
1023 | * @param mixed $value |
||
1024 | * @param string|null $message |
||
1025 | * @param string|null $propertyPath |
||
1026 | * @return void |
||
1027 | * @throws \Assert\AssertionFailedException |
||
1028 | */ |
||
1029 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
1040 | |||
1041 | /** |
||
1042 | * Assert that value is instance of given class-name. |
||
1043 | * |
||
1044 | * @param mixed $value |
||
1045 | * @param string $className |
||
1046 | * @param string|null $message |
||
1047 | * @param string|null $propertyPath |
||
1048 | * @return void |
||
1049 | * @throws \Assert\AssertionFailedException |
||
1050 | */ |
||
1051 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1063 | |||
1064 | /** |
||
1065 | * Assert that value is not instance of given class-name. |
||
1066 | * |
||
1067 | * @param mixed $value |
||
1068 | * @param string $className |
||
1069 | * @param string|null $message |
||
1070 | * @param string|null $propertyPath |
||
1071 | * @return void |
||
1072 | * @throws \Assert\AssertionFailedException |
||
1073 | */ |
||
1074 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1086 | |||
1087 | /** |
||
1088 | * Assert that value is subclass of given class-name. |
||
1089 | * |
||
1090 | * @param mixed $value |
||
1091 | * @param string $className |
||
1092 | * @param string|null $message |
||
1093 | * @param string|null $propertyPath |
||
1094 | * @return void |
||
1095 | * @throws \Assert\AssertionFailedException |
||
1096 | */ |
||
1097 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
1109 | |||
1110 | /** |
||
1111 | * Assert that value is in range of numbers. |
||
1112 | * |
||
1113 | * @param mixed $value |
||
1114 | * @param integer $minValue |
||
1115 | * @param integer $maxValue |
||
1116 | * @param string|null $message |
||
1117 | * @param string|null $propertyPath |
||
1118 | * @return void |
||
1119 | * @throws \Assert\AssertionFailedException |
||
1120 | */ |
||
1121 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
1136 | |||
1137 | /** |
||
1138 | * Assert that a value is at least as big as a given limit |
||
1139 | * |
||
1140 | * @param mixed $value |
||
1141 | * @param mixed $minValue |
||
1142 | * @param string|null $message |
||
1143 | * @param string|null $propertyPath |
||
1144 | * @return void |
||
1145 | * @throws \Assert\AssertionFailedException |
||
1146 | */ |
||
1147 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
1161 | |||
1162 | /** |
||
1163 | * Assert that a number is smaller as a given limit |
||
1164 | * |
||
1165 | * @param mixed $value |
||
1166 | * @param mixed $maxValue |
||
1167 | * @param string|null $message |
||
1168 | * @param string|null $propertyPath |
||
1169 | * @return void |
||
1170 | * @throws \Assert\AssertionFailedException |
||
1171 | */ |
||
1172 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
1186 | |||
1187 | /** |
||
1188 | * Assert that a file exists |
||
1189 | * |
||
1190 | * @param string $value |
||
1191 | * @param string|null $message |
||
1192 | * @param string|null $propertyPath |
||
1193 | * @return void |
||
1194 | * @throws \Assert\AssertionFailedException |
||
1195 | */ |
||
1196 | public static function file($value, $message = null, $propertyPath = null) |
||
1210 | |||
1211 | /** |
||
1212 | * Assert that a directory exists |
||
1213 | * |
||
1214 | * @param string $value |
||
1215 | * @param string|null $message |
||
1216 | * @param string|null $propertyPath |
||
1217 | * @return void |
||
1218 | * @throws \Assert\AssertionFailedException |
||
1219 | */ |
||
1220 | public static function directory($value, $message = null, $propertyPath = null) |
||
1233 | |||
1234 | /** |
||
1235 | * Assert that the value is something readable |
||
1236 | * |
||
1237 | * @param string $value |
||
1238 | * @param string|null $message |
||
1239 | * @param string|null $propertyPath |
||
1240 | * @return void |
||
1241 | * @throws \Assert\AssertionFailedException |
||
1242 | */ |
||
1243 | public static function readable($value, $message = null, $propertyPath = null) |
||
1256 | |||
1257 | /** |
||
1258 | * Assert that the value is something writeable |
||
1259 | * |
||
1260 | * @param string $value |
||
1261 | * @param string|null $message |
||
1262 | * @param string|null $propertyPath |
||
1263 | * @return void |
||
1264 | * @throws \Assert\AssertionFailedException |
||
1265 | */ |
||
1266 | public static function writeable($value, $message = null, $propertyPath = null) |
||
1279 | |||
1280 | /** |
||
1281 | * Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL). |
||
1282 | * |
||
1283 | * @param mixed $value |
||
1284 | * @param string|null $message |
||
1285 | * @param string|null $propertyPath |
||
1286 | * @return void |
||
1287 | * @throws \Assert\AssertionFailedException |
||
1288 | */ |
||
1289 | public static function email($value, $message = null, $propertyPath = null) |
||
1314 | |||
1315 | /** |
||
1316 | * Assert that value is an URL. |
||
1317 | * |
||
1318 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
1319 | * |
||
1320 | * @param mixed $value |
||
1321 | * @param string|null $message |
||
1322 | * @param string|null $propertyPath |
||
1323 | * @return void |
||
1324 | * @throws \Assert\AssertionFailedException |
||
1325 | * |
||
1326 | * |
||
1327 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
1328 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
1329 | */ |
||
1330 | public static function url($value, $message = null, $propertyPath = null) |
||
1363 | |||
1364 | /** |
||
1365 | * Assert that value is alphanumeric. |
||
1366 | * |
||
1367 | * @param mixed $value |
||
1368 | * @param string|null $message |
||
1369 | * @param string|null $propertyPath |
||
1370 | * @return void |
||
1371 | * @throws \Assert\AssertionFailedException |
||
1372 | */ |
||
1373 | public static function alnum($value, $message = null, $propertyPath = null) |
||
1386 | |||
1387 | /** |
||
1388 | * Assert that the value is boolean True. |
||
1389 | * |
||
1390 | * @param mixed $value |
||
1391 | * @param string|null $message |
||
1392 | * @param string|null $propertyPath |
||
1393 | * @return void |
||
1394 | * @throws \Assert\AssertionFailedException |
||
1395 | */ |
||
1396 | public static function true($value, $message = null, $propertyPath = null) |
||
1407 | |||
1408 | /** |
||
1409 | * Assert that the value is boolean False. |
||
1410 | * |
||
1411 | * @param mixed $value |
||
1412 | * @param string|null $message |
||
1413 | * @param string|null $propertyPath |
||
1414 | * @return void |
||
1415 | * @throws \Assert\AssertionFailedException |
||
1416 | */ |
||
1417 | public static function false($value, $message = null, $propertyPath = null) |
||
1428 | |||
1429 | /** |
||
1430 | * Assert that the class exists. |
||
1431 | * |
||
1432 | * @param mixed $value |
||
1433 | * @param string|null $message |
||
1434 | * @param string|null $propertyPath |
||
1435 | * @return void |
||
1436 | * @throws \Assert\AssertionFailedException |
||
1437 | */ |
||
1438 | public static function classExists($value, $message = null, $propertyPath = null) |
||
1449 | |||
1450 | /** |
||
1451 | * Assert that the interface exists. |
||
1452 | * |
||
1453 | * @param mixed $value |
||
1454 | * @param string|null $message |
||
1455 | * @param string|null $propertyPath |
||
1456 | * @return void |
||
1457 | * @throws \Assert\AssertionFailedException |
||
1458 | */ |
||
1459 | public static function interfaceExists($value, $message = null, $propertyPath = null) |
||
1470 | |||
1471 | /** |
||
1472 | * Assert that the class implements the interface |
||
1473 | * |
||
1474 | * @param mixed $class |
||
1475 | * @param string $interfaceName |
||
1476 | * @param string|null $message |
||
1477 | * @param string|null $propertyPath |
||
1478 | * @return void |
||
1479 | * @throws \Assert\AssertionFailedException |
||
1480 | */ |
||
1481 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
1494 | |||
1495 | /** |
||
1496 | * Assert that the given string is a valid json string. |
||
1497 | * |
||
1498 | * NOTICE: |
||
1499 | * Since this does a json_decode to determine its validity |
||
1500 | * you probably should consider, when using the variable |
||
1501 | * content afterwards, just to decode and check for yourself instead |
||
1502 | * of using this assertion. |
||
1503 | * |
||
1504 | * @param mixed $value |
||
1505 | * @param string|null $message |
||
1506 | * @param string|null $propertyPath |
||
1507 | * @return void |
||
1508 | * @throws \Assert\AssertionFailedException |
||
1509 | */ |
||
1510 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
1521 | |||
1522 | /** |
||
1523 | * Assert that the given string is a valid UUID |
||
1524 | * |
||
1525 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
1526 | * |
||
1527 | * @param string $value |
||
1528 | * @param string|null $message |
||
1529 | * @param string|null $propertyPath |
||
1530 | * @return void |
||
1531 | * @throws \Assert\AssertionFailedException |
||
1532 | */ |
||
1533 | public static function uuid($value, $message = null, $propertyPath = null) |
||
1550 | |||
1551 | /** |
||
1552 | * Assert that the count of countable is equal to count. |
||
1553 | * |
||
1554 | * @param array|\Countable $countable |
||
1555 | * @param int $count |
||
1556 | * @param string $message |
||
1557 | * @param string $propertyPath |
||
1558 | * @return void |
||
1559 | * @throws \Assert\AssertionFailedException |
||
1560 | */ |
||
1561 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
1572 | |||
1573 | /** |
||
1574 | * static call handler to implement: |
||
1575 | * - "null or assertion" delegation |
||
1576 | * - "all" delegation |
||
1577 | */ |
||
1578 | public static function __callStatic($method, $args) |
||
1614 | |||
1615 | /** |
||
1616 | * Determines if the values array has every choice as key and that this choice has content. |
||
1617 | * |
||
1618 | * @param array $values |
||
1619 | * @param array $choices |
||
1620 | * @param null $message |
||
1621 | * @param null $propertyPath |
||
1622 | */ |
||
1623 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
1632 | |||
1633 | /** |
||
1634 | * Determines that the named method is defined in the provided object. |
||
1635 | * |
||
1636 | * @param string $value |
||
1637 | * @param mixed $object |
||
1638 | * @param null $message |
||
1639 | * @param null $propertyPath |
||
1640 | * |
||
1641 | * @throws |
||
1642 | */ |
||
1643 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
1656 | |||
1657 | /** |
||
1658 | * Determines that the provided value is an object. |
||
1659 | * |
||
1660 | * @param mixed $value |
||
1661 | * @param null $message |
||
1662 | * @param null $propertyPath |
||
1663 | */ |
||
1664 | public static function isObject($value, $message = null, $propertyPath = null) |
||
1676 | |||
1677 | /** |
||
1678 | * Determines if the value is less than given limit. |
||
1679 | * |
||
1680 | * @param mixed $value |
||
1681 | * @param mixed $limit |
||
1682 | * @param null $message |
||
1683 | * @param null $propertyPath |
||
1684 | */ |
||
1685 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
1697 | |||
1698 | /** |
||
1699 | * Determines if the value is less or than given limit. |
||
1700 | * |
||
1701 | * @param mixed $value |
||
1702 | * @param mixed $limit |
||
1703 | * @param null $message |
||
1704 | * @param null $propertyPath |
||
1705 | */ |
||
1706 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1718 | |||
1719 | /** |
||
1720 | * Determines if the value is greater than given limit. |
||
1721 | * |
||
1722 | * @param mixed $value |
||
1723 | * @param mixed $limit |
||
1724 | * @param null $message |
||
1725 | * @param null $propertyPath |
||
1726 | */ |
||
1727 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
1739 | |||
1740 | /** |
||
1741 | * Determines if the value is greater or equal than given limit. |
||
1742 | * |
||
1743 | * @param mixed $value |
||
1744 | * @param mixed $limit |
||
1745 | * @param null $message |
||
1746 | * @param null $propertyPath |
||
1747 | */ |
||
1748 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1760 | |||
1761 | /** |
||
1762 | * Assert that date is valid and corresponds to the given format. |
||
1763 | * |
||
1764 | * @param string $value |
||
1765 | * @param string $format supports all of the options date(), except for the following: |
||
1766 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
1767 | * @param string|null $message |
||
1768 | * @param string|null $propertyPath |
||
1769 | * |
||
1770 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
1771 | */ |
||
1772 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
1789 | |||
1790 | /** |
||
1791 | * Determines that the provided value is callable. |
||
1792 | * |
||
1793 | * @param mixed $value |
||
1794 | * @param null $message |
||
1795 | * @param null $propertyPath |
||
1796 | */ |
||
1797 | public static function isCallable($value, $message = null, $propertyPath = null) |
||
1808 | |||
1809 | /** |
||
1810 | * Assert that the provided value is valid according to a callback. |
||
1811 | * |
||
1812 | * If the callback returns `false` the assertion will fail. |
||
1813 | * |
||
1814 | * @param mixed $value |
||
1815 | * @param callable $callback |
||
1816 | * @param string|null $message |
||
1817 | * @param string|null $propertyPath |
||
1818 | */ |
||
1819 | public static function satisfy($value, $callback, $message = null, $propertyPath = null) |
||
1832 | |||
1833 | /** |
||
1834 | * Make a string version of a value. |
||
1835 | * |
||
1836 | * @param mixed $value |
||
1837 | * @return string |
||
1838 | */ |
||
1839 | protected static function stringify($value) |
||
1873 | } |
||
1874 |