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 |
||
146 | class Assertion |
||
147 | { |
||
148 | const INVALID_FLOAT = 9; |
||
149 | const INVALID_INTEGER = 10; |
||
150 | const INVALID_DIGIT = 11; |
||
151 | const INVALID_INTEGERISH = 12; |
||
152 | const INVALID_BOOLEAN = 13; |
||
153 | const VALUE_EMPTY = 14; |
||
154 | const VALUE_NULL = 15; |
||
155 | const INVALID_STRING = 16; |
||
156 | const INVALID_REGEX = 17; |
||
157 | const INVALID_MIN_LENGTH = 18; |
||
158 | const INVALID_MAX_LENGTH = 19; |
||
159 | const INVALID_STRING_START = 20; |
||
160 | const INVALID_STRING_CONTAINS = 21; |
||
161 | const INVALID_CHOICE = 22; |
||
162 | const INVALID_NUMERIC = 23; |
||
163 | const INVALID_ARRAY = 24; |
||
164 | const INVALID_KEY_EXISTS = 26; |
||
165 | const INVALID_NOT_BLANK = 27; |
||
166 | const INVALID_INSTANCE_OF = 28; |
||
167 | const INVALID_SUBCLASS_OF = 29; |
||
168 | const INVALID_RANGE = 30; |
||
169 | const INVALID_ALNUM = 31; |
||
170 | const INVALID_TRUE = 32; |
||
171 | const INVALID_EQ = 33; |
||
172 | const INVALID_SAME = 34; |
||
173 | const INVALID_MIN = 35; |
||
174 | const INVALID_MAX = 36; |
||
175 | const INVALID_LENGTH = 37; |
||
176 | const INVALID_FALSE = 38; |
||
177 | const INVALID_STRING_END = 39; |
||
178 | const INVALID_UUID = 40; |
||
179 | const INVALID_COUNT = 41; |
||
180 | const INVALID_NOT_EQ = 42; |
||
181 | const INVALID_NOT_SAME = 43; |
||
182 | const INVALID_TRAVERSABLE = 44; |
||
183 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
184 | const INVALID_KEY_ISSET = 46; |
||
185 | const INVALID_DIRECTORY = 101; |
||
186 | const INVALID_FILE = 102; |
||
187 | const INVALID_READABLE = 103; |
||
188 | const INVALID_WRITEABLE = 104; |
||
189 | const INVALID_CLASS = 105; |
||
190 | const INVALID_EMAIL = 201; |
||
191 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
192 | const INVALID_URL = 203; |
||
193 | const INVALID_NOT_INSTANCE_OF = 204; |
||
194 | const VALUE_NOT_EMPTY = 205; |
||
195 | const INVALID_JSON_STRING = 206; |
||
196 | const INVALID_OBJECT = 207; |
||
197 | const INVALID_METHOD = 208; |
||
198 | const INVALID_SCALAR = 209; |
||
199 | const INVALID_LESS = 210; |
||
200 | const INVALID_LESS_OR_EQUAL = 211; |
||
201 | const INVALID_GREATER = 212; |
||
202 | const INVALID_GREATER_OR_EQUAL = 212; |
||
203 | const INVALID_DATE = 213; |
||
204 | |||
205 | /** |
||
206 | * Exception to throw when an assertion failed. |
||
207 | * |
||
208 | * @var string |
||
209 | */ |
||
210 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
211 | |||
212 | /** |
||
213 | * Helper method that handles building the assertion failure exceptions. |
||
214 | * They are returned from this method so that the stack trace still shows |
||
215 | * the assertions method. |
||
216 | */ |
||
217 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
222 | |||
223 | /** |
||
224 | * Assert that two values are equal (using == ). |
||
225 | * |
||
226 | * @param mixed $value |
||
227 | * @param mixed $value2 |
||
228 | * @param string|null $message |
||
229 | * @param string|null $propertyPath |
||
230 | * @return void |
||
231 | * @throws \Assert\AssertionFailedException |
||
232 | */ |
||
233 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
245 | |||
246 | /** |
||
247 | * Assert that two values are the same (using ===). |
||
248 | * |
||
249 | * @param mixed $value |
||
250 | * @param mixed $value2 |
||
251 | * @param string|null $message |
||
252 | * @param string|null $propertyPath |
||
253 | * @return void |
||
254 | * @throws \Assert\AssertionFailedException |
||
255 | */ |
||
256 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
268 | |||
269 | /** |
||
270 | * Assert that two values are not equal (using == ). |
||
271 | * |
||
272 | * @param mixed $value1 |
||
273 | * @param mixed $value2 |
||
274 | * @param string|null $message |
||
275 | * @param string|null $propertyPath |
||
276 | * @return void |
||
277 | * @throws \Assert\AssertionFailedException |
||
278 | */ |
||
279 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
290 | |||
291 | /** |
||
292 | * Assert that two values are not the same (using === ). |
||
293 | * |
||
294 | * @param mixed $value1 |
||
295 | * @param mixed $value2 |
||
296 | * @param string|null $message |
||
297 | * @param string|null $propertyPath |
||
298 | * @return void |
||
299 | * @throws \Assert\AssertionFailedException |
||
300 | */ |
||
301 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
312 | |||
313 | /** |
||
314 | * Assert that value is a php integer. |
||
315 | * |
||
316 | * @param mixed $value |
||
317 | * @param string|null $message |
||
318 | * @param string|null $propertyPath |
||
319 | * @return void |
||
320 | * @throws \Assert\AssertionFailedException |
||
321 | */ |
||
322 | public static function integer($value, $message = null, $propertyPath = null) |
||
333 | |||
334 | /** |
||
335 | * Assert that value is a php float. |
||
336 | * |
||
337 | * @param mixed $value |
||
338 | * @param string|null $message |
||
339 | * @param string|null $propertyPath |
||
340 | * @return void |
||
341 | * @throws \Assert\AssertionFailedException |
||
342 | */ |
||
343 | public static function float($value, $message = null, $propertyPath = null) |
||
354 | |||
355 | /** |
||
356 | * Validates if an integer or integerish is a digit. |
||
357 | * |
||
358 | * @param mixed $value |
||
359 | * @param string|null $message |
||
360 | * @param string|null $propertyPath |
||
361 | * @return void |
||
362 | * @throws \Assert\AssertionFailedException |
||
363 | */ |
||
364 | public static function digit($value, $message = null, $propertyPath = null) |
||
375 | |||
376 | /** |
||
377 | * Assert that value is a php integer'ish. |
||
378 | * @param mixed $value |
||
379 | * @param string|null $message |
||
380 | * @param string|null $propertyPath |
||
381 | * @return void |
||
382 | * @throws \Assert\AssertionFailedException |
||
383 | */ |
||
384 | public static function integerish($value, $message = null, $propertyPath = null) |
||
395 | |||
396 | /** |
||
397 | * Assert that value is php boolean |
||
398 | * |
||
399 | * @param mixed $value |
||
400 | * @param string|null $message |
||
401 | * @param string|null $propertyPath |
||
402 | * @return void |
||
403 | * @throws \Assert\AssertionFailedException |
||
404 | */ |
||
405 | public static function boolean($value, $message = null, $propertyPath = null) |
||
416 | |||
417 | /** |
||
418 | * Assert that value is a PHP scalar |
||
419 | * |
||
420 | * @param mixed $value |
||
421 | * @param string|null $message |
||
422 | * @param string|null $propertyPath |
||
423 | * @return void |
||
424 | * @throws \Assert\AssertionFailedException |
||
425 | */ |
||
426 | public static function scalar($value, $message = null, $propertyPath = null) |
||
437 | |||
438 | /** |
||
439 | * Assert that value is not empty |
||
440 | * |
||
441 | * @param mixed $value |
||
442 | * @param string|null $message |
||
443 | * @param string|null $propertyPath |
||
444 | * @return void |
||
445 | * @throws \Assert\AssertionFailedException |
||
446 | */ |
||
447 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
458 | |||
459 | /** |
||
460 | * Assert that value is empty |
||
461 | * |
||
462 | * @param mixed $value |
||
463 | * @param string|null $message |
||
464 | * @param string|null $propertyPath |
||
465 | * @return void |
||
466 | * @throws \Assert\AssertionFailedException |
||
467 | */ |
||
468 | public static function noContent($value, $message = null, $propertyPath = null) |
||
479 | |||
480 | /** |
||
481 | * Assert that value is not null |
||
482 | * |
||
483 | * @param mixed $value |
||
484 | * @param string|null $message |
||
485 | * @param string|null $propertyPath |
||
486 | * @return void |
||
487 | * @throws \Assert\AssertionFailedException |
||
488 | */ |
||
489 | public static function notNull($value, $message = null, $propertyPath = null) |
||
500 | |||
501 | /** |
||
502 | * Assert that value is a string |
||
503 | * |
||
504 | * @param mixed $value |
||
505 | * @param string|null $message |
||
506 | * @param string|null $propertyPath |
||
507 | * @return void |
||
508 | * @throws \Assert\AssertionFailedException |
||
509 | */ |
||
510 | public static function string($value, $message = null, $propertyPath = null) |
||
522 | |||
523 | /** |
||
524 | * Assert that value matches a regex |
||
525 | * |
||
526 | * @param mixed $value |
||
527 | * @param string $pattern |
||
528 | * @param string|null $message |
||
529 | * @param string|null $propertyPath |
||
530 | * @return void |
||
531 | * @throws \Assert\AssertionFailedException |
||
532 | */ |
||
533 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
546 | |||
547 | /** |
||
548 | * Assert that string has a given length. |
||
549 | * |
||
550 | * @param mixed $value |
||
551 | * @param int $length |
||
552 | * @param string|null $message |
||
553 | * @param string|null $propertyPath |
||
554 | * @param string $encoding |
||
555 | * @return void |
||
556 | * @throws \Assert\AssertionFailedException |
||
557 | */ |
||
558 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
574 | |||
575 | /** |
||
576 | * Assert that a string is at least $minLength chars long. |
||
577 | * |
||
578 | * @param mixed $value |
||
579 | * @param int $minLength |
||
580 | * @param string|null $message |
||
581 | * @param string|null $propertyPath |
||
582 | * @param string $encoding |
||
583 | * @return void |
||
584 | * @throws \Assert\AssertionFailedException |
||
585 | */ |
||
586 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
602 | |||
603 | /** |
||
604 | * Assert that string value is not longer than $maxLength chars. |
||
605 | * |
||
606 | * @param mixed $value |
||
607 | * @param integer $maxLength |
||
608 | * @param string|null $message |
||
609 | * @param string|null $propertyPath |
||
610 | * @param string $encoding |
||
611 | * @return void |
||
612 | * @throws \Assert\AssertionFailedException |
||
613 | */ |
||
614 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
630 | |||
631 | /** |
||
632 | * Assert that string length is between min,max lengths. |
||
633 | * |
||
634 | * @param mixed $value |
||
635 | * @param integer $minLength |
||
636 | * @param integer $maxLength |
||
637 | * @param string|null $message |
||
638 | * @param string|null $propertyPath |
||
639 | * @param string $encoding |
||
640 | * @return void |
||
641 | * @throws \Assert\AssertionFailedException |
||
642 | */ |
||
643 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
671 | |||
672 | /** |
||
673 | * Assert that string starts with a sequence of chars. |
||
674 | * |
||
675 | * @param mixed $string |
||
676 | * @param string $needle |
||
677 | * @param string|null $message |
||
678 | * @param string|null $propertyPath |
||
679 | * @param string $encoding |
||
680 | * @return void |
||
681 | * @throws \Assert\AssertionFailedException |
||
682 | */ |
||
683 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
698 | |||
699 | /** |
||
700 | * Assert that string ends with a sequence of chars. |
||
701 | * |
||
702 | * @param mixed $string |
||
703 | * @param string $needle |
||
704 | * @param string|null $message |
||
705 | * @param string|null $propertyPath |
||
706 | * @param string $encoding |
||
707 | * @return void |
||
708 | * @throws \Assert\AssertionFailedException |
||
709 | */ |
||
710 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
727 | |||
728 | /** |
||
729 | * Assert that string contains a sequence of chars. |
||
730 | * |
||
731 | * @param mixed $string |
||
732 | * @param string $needle |
||
733 | * @param string|null $message |
||
734 | * @param string|null $propertyPath |
||
735 | * @param string $encoding |
||
736 | * @return void |
||
737 | * @throws \Assert\AssertionFailedException |
||
738 | */ |
||
739 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
754 | |||
755 | /** |
||
756 | * Assert that value is in array of choices. |
||
757 | * |
||
758 | * @param mixed $value |
||
759 | * @param array $choices |
||
760 | * @param string|null $message |
||
761 | * @param string|null $propertyPath |
||
762 | * @return void |
||
763 | * @throws \Assert\AssertionFailedException |
||
764 | */ |
||
765 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
777 | |||
778 | /** |
||
779 | * Alias of {@see choice()} |
||
780 | * |
||
781 | * @throws \Assert\AssertionFailedException |
||
782 | */ |
||
783 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
787 | |||
788 | /** |
||
789 | * Assert that value is numeric. |
||
790 | * |
||
791 | * @param mixed $value |
||
792 | * @param string|null $message |
||
793 | * @param string|null $propertyPath |
||
794 | * @return void |
||
795 | * @throws \Assert\AssertionFailedException |
||
796 | */ |
||
797 | public static function numeric($value, $message = null, $propertyPath = null) |
||
808 | |||
809 | /** |
||
810 | * Assert that value is an array. |
||
811 | * |
||
812 | * @param mixed $value |
||
813 | * @param string|null $message |
||
814 | * @param string|null $propertyPath |
||
815 | * @return void |
||
816 | * @throws \Assert\AssertionFailedException |
||
817 | */ |
||
818 | public static function isArray($value, $message = null, $propertyPath = null) |
||
829 | |||
830 | /** |
||
831 | * Assert that value is an array or a traversable object. |
||
832 | * |
||
833 | * @param mixed $value |
||
834 | * @param string|null $message |
||
835 | * @param string|null $propertyPath |
||
836 | * @return void |
||
837 | * @throws \Assert\AssertionFailedException |
||
838 | */ |
||
839 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
850 | |||
851 | /** |
||
852 | * Assert that value is an array or an array-accessible object. |
||
853 | * |
||
854 | * @param mixed $value |
||
855 | * @param string|null $message |
||
856 | * @param string|null $propertyPath |
||
857 | * @return void |
||
858 | * @throws \Assert\AssertionFailedException |
||
859 | */ |
||
860 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
871 | |||
872 | /** |
||
873 | * Assert that key exists in an array |
||
874 | * |
||
875 | * @param mixed $value |
||
876 | * @param string|integer $key |
||
877 | * @param string|null $message |
||
878 | * @param string|null $propertyPath |
||
879 | * @return void |
||
880 | * @throws \Assert\AssertionFailedException |
||
881 | */ |
||
882 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
895 | |||
896 | /** |
||
897 | * Assert that key exists in an array/array-accessible object using isset() |
||
898 | * |
||
899 | * @param mixed $value |
||
900 | * @param string|integer $key |
||
901 | * @param string|null $message |
||
902 | * @param string|null $propertyPath |
||
903 | * @return void |
||
904 | * @throws \Assert\AssertionFailedException |
||
905 | */ |
||
906 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
919 | |||
920 | /** |
||
921 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
922 | * |
||
923 | * @param mixed $value |
||
924 | * @param string|integer $key |
||
925 | * @param string|null $message |
||
926 | * @param string|null $propertyPath |
||
927 | * @return void |
||
928 | * @throws \Assert\AssertionFailedException |
||
929 | */ |
||
930 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
935 | |||
936 | /** |
||
937 | * Assert that value is not blank |
||
938 | * |
||
939 | * @param mixed $value |
||
940 | * @param string|null $message |
||
941 | * @param string|null $propertyPath |
||
942 | * @return void |
||
943 | * @throws \Assert\AssertionFailedException |
||
944 | */ |
||
945 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
956 | |||
957 | /** |
||
958 | * Assert that value is instance of given class-name. |
||
959 | * |
||
960 | * @param mixed $value |
||
961 | * @param string $className |
||
962 | * @param string|null $message |
||
963 | * @param string|null $propertyPath |
||
964 | * @return void |
||
965 | * @throws \Assert\AssertionFailedException |
||
966 | */ |
||
967 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
979 | |||
980 | /** |
||
981 | * Assert that value is not instance of given class-name. |
||
982 | * |
||
983 | * @param mixed $value |
||
984 | * @param string $className |
||
985 | * @param string|null $message |
||
986 | * @param string|null $propertyPath |
||
987 | * @return void |
||
988 | * @throws \Assert\AssertionFailedException |
||
989 | */ |
||
990 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1002 | |||
1003 | /** |
||
1004 | * Assert that value is subclass of given class-name. |
||
1005 | * |
||
1006 | * @param mixed $value |
||
1007 | * @param string $className |
||
1008 | * @param string|null $message |
||
1009 | * @param string|null $propertyPath |
||
1010 | * @return void |
||
1011 | * @throws \Assert\AssertionFailedException |
||
1012 | */ |
||
1013 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
1025 | |||
1026 | /** |
||
1027 | * Assert that value is in range of numbers. |
||
1028 | * |
||
1029 | * @param mixed $value |
||
1030 | * @param integer $minValue |
||
1031 | * @param integer $maxValue |
||
1032 | * @param string|null $message |
||
1033 | * @param string|null $propertyPath |
||
1034 | * @return void |
||
1035 | * @throws \Assert\AssertionFailedException |
||
1036 | */ |
||
1037 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
1052 | |||
1053 | /** |
||
1054 | * Assert that a value is at least as big as a given limit |
||
1055 | * |
||
1056 | * @param mixed $value |
||
1057 | * @param mixed $minValue |
||
1058 | * @param string|null $message |
||
1059 | * @param string|null $propertyPath |
||
1060 | * @return void |
||
1061 | * @throws \Assert\AssertionFailedException |
||
1062 | */ |
||
1063 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
1077 | |||
1078 | /** |
||
1079 | * Assert that a number is smaller as a given limit |
||
1080 | * |
||
1081 | * @param mixed $value |
||
1082 | * @param mixed $maxValue |
||
1083 | * @param string|null $message |
||
1084 | * @param string|null $propertyPath |
||
1085 | * @return void |
||
1086 | * @throws \Assert\AssertionFailedException |
||
1087 | */ |
||
1088 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
1102 | |||
1103 | /** |
||
1104 | * Assert that a file exists |
||
1105 | * |
||
1106 | * @param string $value |
||
1107 | * @param string|null $message |
||
1108 | * @param string|null $propertyPath |
||
1109 | * @return void |
||
1110 | * @throws \Assert\AssertionFailedException |
||
1111 | */ |
||
1112 | public static function file($value, $message = null, $propertyPath = null) |
||
1126 | |||
1127 | /** |
||
1128 | * Assert that a directory exists |
||
1129 | * |
||
1130 | * @param string $value |
||
1131 | * @param string|null $message |
||
1132 | * @param string|null $propertyPath |
||
1133 | * @return void |
||
1134 | * @throws \Assert\AssertionFailedException |
||
1135 | */ |
||
1136 | public static function directory($value, $message = null, $propertyPath = null) |
||
1149 | |||
1150 | /** |
||
1151 | * Assert that the value is something readable |
||
1152 | * |
||
1153 | * @param string $value |
||
1154 | * @param string|null $message |
||
1155 | * @param string|null $propertyPath |
||
1156 | * @return void |
||
1157 | * @throws \Assert\AssertionFailedException |
||
1158 | */ |
||
1159 | public static function readable($value, $message = null, $propertyPath = null) |
||
1172 | |||
1173 | /** |
||
1174 | * Assert that the value is something writeable |
||
1175 | * |
||
1176 | * @param string $value |
||
1177 | * @param string|null $message |
||
1178 | * @param string|null $propertyPath |
||
1179 | * @return void |
||
1180 | * @throws \Assert\AssertionFailedException |
||
1181 | */ |
||
1182 | public static function writeable($value, $message = null, $propertyPath = null) |
||
1195 | |||
1196 | /** |
||
1197 | * Assert that value is an email adress (using |
||
1198 | * input_filter/FILTER_VALIDATE_EMAIL). |
||
1199 | * |
||
1200 | * @param mixed $value |
||
1201 | * @param string|null $message |
||
1202 | * @param string|null $propertyPath |
||
1203 | * @return void |
||
1204 | * @throws \Assert\AssertionFailedException |
||
1205 | */ |
||
1206 | public static function email($value, $message = null, $propertyPath = null) |
||
1231 | |||
1232 | /** |
||
1233 | * Assert that value is an URL. |
||
1234 | * |
||
1235 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
1236 | * |
||
1237 | * @param mixed $value |
||
1238 | * @param string|null $message |
||
1239 | * @param string|null $propertyPath |
||
1240 | * @return void |
||
1241 | * @throws \Assert\AssertionFailedException |
||
1242 | * |
||
1243 | * |
||
1244 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
1245 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
1246 | */ |
||
1247 | public static function url($value, $message = null, $propertyPath = null) |
||
1280 | |||
1281 | /** |
||
1282 | * Assert that value is alphanumeric. |
||
1283 | * |
||
1284 | * @param mixed $value |
||
1285 | * @param string|null $message |
||
1286 | * @param string|null $propertyPath |
||
1287 | * @return void |
||
1288 | * @throws \Assert\AssertionFailedException |
||
1289 | */ |
||
1290 | public static function alnum($value, $message = null, $propertyPath = null) |
||
1303 | |||
1304 | /** |
||
1305 | * Assert that the value is boolean True. |
||
1306 | * |
||
1307 | * @param mixed $value |
||
1308 | * @param string|null $message |
||
1309 | * @param string|null $propertyPath |
||
1310 | * @return void |
||
1311 | * @throws \Assert\AssertionFailedException |
||
1312 | */ |
||
1313 | public static function true($value, $message = null, $propertyPath = null) |
||
1324 | |||
1325 | /** |
||
1326 | * Assert that the value is boolean False. |
||
1327 | * |
||
1328 | * @param mixed $value |
||
1329 | * @param string|null $message |
||
1330 | * @param string|null $propertyPath |
||
1331 | * @return void |
||
1332 | * @throws \Assert\AssertionFailedException |
||
1333 | */ |
||
1334 | public static function false($value, $message = null, $propertyPath = null) |
||
1345 | |||
1346 | /** |
||
1347 | * Assert that the class exists. |
||
1348 | * |
||
1349 | * @param mixed $value |
||
1350 | * @param string|null $message |
||
1351 | * @param string|null $propertyPath |
||
1352 | * @return void |
||
1353 | * @throws \Assert\AssertionFailedException |
||
1354 | */ |
||
1355 | public static function classExists($value, $message = null, $propertyPath = null) |
||
1366 | |||
1367 | /** |
||
1368 | * Assert that the class implements the interface |
||
1369 | * |
||
1370 | * @param mixed $class |
||
1371 | * @param string $interfaceName |
||
1372 | * @param string|null $message |
||
1373 | * @param string|null $propertyPath |
||
1374 | * @return void |
||
1375 | * @throws \Assert\AssertionFailedException |
||
1376 | */ |
||
1377 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
1390 | |||
1391 | /** |
||
1392 | * Assert that the given string is a valid json string. |
||
1393 | * |
||
1394 | * NOTICE: |
||
1395 | * Since this does a json_decode to determine its validity |
||
1396 | * you probably should consider, when using the variable |
||
1397 | * content afterwards, just to decode and check for yourself instead |
||
1398 | * of using this assertion. |
||
1399 | * |
||
1400 | * @param mixed $value |
||
1401 | * @param string|null $message |
||
1402 | * @param string|null $propertyPath |
||
1403 | * @return void |
||
1404 | * @throws \Assert\AssertionFailedException |
||
1405 | */ |
||
1406 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
1417 | |||
1418 | /** |
||
1419 | * Assert that the given string is a valid UUID |
||
1420 | * |
||
1421 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
1422 | * |
||
1423 | * @param string $value |
||
1424 | * @param string|null $message |
||
1425 | * @param string|null $propertyPath |
||
1426 | * @return void |
||
1427 | * @throws \Assert\AssertionFailedException |
||
1428 | */ |
||
1429 | public static function uuid($value, $message = null, $propertyPath = null) |
||
1446 | |||
1447 | /** |
||
1448 | * Assert that the count of countable is equal to count. |
||
1449 | * |
||
1450 | * @param array|\Countable $countable |
||
1451 | * @param int $count |
||
1452 | * @param string $message |
||
1453 | * @param string $propertyPath |
||
1454 | * @return void |
||
1455 | * @throws \Assert\AssertionFailedException |
||
1456 | */ |
||
1457 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
1468 | |||
1469 | /** |
||
1470 | * static call handler to implement: |
||
1471 | * - "null or assertion" delegation |
||
1472 | * - "all" delegation |
||
1473 | */ |
||
1474 | public static function __callStatic($method, $args) |
||
1510 | |||
1511 | /** |
||
1512 | * Determines if the values array has every choice as key and that this choice has content. |
||
1513 | * |
||
1514 | * @param array $values |
||
1515 | * @param array $choices |
||
1516 | * @param null $message |
||
1517 | * @param null $propertyPath |
||
1518 | */ |
||
1519 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
1528 | |||
1529 | /** |
||
1530 | * Determines that the named method is defined in the provided object. |
||
1531 | * |
||
1532 | * @param string $value |
||
1533 | * @param mixed $object |
||
1534 | * @param null $message |
||
1535 | * @param null $propertyPath |
||
1536 | * |
||
1537 | * @throws |
||
1538 | */ |
||
1539 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
1552 | |||
1553 | /** |
||
1554 | * Determines that the provided value is an object. |
||
1555 | * |
||
1556 | * @param mixed $value |
||
1557 | * @param null $message |
||
1558 | * @param null $propertyPath |
||
1559 | */ |
||
1560 | public static function isObject($value, $message = null, $propertyPath = null) |
||
1572 | |||
1573 | /** |
||
1574 | * Determines if the value is less than given limit. |
||
1575 | * |
||
1576 | * @param mixed $value |
||
1577 | * @param mixed $limit |
||
1578 | * @param null $message |
||
1579 | * @param null $propertyPath |
||
1580 | */ |
||
1581 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
1593 | |||
1594 | /** |
||
1595 | * Determines if the value is less or than given limit. |
||
1596 | * |
||
1597 | * @param mixed $value |
||
1598 | * @param mixed $limit |
||
1599 | * @param null $message |
||
1600 | * @param null $propertyPath |
||
1601 | */ |
||
1602 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1614 | |||
1615 | /** |
||
1616 | * Determines if the value is greater than given limit. |
||
1617 | * |
||
1618 | * @param mixed $value |
||
1619 | * @param mixed $limit |
||
1620 | * @param null $message |
||
1621 | * @param null $propertyPath |
||
1622 | */ |
||
1623 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
1635 | |||
1636 | /** |
||
1637 | * Determines if the value is greater or equal than given limit. |
||
1638 | * |
||
1639 | * @param mixed $value |
||
1640 | * @param mixed $limit |
||
1641 | * @param null $message |
||
1642 | * @param null $propertyPath |
||
1643 | */ |
||
1644 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1656 | |||
1657 | /** |
||
1658 | * Assert that date is valid and corresponds to the given format. |
||
1659 | * |
||
1660 | * @param string $value |
||
1661 | * @param string $format supports all of the options date(), except for the following: |
||
1662 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
1663 | * @param string|null $message |
||
1664 | * @param string|null $propertyPath |
||
1665 | * |
||
1666 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
1667 | */ |
||
1668 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
1685 | |||
1686 | /** |
||
1687 | * Make a string version of a value. |
||
1688 | * |
||
1689 | * @param mixed $value |
||
1690 | * @return string |
||
1691 | */ |
||
1692 | protected static function stringify($value) |
||
1726 | } |
||
1727 | |||
1728 |