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 |
||
140 | class Assertion |
||
141 | { |
||
142 | const INVALID_FLOAT = 9; |
||
143 | const INVALID_INTEGER = 10; |
||
144 | const INVALID_DIGIT = 11; |
||
145 | const INVALID_INTEGERISH = 12; |
||
146 | const INVALID_BOOLEAN = 13; |
||
147 | const VALUE_EMPTY = 14; |
||
148 | const VALUE_NULL = 15; |
||
149 | const INVALID_STRING = 16; |
||
150 | const INVALID_REGEX = 17; |
||
151 | const INVALID_MIN_LENGTH = 18; |
||
152 | const INVALID_MAX_LENGTH = 19; |
||
153 | const INVALID_STRING_START = 20; |
||
154 | const INVALID_STRING_CONTAINS = 21; |
||
155 | const INVALID_CHOICE = 22; |
||
156 | const INVALID_NUMERIC = 23; |
||
157 | const INVALID_ARRAY = 24; |
||
158 | const INVALID_KEY_EXISTS = 26; |
||
159 | const INVALID_NOT_BLANK = 27; |
||
160 | const INVALID_INSTANCE_OF = 28; |
||
161 | const INVALID_SUBCLASS_OF = 29; |
||
162 | const INVALID_RANGE = 30; |
||
163 | const INVALID_ALNUM = 31; |
||
164 | const INVALID_TRUE = 32; |
||
165 | const INVALID_EQ = 33; |
||
166 | const INVALID_SAME = 34; |
||
167 | const INVALID_MIN = 35; |
||
168 | const INVALID_MAX = 36; |
||
169 | const INVALID_LENGTH = 37; |
||
170 | const INVALID_FALSE = 38; |
||
171 | const INVALID_STRING_END = 39; |
||
172 | const INVALID_UUID = 40; |
||
173 | const INVALID_COUNT = 41; |
||
174 | const INVALID_NOT_EQ = 42; |
||
175 | const INVALID_NOT_SAME = 43; |
||
176 | const INVALID_TRAVERSABLE = 44; |
||
177 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
178 | const INVALID_KEY_ISSET = 46; |
||
179 | const INVALID_DIRECTORY = 101; |
||
180 | const INVALID_FILE = 102; |
||
181 | const INVALID_READABLE = 103; |
||
182 | const INVALID_WRITEABLE = 104; |
||
183 | const INVALID_CLASS = 105; |
||
184 | const INVALID_EMAIL = 201; |
||
185 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
186 | const INVALID_URL = 203; |
||
187 | const INVALID_NOT_INSTANCE_OF = 204; |
||
188 | const VALUE_NOT_EMPTY = 205; |
||
189 | const INVALID_JSON_STRING = 206; |
||
190 | const INVALID_OBJECT = 207; |
||
191 | const INVALID_METHOD = 208; |
||
192 | const INVALID_SCALAR = 209; |
||
193 | const INVALID_LESS = 210; |
||
194 | const INVALID_LESS_OR_EQUAL = 211; |
||
195 | const INVALID_GREATER = 212; |
||
196 | const INVALID_GREATER_OR_EQUAL = 212; |
||
197 | const INVALID_DATE = 213; |
||
198 | const INVALID_CALLABLE = 214; |
||
199 | |||
200 | /** |
||
201 | * Exception to throw when an assertion failed. |
||
202 | * |
||
203 | * @var string |
||
204 | */ |
||
205 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
206 | |||
207 | /** |
||
208 | * Helper method that handles building the assertion failure exceptions. |
||
209 | * They are returned from this method so that the stack trace still shows |
||
210 | * the assertions method. |
||
211 | */ |
||
212 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
217 | |||
218 | /** |
||
219 | * Assert that two values are equal (using == ). |
||
220 | * |
||
221 | * @param mixed $value |
||
222 | * @param mixed $value2 |
||
223 | * @param string|null $message |
||
224 | * @param string|null $propertyPath |
||
225 | * @return void |
||
226 | * @throws \Assert\AssertionFailedException |
||
227 | */ |
||
228 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
240 | |||
241 | /** |
||
242 | * Assert that two values are the same (using ===). |
||
243 | * |
||
244 | * @param mixed $value |
||
245 | * @param mixed $value2 |
||
246 | * @param string|null $message |
||
247 | * @param string|null $propertyPath |
||
248 | * @return void |
||
249 | * @throws \Assert\AssertionFailedException |
||
250 | */ |
||
251 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
263 | |||
264 | /** |
||
265 | * Assert that two values are not equal (using == ). |
||
266 | * |
||
267 | * @param mixed $value1 |
||
268 | * @param mixed $value2 |
||
269 | * @param string|null $message |
||
270 | * @param string|null $propertyPath |
||
271 | * @return void |
||
272 | * @throws \Assert\AssertionFailedException |
||
273 | */ |
||
274 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
285 | |||
286 | /** |
||
287 | * Assert that two values are not the same (using === ). |
||
288 | * |
||
289 | * @param mixed $value1 |
||
290 | * @param mixed $value2 |
||
291 | * @param string|null $message |
||
292 | * @param string|null $propertyPath |
||
293 | * @return void |
||
294 | * @throws \Assert\AssertionFailedException |
||
295 | */ |
||
296 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
307 | |||
308 | /** |
||
309 | * Assert that value is a php integer. |
||
310 | * |
||
311 | * @param mixed $value |
||
312 | * @param string|null $message |
||
313 | * @param string|null $propertyPath |
||
314 | * @return void |
||
315 | * @throws \Assert\AssertionFailedException |
||
316 | */ |
||
317 | public static function integer($value, $message = null, $propertyPath = null) |
||
328 | |||
329 | /** |
||
330 | * Assert that value is a php float. |
||
331 | * |
||
332 | * @param mixed $value |
||
333 | * @param string|null $message |
||
334 | * @param string|null $propertyPath |
||
335 | * @return void |
||
336 | * @throws \Assert\AssertionFailedException |
||
337 | */ |
||
338 | public static function float($value, $message = null, $propertyPath = null) |
||
349 | |||
350 | /** |
||
351 | * Validates if an integer or integerish is a digit. |
||
352 | * |
||
353 | * @param mixed $value |
||
354 | * @param string|null $message |
||
355 | * @param string|null $propertyPath |
||
356 | * @return void |
||
357 | * @throws \Assert\AssertionFailedException |
||
358 | */ |
||
359 | public static function digit($value, $message = null, $propertyPath = null) |
||
370 | |||
371 | /** |
||
372 | * Assert that value is a php integer'ish. |
||
373 | * @param mixed $value |
||
374 | * @param string|null $message |
||
375 | * @param string|null $propertyPath |
||
376 | * @return void |
||
377 | * @throws \Assert\AssertionFailedException |
||
378 | */ |
||
379 | public static function integerish($value, $message = null, $propertyPath = null) |
||
390 | |||
391 | /** |
||
392 | * Assert that value is php boolean |
||
393 | * |
||
394 | * @param mixed $value |
||
395 | * @param string|null $message |
||
396 | * @param string|null $propertyPath |
||
397 | * @return void |
||
398 | * @throws \Assert\AssertionFailedException |
||
399 | */ |
||
400 | public static function boolean($value, $message = null, $propertyPath = null) |
||
411 | |||
412 | /** |
||
413 | * Assert that value is a PHP scalar |
||
414 | * |
||
415 | * @param mixed $value |
||
416 | * @param string|null $message |
||
417 | * @param string|null $propertyPath |
||
418 | * @return void |
||
419 | * @throws \Assert\AssertionFailedException |
||
420 | */ |
||
421 | public static function scalar($value, $message = null, $propertyPath = null) |
||
432 | |||
433 | /** |
||
434 | * Assert that value is not empty |
||
435 | * |
||
436 | * @param mixed $value |
||
437 | * @param string|null $message |
||
438 | * @param string|null $propertyPath |
||
439 | * @return void |
||
440 | * @throws \Assert\AssertionFailedException |
||
441 | */ |
||
442 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
453 | |||
454 | /** |
||
455 | * Assert that value is empty |
||
456 | * |
||
457 | * @param mixed $value |
||
458 | * @param string|null $message |
||
459 | * @param string|null $propertyPath |
||
460 | * @return void |
||
461 | * @throws \Assert\AssertionFailedException |
||
462 | */ |
||
463 | public static function noContent($value, $message = null, $propertyPath = null) |
||
474 | |||
475 | /** |
||
476 | * Assert that value is not null |
||
477 | * |
||
478 | * @param mixed $value |
||
479 | * @param string|null $message |
||
480 | * @param string|null $propertyPath |
||
481 | * @return void |
||
482 | * @throws \Assert\AssertionFailedException |
||
483 | */ |
||
484 | public static function notNull($value, $message = null, $propertyPath = null) |
||
495 | |||
496 | /** |
||
497 | * Assert that value is a string |
||
498 | * |
||
499 | * @param mixed $value |
||
500 | * @param string|null $message |
||
501 | * @param string|null $propertyPath |
||
502 | * @return void |
||
503 | * @throws \Assert\AssertionFailedException |
||
504 | */ |
||
505 | public static function string($value, $message = null, $propertyPath = null) |
||
517 | |||
518 | /** |
||
519 | * Assert that value matches a regex |
||
520 | * |
||
521 | * @param mixed $value |
||
522 | * @param string $pattern |
||
523 | * @param string|null $message |
||
524 | * @param string|null $propertyPath |
||
525 | * @return void |
||
526 | * @throws \Assert\AssertionFailedException |
||
527 | */ |
||
528 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
541 | |||
542 | /** |
||
543 | * Assert that string has a given length. |
||
544 | * |
||
545 | * @param mixed $value |
||
546 | * @param int $length |
||
547 | * @param string|null $message |
||
548 | * @param string|null $propertyPath |
||
549 | * @param string $encoding |
||
550 | * @return void |
||
551 | * @throws \Assert\AssertionFailedException |
||
552 | */ |
||
553 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
569 | |||
570 | /** |
||
571 | * Assert that a string is at least $minLength chars long. |
||
572 | * |
||
573 | * @param mixed $value |
||
574 | * @param int $minLength |
||
575 | * @param string|null $message |
||
576 | * @param string|null $propertyPath |
||
577 | * @param string $encoding |
||
578 | * @return void |
||
579 | * @throws \Assert\AssertionFailedException |
||
580 | */ |
||
581 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
597 | |||
598 | /** |
||
599 | * Assert that string value is not longer than $maxLength chars. |
||
600 | * |
||
601 | * @param mixed $value |
||
602 | * @param integer $maxLength |
||
603 | * @param string|null $message |
||
604 | * @param string|null $propertyPath |
||
605 | * @param string $encoding |
||
606 | * @return void |
||
607 | * @throws \Assert\AssertionFailedException |
||
608 | */ |
||
609 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
625 | |||
626 | /** |
||
627 | * Assert that string length is between min,max lengths. |
||
628 | * |
||
629 | * @param mixed $value |
||
630 | * @param integer $minLength |
||
631 | * @param integer $maxLength |
||
632 | * @param string|null $message |
||
633 | * @param string|null $propertyPath |
||
634 | * @param string $encoding |
||
635 | * @return void |
||
636 | * @throws \Assert\AssertionFailedException |
||
637 | */ |
||
638 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
666 | |||
667 | /** |
||
668 | * Assert that string starts with a sequence of chars. |
||
669 | * |
||
670 | * @param mixed $string |
||
671 | * @param string $needle |
||
672 | * @param string|null $message |
||
673 | * @param string|null $propertyPath |
||
674 | * @param string $encoding |
||
675 | * @return void |
||
676 | * @throws \Assert\AssertionFailedException |
||
677 | */ |
||
678 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
693 | |||
694 | /** |
||
695 | * Assert that string ends with a sequence of chars. |
||
696 | * |
||
697 | * @param mixed $string |
||
698 | * @param string $needle |
||
699 | * @param string|null $message |
||
700 | * @param string|null $propertyPath |
||
701 | * @param string $encoding |
||
702 | * @return void |
||
703 | * @throws \Assert\AssertionFailedException |
||
704 | */ |
||
705 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
722 | |||
723 | /** |
||
724 | * Assert that string contains a sequence of chars. |
||
725 | * |
||
726 | * @param mixed $string |
||
727 | * @param string $needle |
||
728 | * @param string|null $message |
||
729 | * @param string|null $propertyPath |
||
730 | * @param string $encoding |
||
731 | * @return void |
||
732 | * @throws \Assert\AssertionFailedException |
||
733 | */ |
||
734 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
749 | |||
750 | /** |
||
751 | * Assert that value is in array of choices. |
||
752 | * |
||
753 | * @param mixed $value |
||
754 | * @param array $choices |
||
755 | * @param string|null $message |
||
756 | * @param string|null $propertyPath |
||
757 | * @return void |
||
758 | * @throws \Assert\AssertionFailedException |
||
759 | */ |
||
760 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
772 | |||
773 | /** |
||
774 | * Alias of {@see choice()} |
||
775 | * |
||
776 | * @throws \Assert\AssertionFailedException |
||
777 | */ |
||
778 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
782 | |||
783 | /** |
||
784 | * Assert that value is numeric. |
||
785 | * |
||
786 | * @param mixed $value |
||
787 | * @param string|null $message |
||
788 | * @param string|null $propertyPath |
||
789 | * @return void |
||
790 | * @throws \Assert\AssertionFailedException |
||
791 | */ |
||
792 | public static function numeric($value, $message = null, $propertyPath = null) |
||
803 | |||
804 | /** |
||
805 | * Assert that value is an array. |
||
806 | * |
||
807 | * @param mixed $value |
||
808 | * @param string|null $message |
||
809 | * @param string|null $propertyPath |
||
810 | * @return void |
||
811 | * @throws \Assert\AssertionFailedException |
||
812 | */ |
||
813 | public static function isArray($value, $message = null, $propertyPath = null) |
||
824 | |||
825 | /** |
||
826 | * Assert that value is an array or a traversable object. |
||
827 | * |
||
828 | * @param mixed $value |
||
829 | * @param string|null $message |
||
830 | * @param string|null $propertyPath |
||
831 | * @return void |
||
832 | * @throws \Assert\AssertionFailedException |
||
833 | */ |
||
834 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
845 | |||
846 | /** |
||
847 | * Assert that value is an array or an array-accessible object. |
||
848 | * |
||
849 | * @param mixed $value |
||
850 | * @param string|null $message |
||
851 | * @param string|null $propertyPath |
||
852 | * @return void |
||
853 | * @throws \Assert\AssertionFailedException |
||
854 | */ |
||
855 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
866 | |||
867 | /** |
||
868 | * Assert that key exists in an array |
||
869 | * |
||
870 | * @param mixed $value |
||
871 | * @param string|integer $key |
||
872 | * @param string|null $message |
||
873 | * @param string|null $propertyPath |
||
874 | * @return void |
||
875 | * @throws \Assert\AssertionFailedException |
||
876 | */ |
||
877 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
890 | |||
891 | /** |
||
892 | * Assert that key exists in an array/array-accessible object using isset() |
||
893 | * |
||
894 | * @param mixed $value |
||
895 | * @param string|integer $key |
||
896 | * @param string|null $message |
||
897 | * @param string|null $propertyPath |
||
898 | * @return void |
||
899 | * @throws \Assert\AssertionFailedException |
||
900 | */ |
||
901 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
914 | |||
915 | /** |
||
916 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
917 | * |
||
918 | * @param mixed $value |
||
919 | * @param string|integer $key |
||
920 | * @param string|null $message |
||
921 | * @param string|null $propertyPath |
||
922 | * @return void |
||
923 | * @throws \Assert\AssertionFailedException |
||
924 | */ |
||
925 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
930 | |||
931 | /** |
||
932 | * Assert that value is not blank |
||
933 | * |
||
934 | * @param mixed $value |
||
935 | * @param string|null $message |
||
936 | * @param string|null $propertyPath |
||
937 | * @return void |
||
938 | * @throws \Assert\AssertionFailedException |
||
939 | */ |
||
940 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
951 | |||
952 | /** |
||
953 | * Assert that value is instance of given class-name. |
||
954 | * |
||
955 | * @param mixed $value |
||
956 | * @param string $className |
||
957 | * @param string|null $message |
||
958 | * @param string|null $propertyPath |
||
959 | * @return void |
||
960 | * @throws \Assert\AssertionFailedException |
||
961 | */ |
||
962 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
974 | |||
975 | /** |
||
976 | * Assert that value is not instance of given class-name. |
||
977 | * |
||
978 | * @param mixed $value |
||
979 | * @param string $className |
||
980 | * @param string|null $message |
||
981 | * @param string|null $propertyPath |
||
982 | * @return void |
||
983 | * @throws \Assert\AssertionFailedException |
||
984 | */ |
||
985 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
997 | |||
998 | /** |
||
999 | * Assert that value is subclass of given class-name. |
||
1000 | * |
||
1001 | * @param mixed $value |
||
1002 | * @param string $className |
||
1003 | * @param string|null $message |
||
1004 | * @param string|null $propertyPath |
||
1005 | * @return void |
||
1006 | * @throws \Assert\AssertionFailedException |
||
1007 | */ |
||
1008 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
1020 | |||
1021 | /** |
||
1022 | * Assert that value is in range of numbers. |
||
1023 | * |
||
1024 | * @param mixed $value |
||
1025 | * @param integer $minValue |
||
1026 | * @param integer $maxValue |
||
1027 | * @param string|null $message |
||
1028 | * @param string|null $propertyPath |
||
1029 | * @return void |
||
1030 | * @throws \Assert\AssertionFailedException |
||
1031 | */ |
||
1032 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
1047 | |||
1048 | /** |
||
1049 | * Assert that a value is at least as big as a given limit |
||
1050 | * |
||
1051 | * @param mixed $value |
||
1052 | * @param mixed $minValue |
||
1053 | * @param string|null $message |
||
1054 | * @param string|null $propertyPath |
||
1055 | * @return void |
||
1056 | * @throws \Assert\AssertionFailedException |
||
1057 | */ |
||
1058 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
1072 | |||
1073 | /** |
||
1074 | * Assert that a number is smaller as a given limit |
||
1075 | * |
||
1076 | * @param mixed $value |
||
1077 | * @param mixed $maxValue |
||
1078 | * @param string|null $message |
||
1079 | * @param string|null $propertyPath |
||
1080 | * @return void |
||
1081 | * @throws \Assert\AssertionFailedException |
||
1082 | */ |
||
1083 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
1097 | |||
1098 | /** |
||
1099 | * Assert that a file exists |
||
1100 | * |
||
1101 | * @param string $value |
||
1102 | * @param string|null $message |
||
1103 | * @param string|null $propertyPath |
||
1104 | * @return void |
||
1105 | * @throws \Assert\AssertionFailedException |
||
1106 | */ |
||
1107 | public static function file($value, $message = null, $propertyPath = null) |
||
1121 | |||
1122 | /** |
||
1123 | * Assert that a directory exists |
||
1124 | * |
||
1125 | * @param string $value |
||
1126 | * @param string|null $message |
||
1127 | * @param string|null $propertyPath |
||
1128 | * @return void |
||
1129 | * @throws \Assert\AssertionFailedException |
||
1130 | */ |
||
1131 | public static function directory($value, $message = null, $propertyPath = null) |
||
1144 | |||
1145 | /** |
||
1146 | * Assert that the value is something readable |
||
1147 | * |
||
1148 | * @param string $value |
||
1149 | * @param string|null $message |
||
1150 | * @param string|null $propertyPath |
||
1151 | * @return void |
||
1152 | * @throws \Assert\AssertionFailedException |
||
1153 | */ |
||
1154 | public static function readable($value, $message = null, $propertyPath = null) |
||
1167 | |||
1168 | /** |
||
1169 | * Assert that the value is something writeable |
||
1170 | * |
||
1171 | * @param string $value |
||
1172 | * @param string|null $message |
||
1173 | * @param string|null $propertyPath |
||
1174 | * @return void |
||
1175 | * @throws \Assert\AssertionFailedException |
||
1176 | */ |
||
1177 | public static function writeable($value, $message = null, $propertyPath = null) |
||
1190 | |||
1191 | /** |
||
1192 | * Assert that value is an email adress (using |
||
1193 | * input_filter/FILTER_VALIDATE_EMAIL). |
||
1194 | * |
||
1195 | * @param mixed $value |
||
1196 | * @param string|null $message |
||
1197 | * @param string|null $propertyPath |
||
1198 | * @return void |
||
1199 | * @throws \Assert\AssertionFailedException |
||
1200 | */ |
||
1201 | public static function email($value, $message = null, $propertyPath = null) |
||
1226 | |||
1227 | /** |
||
1228 | * Assert that value is an URL. |
||
1229 | * |
||
1230 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
1231 | * |
||
1232 | * @param mixed $value |
||
1233 | * @param string|null $message |
||
1234 | * @param string|null $propertyPath |
||
1235 | * @return void |
||
1236 | * @throws \Assert\AssertionFailedException |
||
1237 | * |
||
1238 | * |
||
1239 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
1240 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
1241 | */ |
||
1242 | public static function url($value, $message = null, $propertyPath = null) |
||
1275 | |||
1276 | /** |
||
1277 | * Assert that value is alphanumeric. |
||
1278 | * |
||
1279 | * @param mixed $value |
||
1280 | * @param string|null $message |
||
1281 | * @param string|null $propertyPath |
||
1282 | * @return void |
||
1283 | * @throws \Assert\AssertionFailedException |
||
1284 | */ |
||
1285 | public static function alnum($value, $message = null, $propertyPath = null) |
||
1298 | |||
1299 | /** |
||
1300 | * Assert that the value is boolean True. |
||
1301 | * |
||
1302 | * @param mixed $value |
||
1303 | * @param string|null $message |
||
1304 | * @param string|null $propertyPath |
||
1305 | * @return void |
||
1306 | * @throws \Assert\AssertionFailedException |
||
1307 | */ |
||
1308 | public static function true($value, $message = null, $propertyPath = null) |
||
1319 | |||
1320 | /** |
||
1321 | * Assert that the value is boolean False. |
||
1322 | * |
||
1323 | * @param mixed $value |
||
1324 | * @param string|null $message |
||
1325 | * @param string|null $propertyPath |
||
1326 | * @return void |
||
1327 | * @throws \Assert\AssertionFailedException |
||
1328 | */ |
||
1329 | public static function false($value, $message = null, $propertyPath = null) |
||
1340 | |||
1341 | /** |
||
1342 | * Assert that the class exists. |
||
1343 | * |
||
1344 | * @param mixed $value |
||
1345 | * @param string|null $message |
||
1346 | * @param string|null $propertyPath |
||
1347 | * @return void |
||
1348 | * @throws \Assert\AssertionFailedException |
||
1349 | */ |
||
1350 | public static function classExists($value, $message = null, $propertyPath = null) |
||
1361 | |||
1362 | /** |
||
1363 | * Assert that the class implements the interface |
||
1364 | * |
||
1365 | * @param mixed $class |
||
1366 | * @param string $interfaceName |
||
1367 | * @param string|null $message |
||
1368 | * @param string|null $propertyPath |
||
1369 | * @return void |
||
1370 | * @throws \Assert\AssertionFailedException |
||
1371 | */ |
||
1372 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
1385 | |||
1386 | /** |
||
1387 | * Assert that the given string is a valid json string. |
||
1388 | * |
||
1389 | * NOTICE: |
||
1390 | * Since this does a json_decode to determine its validity |
||
1391 | * you probably should consider, when using the variable |
||
1392 | * content afterwards, just to decode and check for yourself instead |
||
1393 | * of using this assertion. |
||
1394 | * |
||
1395 | * @param mixed $value |
||
1396 | * @param string|null $message |
||
1397 | * @param string|null $propertyPath |
||
1398 | * @return void |
||
1399 | * @throws \Assert\AssertionFailedException |
||
1400 | */ |
||
1401 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
1412 | |||
1413 | /** |
||
1414 | * Assert that the given string is a valid UUID |
||
1415 | * |
||
1416 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
1417 | * |
||
1418 | * @param string $value |
||
1419 | * @param string|null $message |
||
1420 | * @param string|null $propertyPath |
||
1421 | * @return void |
||
1422 | * @throws \Assert\AssertionFailedException |
||
1423 | */ |
||
1424 | public static function uuid($value, $message = null, $propertyPath = null) |
||
1441 | |||
1442 | /** |
||
1443 | * Assert that the count of countable is equal to count. |
||
1444 | * |
||
1445 | * @param array|\Countable $countable |
||
1446 | * @param int $count |
||
1447 | * @param string $message |
||
1448 | * @param string $propertyPath |
||
1449 | * @return void |
||
1450 | * @throws \Assert\AssertionFailedException |
||
1451 | */ |
||
1452 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
1463 | |||
1464 | /** |
||
1465 | * static call handler to implement: |
||
1466 | * - "null or assertion" delegation |
||
1467 | * - "all" delegation |
||
1468 | */ |
||
1469 | public static function __callStatic($method, $args) |
||
1505 | |||
1506 | /** |
||
1507 | * Determines if the values array has every choice as key and that this choice has content. |
||
1508 | * |
||
1509 | * @param array $values |
||
1510 | * @param array $choices |
||
1511 | * @param null $message |
||
1512 | * @param null $propertyPath |
||
1513 | */ |
||
1514 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
1523 | |||
1524 | /** |
||
1525 | * Determines that the named method is defined in the provided object. |
||
1526 | * |
||
1527 | * @param string $value |
||
1528 | * @param mixed $object |
||
1529 | * @param null $message |
||
1530 | * @param null $propertyPath |
||
1531 | * |
||
1532 | * @throws |
||
1533 | */ |
||
1534 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
1547 | |||
1548 | /** |
||
1549 | * Determines that the provided value is an object. |
||
1550 | * |
||
1551 | * @param mixed $value |
||
1552 | * @param null $message |
||
1553 | * @param null $propertyPath |
||
1554 | */ |
||
1555 | public static function isObject($value, $message = null, $propertyPath = null) |
||
1566 | |||
1567 | /** |
||
1568 | * Determines that the provided value is callable. |
||
1569 | * |
||
1570 | * @param mixed $value |
||
1571 | * @param null $message |
||
1572 | * @param null $propertyPath |
||
1573 | */ |
||
1574 | public static function isCallable($value, $message = null, $propertyPath = null) |
||
1585 | |||
1586 | /** |
||
1587 | * Determines if the value is less than given limit. |
||
1588 | * |
||
1589 | * @param mixed $value |
||
1590 | * @param mixed $limit |
||
1591 | * @param null $message |
||
1592 | * @param null $propertyPath |
||
1593 | */ |
||
1594 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
1606 | |||
1607 | /** |
||
1608 | * Determines if the value is less or than given limit. |
||
1609 | * |
||
1610 | * @param mixed $value |
||
1611 | * @param mixed $limit |
||
1612 | * @param null $message |
||
1613 | * @param null $propertyPath |
||
1614 | */ |
||
1615 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1627 | |||
1628 | /** |
||
1629 | * Determines if the value is greater than given limit. |
||
1630 | * |
||
1631 | * @param mixed $value |
||
1632 | * @param mixed $limit |
||
1633 | * @param null $message |
||
1634 | * @param null $propertyPath |
||
1635 | */ |
||
1636 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
1648 | |||
1649 | /** |
||
1650 | * Determines if the value is greater or equal than given limit. |
||
1651 | * |
||
1652 | * @param mixed $value |
||
1653 | * @param mixed $limit |
||
1654 | * @param null $message |
||
1655 | * @param null $propertyPath |
||
1656 | */ |
||
1657 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1669 | |||
1670 | /** |
||
1671 | * Assert that date is valid and corresponds to the given format. |
||
1672 | * |
||
1673 | * @param string $value |
||
1674 | * @param string $format supports all of the options date(), except for the following: |
||
1675 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
1676 | * @param string|null $message |
||
1677 | * @param string|null $propertyPath |
||
1678 | * |
||
1679 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
1680 | */ |
||
1681 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
1698 | |||
1699 | /** |
||
1700 | * Make a string version of a value. |
||
1701 | * |
||
1702 | * @param mixed $value |
||
1703 | * @return string |
||
1704 | */ |
||
1705 | protected static function stringify($value) |
||
1739 | } |
||
1740 | |||
1741 |