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 |
||
168 | class Assertion |
||
169 | { |
||
170 | const INVALID_FLOAT = 9; |
||
171 | const INVALID_INTEGER = 10; |
||
172 | const INVALID_DIGIT = 11; |
||
173 | const INVALID_INTEGERISH = 12; |
||
174 | const INVALID_BOOLEAN = 13; |
||
175 | const VALUE_EMPTY = 14; |
||
176 | const VALUE_NULL = 15; |
||
177 | const VALUE_NOT_NULL = 25; |
||
178 | const INVALID_STRING = 16; |
||
179 | const INVALID_REGEX = 17; |
||
180 | const INVALID_MIN_LENGTH = 18; |
||
181 | const INVALID_MAX_LENGTH = 19; |
||
182 | const INVALID_STRING_START = 20; |
||
183 | const INVALID_STRING_CONTAINS = 21; |
||
184 | const INVALID_CHOICE = 22; |
||
185 | const INVALID_NUMERIC = 23; |
||
186 | const INVALID_ARRAY = 24; |
||
187 | const INVALID_KEY_EXISTS = 26; |
||
188 | const INVALID_NOT_BLANK = 27; |
||
189 | const INVALID_INSTANCE_OF = 28; |
||
190 | const INVALID_SUBCLASS_OF = 29; |
||
191 | const INVALID_RANGE = 30; |
||
192 | const INVALID_ALNUM = 31; |
||
193 | const INVALID_TRUE = 32; |
||
194 | const INVALID_EQ = 33; |
||
195 | const INVALID_SAME = 34; |
||
196 | const INVALID_MIN = 35; |
||
197 | const INVALID_MAX = 36; |
||
198 | const INVALID_LENGTH = 37; |
||
199 | const INVALID_FALSE = 38; |
||
200 | const INVALID_STRING_END = 39; |
||
201 | const INVALID_UUID = 40; |
||
202 | const INVALID_COUNT = 41; |
||
203 | const INVALID_NOT_EQ = 42; |
||
204 | const INVALID_NOT_SAME = 43; |
||
205 | const INVALID_TRAVERSABLE = 44; |
||
206 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
207 | const INVALID_KEY_ISSET = 46; |
||
208 | const INVALID_VALUE_IN_ARRAY = 47; |
||
209 | const INVALID_E164 = 48; |
||
210 | const INVALID_DIRECTORY = 101; |
||
211 | const INVALID_FILE = 102; |
||
212 | const INVALID_READABLE = 103; |
||
213 | const INVALID_WRITEABLE = 104; |
||
214 | const INVALID_CLASS = 105; |
||
215 | const INVALID_INTERFACE = 106; |
||
216 | const INVALID_EMAIL = 201; |
||
217 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
218 | const INVALID_URL = 203; |
||
219 | const INVALID_NOT_INSTANCE_OF = 204; |
||
220 | const VALUE_NOT_EMPTY = 205; |
||
221 | const INVALID_JSON_STRING = 206; |
||
222 | const INVALID_OBJECT = 207; |
||
223 | const INVALID_METHOD = 208; |
||
224 | const INVALID_SCALAR = 209; |
||
225 | const INVALID_LESS = 210; |
||
226 | const INVALID_LESS_OR_EQUAL = 211; |
||
227 | const INVALID_GREATER = 212; |
||
228 | const INVALID_GREATER_OR_EQUAL = 213; |
||
229 | const INVALID_DATE = 214; |
||
230 | const INVALID_CALLABLE = 215; |
||
231 | const INVALID_KEY_NOT_EXISTS = 216; |
||
232 | const INVALID_SATISFY = 217; |
||
233 | const INVALID_IP = 218; |
||
234 | const INVALID_BETWEEN = 219; |
||
235 | const INVALID_BETWEEN_EXCLUSIVE = 220; |
||
236 | |||
237 | /** |
||
238 | * Exception to throw when an assertion failed. |
||
239 | * |
||
240 | * @var string |
||
241 | */ |
||
242 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
243 | |||
244 | /** |
||
245 | * Helper method that handles building the assertion failure exceptions. |
||
246 | * They are returned from this method so that the stack trace still shows |
||
247 | * the assertions method. |
||
248 | */ |
||
249 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
254 | |||
255 | /** |
||
256 | * Assert that two values are equal (using == ). |
||
257 | * |
||
258 | * @param mixed $value |
||
259 | * @param mixed $value2 |
||
260 | * @param string|null $message |
||
261 | * @param string|null $propertyPath |
||
262 | * @return void |
||
263 | * @throws \Assert\AssertionFailedException |
||
264 | */ |
||
265 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
277 | |||
278 | /** |
||
279 | * Assert that two values are the same (using ===). |
||
280 | * |
||
281 | * @param mixed $value |
||
282 | * @param mixed $value2 |
||
283 | * @param string|null $message |
||
284 | * @param string|null $propertyPath |
||
285 | * @return void |
||
286 | * @throws \Assert\AssertionFailedException |
||
287 | */ |
||
288 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
300 | |||
301 | /** |
||
302 | * Assert that two values are not equal (using == ). |
||
303 | * |
||
304 | * @param mixed $value1 |
||
305 | * @param mixed $value2 |
||
306 | * @param string|null $message |
||
307 | * @param string|null $propertyPath |
||
308 | * @return void |
||
309 | * @throws \Assert\AssertionFailedException |
||
310 | */ |
||
311 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
322 | |||
323 | /** |
||
324 | * Assert that two values are not the same (using === ). |
||
325 | * |
||
326 | * @param mixed $value1 |
||
327 | * @param mixed $value2 |
||
328 | * @param string|null $message |
||
329 | * @param string|null $propertyPath |
||
330 | * @return void |
||
331 | * @throws \Assert\AssertionFailedException |
||
332 | */ |
||
333 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
344 | |||
345 | /** |
||
346 | * Assert that value is not in array of choices. |
||
347 | * |
||
348 | * @param mixed $value |
||
349 | * @param array $choices |
||
350 | * @param string|null $message |
||
351 | * @param string|null $propertyPath |
||
352 | * @return void |
||
353 | * @throws \Assert\AssertionFailedException |
||
354 | */ |
||
355 | public static function notInArray($value, array $choices, $message = null, $propertyPath = null) |
||
366 | |||
367 | /** |
||
368 | * Assert that value is a php integer. |
||
369 | * |
||
370 | * @param mixed $value |
||
371 | * @param string|null $message |
||
372 | * @param string|null $propertyPath |
||
373 | * @return void |
||
374 | * @throws \Assert\AssertionFailedException |
||
375 | */ |
||
376 | public static function integer($value, $message = null, $propertyPath = null) |
||
387 | |||
388 | /** |
||
389 | * Assert that value is a php float. |
||
390 | * |
||
391 | * @param mixed $value |
||
392 | * @param string|null $message |
||
393 | * @param string|null $propertyPath |
||
394 | * @return void |
||
395 | * @throws \Assert\AssertionFailedException |
||
396 | */ |
||
397 | public static function float($value, $message = null, $propertyPath = null) |
||
408 | |||
409 | /** |
||
410 | * Validates if an integer or integerish is a digit. |
||
411 | * |
||
412 | * @param mixed $value |
||
413 | * @param string|null $message |
||
414 | * @param string|null $propertyPath |
||
415 | * @return void |
||
416 | * @throws \Assert\AssertionFailedException |
||
417 | */ |
||
418 | public static function digit($value, $message = null, $propertyPath = null) |
||
429 | |||
430 | /** |
||
431 | * Assert that value is a php integer'ish. |
||
432 | * |
||
433 | * @param mixed $value |
||
434 | * @param string|null $message |
||
435 | * @param string|null $propertyPath |
||
436 | * @return void |
||
437 | * @throws \Assert\AssertionFailedException |
||
438 | */ |
||
439 | public static function integerish($value, $message = null, $propertyPath = null) |
||
450 | |||
451 | /** |
||
452 | * Assert that value is php boolean |
||
453 | * |
||
454 | * @param mixed $value |
||
455 | * @param string|null $message |
||
456 | * @param string|null $propertyPath |
||
457 | * @return void |
||
458 | * @throws \Assert\AssertionFailedException |
||
459 | */ |
||
460 | public static function boolean($value, $message = null, $propertyPath = null) |
||
471 | |||
472 | /** |
||
473 | * Assert that value is a PHP scalar |
||
474 | * |
||
475 | * @param mixed $value |
||
476 | * @param string|null $message |
||
477 | * @param string|null $propertyPath |
||
478 | * @return void |
||
479 | * @throws \Assert\AssertionFailedException |
||
480 | */ |
||
481 | public static function scalar($value, $message = null, $propertyPath = null) |
||
492 | |||
493 | /** |
||
494 | * Assert that value is not empty |
||
495 | * |
||
496 | * @param mixed $value |
||
497 | * @param string|null $message |
||
498 | * @param string|null $propertyPath |
||
499 | * @return void |
||
500 | * @throws \Assert\AssertionFailedException |
||
501 | */ |
||
502 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
513 | |||
514 | /** |
||
515 | * Assert that value is empty |
||
516 | * |
||
517 | * @param mixed $value |
||
518 | * @param string|null $message |
||
519 | * @param string|null $propertyPath |
||
520 | * @return void |
||
521 | * @throws \Assert\AssertionFailedException |
||
522 | */ |
||
523 | public static function noContent($value, $message = null, $propertyPath = null) |
||
534 | |||
535 | /** |
||
536 | * Assert that value is null |
||
537 | * |
||
538 | * @param mixed $value |
||
539 | * @param string|null $message |
||
540 | * @param string|null $propertyPath |
||
541 | * @return void |
||
542 | * @throws \Assert\AssertionFailedException |
||
543 | */ |
||
544 | public static function null($value, $message = null, $propertyPath = null) |
||
555 | |||
556 | /** |
||
557 | * Assert that value is not null |
||
558 | * |
||
559 | * @param mixed $value |
||
560 | * @param string|null $message |
||
561 | * @param string|null $propertyPath |
||
562 | * @return void |
||
563 | * @throws \Assert\AssertionFailedException |
||
564 | */ |
||
565 | public static function notNull($value, $message = null, $propertyPath = null) |
||
576 | |||
577 | /** |
||
578 | * Assert that value is a string |
||
579 | * |
||
580 | * @param mixed $value |
||
581 | * @param string|null $message |
||
582 | * @param string|null $propertyPath |
||
583 | * @return void |
||
584 | * @throws \Assert\AssertionFailedException |
||
585 | */ |
||
586 | public static function string($value, $message = null, $propertyPath = null) |
||
598 | |||
599 | /** |
||
600 | * Assert that value matches a regex |
||
601 | * |
||
602 | * @param mixed $value |
||
603 | * @param string $pattern |
||
604 | * @param string|null $message |
||
605 | * @param string|null $propertyPath |
||
606 | * @return void |
||
607 | * @throws \Assert\AssertionFailedException |
||
608 | */ |
||
609 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
622 | |||
623 | /** |
||
624 | * Assert that string has a given length. |
||
625 | * |
||
626 | * @param mixed $value |
||
627 | * @param int $length |
||
628 | * @param string|null $message |
||
629 | * @param string|null $propertyPath |
||
630 | * @param string $encoding |
||
631 | * @return void |
||
632 | * @throws \Assert\AssertionFailedException |
||
633 | */ |
||
634 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
650 | |||
651 | /** |
||
652 | * Assert that a string is at least $minLength chars long. |
||
653 | * |
||
654 | * @param mixed $value |
||
655 | * @param int $minLength |
||
656 | * @param string|null $message |
||
657 | * @param string|null $propertyPath |
||
658 | * @param string $encoding |
||
659 | * @return void |
||
660 | * @throws \Assert\AssertionFailedException |
||
661 | */ |
||
662 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
678 | |||
679 | /** |
||
680 | * Assert that string value is not longer than $maxLength chars. |
||
681 | * |
||
682 | * @param mixed $value |
||
683 | * @param integer $maxLength |
||
684 | * @param string|null $message |
||
685 | * @param string|null $propertyPath |
||
686 | * @param string $encoding |
||
687 | * @return void |
||
688 | * @throws \Assert\AssertionFailedException |
||
689 | */ |
||
690 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
706 | |||
707 | /** |
||
708 | * Assert that string length is between min,max lengths. |
||
709 | * |
||
710 | * @param mixed $value |
||
711 | * @param integer $minLength |
||
712 | * @param integer $maxLength |
||
713 | * @param string|null $message |
||
714 | * @param string|null $propertyPath |
||
715 | * @param string $encoding |
||
716 | * @return void |
||
717 | * @throws \Assert\AssertionFailedException |
||
718 | */ |
||
719 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
747 | |||
748 | /** |
||
749 | * Assert that string starts with a sequence of chars. |
||
750 | * |
||
751 | * @param mixed $string |
||
752 | * @param string $needle |
||
753 | * @param string|null $message |
||
754 | * @param string|null $propertyPath |
||
755 | * @param string $encoding |
||
756 | * @return void |
||
757 | * @throws \Assert\AssertionFailedException |
||
758 | */ |
||
759 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
774 | |||
775 | /** |
||
776 | * Assert that string ends with a sequence of chars. |
||
777 | * |
||
778 | * @param mixed $string |
||
779 | * @param string $needle |
||
780 | * @param string|null $message |
||
781 | * @param string|null $propertyPath |
||
782 | * @param string $encoding |
||
783 | * @return void |
||
784 | * @throws \Assert\AssertionFailedException |
||
785 | */ |
||
786 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
803 | |||
804 | /** |
||
805 | * Assert that string contains a sequence of chars. |
||
806 | * |
||
807 | * @param mixed $string |
||
808 | * @param string $needle |
||
809 | * @param string|null $message |
||
810 | * @param string|null $propertyPath |
||
811 | * @param string $encoding |
||
812 | * @return void |
||
813 | * @throws \Assert\AssertionFailedException |
||
814 | */ |
||
815 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
830 | |||
831 | /** |
||
832 | * Assert that value is in array of choices. |
||
833 | * |
||
834 | * @param mixed $value |
||
835 | * @param array $choices |
||
836 | * @param string|null $message |
||
837 | * @param string|null $propertyPath |
||
838 | * @return void |
||
839 | * @throws \Assert\AssertionFailedException |
||
840 | */ |
||
841 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
853 | |||
854 | /** |
||
855 | * Alias of {@see choice()} |
||
856 | * |
||
857 | * @throws \Assert\AssertionFailedException |
||
858 | */ |
||
859 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
863 | |||
864 | /** |
||
865 | * Assert that value is numeric. |
||
866 | * |
||
867 | * @param mixed $value |
||
868 | * @param string|null $message |
||
869 | * @param string|null $propertyPath |
||
870 | * @return void |
||
871 | * @throws \Assert\AssertionFailedException |
||
872 | */ |
||
873 | public static function numeric($value, $message = null, $propertyPath = null) |
||
884 | |||
885 | /** |
||
886 | * Assert that value is an array. |
||
887 | * |
||
888 | * @param mixed $value |
||
889 | * @param string|null $message |
||
890 | * @param string|null $propertyPath |
||
891 | * @return void |
||
892 | * @throws \Assert\AssertionFailedException |
||
893 | */ |
||
894 | public static function isArray($value, $message = null, $propertyPath = null) |
||
905 | |||
906 | /** |
||
907 | * Assert that value is an array or a traversable object. |
||
908 | * |
||
909 | * @param mixed $value |
||
910 | * @param string|null $message |
||
911 | * @param string|null $propertyPath |
||
912 | * @return void |
||
913 | * @throws \Assert\AssertionFailedException |
||
914 | */ |
||
915 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
926 | |||
927 | /** |
||
928 | * Assert that value is an array or an array-accessible object. |
||
929 | * |
||
930 | * @param mixed $value |
||
931 | * @param string|null $message |
||
932 | * @param string|null $propertyPath |
||
933 | * @return void |
||
934 | * @throws \Assert\AssertionFailedException |
||
935 | */ |
||
936 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
947 | |||
948 | /** |
||
949 | * Assert that key exists in an array |
||
950 | * |
||
951 | * @param mixed $value |
||
952 | * @param string|integer $key |
||
953 | * @param string|null $message |
||
954 | * @param string|null $propertyPath |
||
955 | * @return void |
||
956 | * @throws \Assert\AssertionFailedException |
||
957 | */ |
||
958 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
971 | |||
972 | /** |
||
973 | * Assert that key does not exist in an array |
||
974 | * |
||
975 | * @param mixed $value |
||
976 | * @param string|integer $key |
||
977 | * @param string|null $message |
||
978 | * @param string|null $propertyPath |
||
979 | * @return void |
||
980 | * @throws \Assert\AssertionFailedException |
||
981 | */ |
||
982 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null) |
||
995 | |||
996 | /** |
||
997 | * Assert that key exists in an array/array-accessible object using isset() |
||
998 | * |
||
999 | * @param mixed $value |
||
1000 | * @param string|integer $key |
||
1001 | * @param string|null $message |
||
1002 | * @param string|null $propertyPath |
||
1003 | * @return void |
||
1004 | * @throws \Assert\AssertionFailedException |
||
1005 | */ |
||
1006 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
1019 | |||
1020 | /** |
||
1021 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
1022 | * |
||
1023 | * @param mixed $value |
||
1024 | * @param string|integer $key |
||
1025 | * @param string|null $message |
||
1026 | * @param string|null $propertyPath |
||
1027 | * @return void |
||
1028 | * @throws \Assert\AssertionFailedException |
||
1029 | */ |
||
1030 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
1035 | |||
1036 | /** |
||
1037 | * Assert that value is not blank |
||
1038 | * |
||
1039 | * @param mixed $value |
||
1040 | * @param string|null $message |
||
1041 | * @param string|null $propertyPath |
||
1042 | * @return void |
||
1043 | * @throws \Assert\AssertionFailedException |
||
1044 | */ |
||
1045 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
1056 | |||
1057 | /** |
||
1058 | * Assert that value is instance of given class-name. |
||
1059 | * |
||
1060 | * @param mixed $value |
||
1061 | * @param string $className |
||
1062 | * @param string|null $message |
||
1063 | * @param string|null $propertyPath |
||
1064 | * @return void |
||
1065 | * @throws \Assert\AssertionFailedException |
||
1066 | */ |
||
1067 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1079 | |||
1080 | /** |
||
1081 | * Assert that value is not instance of given class-name. |
||
1082 | * |
||
1083 | * @param mixed $value |
||
1084 | * @param string $className |
||
1085 | * @param string|null $message |
||
1086 | * @param string|null $propertyPath |
||
1087 | * @return void |
||
1088 | * @throws \Assert\AssertionFailedException |
||
1089 | */ |
||
1090 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
1102 | |||
1103 | /** |
||
1104 | * Assert that value is subclass of given class-name. |
||
1105 | * |
||
1106 | * @param mixed $value |
||
1107 | * @param string $className |
||
1108 | * @param string|null $message |
||
1109 | * @param string|null $propertyPath |
||
1110 | * @return void |
||
1111 | * @throws \Assert\AssertionFailedException |
||
1112 | */ |
||
1113 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
1125 | |||
1126 | /** |
||
1127 | * Assert that value is in range of numbers. |
||
1128 | * |
||
1129 | * @param mixed $value |
||
1130 | * @param integer $minValue |
||
1131 | * @param integer $maxValue |
||
1132 | * @param string|null $message |
||
1133 | * @param string|null $propertyPath |
||
1134 | * @return void |
||
1135 | * @throws \Assert\AssertionFailedException |
||
1136 | */ |
||
1137 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
1152 | |||
1153 | /** |
||
1154 | * Assert that a value is at least as big as a given limit |
||
1155 | * |
||
1156 | * @param mixed $value |
||
1157 | * @param mixed $minValue |
||
1158 | * @param string|null $message |
||
1159 | * @param string|null $propertyPath |
||
1160 | * @return void |
||
1161 | * @throws \Assert\AssertionFailedException |
||
1162 | */ |
||
1163 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
1177 | |||
1178 | /** |
||
1179 | * Assert that a number is smaller as a given limit |
||
1180 | * |
||
1181 | * @param mixed $value |
||
1182 | * @param mixed $maxValue |
||
1183 | * @param string|null $message |
||
1184 | * @param string|null $propertyPath |
||
1185 | * @return void |
||
1186 | * @throws \Assert\AssertionFailedException |
||
1187 | */ |
||
1188 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
1202 | |||
1203 | /** |
||
1204 | * Assert that a file exists |
||
1205 | * |
||
1206 | * @param string $value |
||
1207 | * @param string|null $message |
||
1208 | * @param string|null $propertyPath |
||
1209 | * @return void |
||
1210 | * @throws \Assert\AssertionFailedException |
||
1211 | */ |
||
1212 | public static function file($value, $message = null, $propertyPath = null) |
||
1226 | |||
1227 | /** |
||
1228 | * Assert that a directory exists |
||
1229 | * |
||
1230 | * @param string $value |
||
1231 | * @param string|null $message |
||
1232 | * @param string|null $propertyPath |
||
1233 | * @return void |
||
1234 | * @throws \Assert\AssertionFailedException |
||
1235 | */ |
||
1236 | public static function directory($value, $message = null, $propertyPath = null) |
||
1249 | |||
1250 | /** |
||
1251 | * Assert that the value is something readable |
||
1252 | * |
||
1253 | * @param string $value |
||
1254 | * @param string|null $message |
||
1255 | * @param string|null $propertyPath |
||
1256 | * @return void |
||
1257 | * @throws \Assert\AssertionFailedException |
||
1258 | */ |
||
1259 | public static function readable($value, $message = null, $propertyPath = null) |
||
1272 | |||
1273 | /** |
||
1274 | * Assert that the value is something writeable |
||
1275 | * |
||
1276 | * @param string $value |
||
1277 | * @param string|null $message |
||
1278 | * @param string|null $propertyPath |
||
1279 | * @return void |
||
1280 | * @throws \Assert\AssertionFailedException |
||
1281 | */ |
||
1282 | public static function writeable($value, $message = null, $propertyPath = null) |
||
1295 | |||
1296 | /** |
||
1297 | * Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL). |
||
1298 | * |
||
1299 | * @param mixed $value |
||
1300 | * @param string|null $message |
||
1301 | * @param string|null $propertyPath |
||
1302 | * @return void |
||
1303 | * @throws \Assert\AssertionFailedException |
||
1304 | */ |
||
1305 | public static function email($value, $message = null, $propertyPath = null) |
||
1330 | |||
1331 | /** |
||
1332 | * Assert that value is an URL. |
||
1333 | * |
||
1334 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
1335 | * |
||
1336 | * @param mixed $value |
||
1337 | * @param string|null $message |
||
1338 | * @param string|null $propertyPath |
||
1339 | * @return void |
||
1340 | * @throws \Assert\AssertionFailedException |
||
1341 | * |
||
1342 | * |
||
1343 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
1344 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
1345 | */ |
||
1346 | public static function url($value, $message = null, $propertyPath = null) |
||
1379 | |||
1380 | /** |
||
1381 | * Assert that value is alphanumeric. |
||
1382 | * |
||
1383 | * @param mixed $value |
||
1384 | * @param string|null $message |
||
1385 | * @param string|null $propertyPath |
||
1386 | * @return void |
||
1387 | * @throws \Assert\AssertionFailedException |
||
1388 | */ |
||
1389 | public static function alnum($value, $message = null, $propertyPath = null) |
||
1402 | |||
1403 | /** |
||
1404 | * Assert that the value is boolean True. |
||
1405 | * |
||
1406 | * @param mixed $value |
||
1407 | * @param string|null $message |
||
1408 | * @param string|null $propertyPath |
||
1409 | * @return void |
||
1410 | * @throws \Assert\AssertionFailedException |
||
1411 | */ |
||
1412 | public static function true($value, $message = null, $propertyPath = null) |
||
1423 | |||
1424 | /** |
||
1425 | * Assert that the value is boolean False. |
||
1426 | * |
||
1427 | * @param mixed $value |
||
1428 | * @param string|null $message |
||
1429 | * @param string|null $propertyPath |
||
1430 | * @return void |
||
1431 | * @throws \Assert\AssertionFailedException |
||
1432 | */ |
||
1433 | public static function false($value, $message = null, $propertyPath = null) |
||
1444 | |||
1445 | /** |
||
1446 | * Assert that the class exists. |
||
1447 | * |
||
1448 | * @param mixed $value |
||
1449 | * @param string|null $message |
||
1450 | * @param string|null $propertyPath |
||
1451 | * @return void |
||
1452 | * @throws \Assert\AssertionFailedException |
||
1453 | */ |
||
1454 | public static function classExists($value, $message = null, $propertyPath = null) |
||
1465 | |||
1466 | /** |
||
1467 | * Assert that the interface exists. |
||
1468 | * |
||
1469 | * @param mixed $value |
||
1470 | * @param string|null $message |
||
1471 | * @param string|null $propertyPath |
||
1472 | * @return void |
||
1473 | * @throws \Assert\AssertionFailedException |
||
1474 | */ |
||
1475 | public static function interfaceExists($value, $message = null, $propertyPath = null) |
||
1486 | |||
1487 | /** |
||
1488 | * Assert that the class implements the interface |
||
1489 | * |
||
1490 | * @param mixed $class |
||
1491 | * @param string $interfaceName |
||
1492 | * @param string|null $message |
||
1493 | * @param string|null $propertyPath |
||
1494 | * @return void |
||
1495 | * @throws \Assert\AssertionFailedException |
||
1496 | */ |
||
1497 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
1510 | |||
1511 | /** |
||
1512 | * Assert that the given string is a valid json string. |
||
1513 | * |
||
1514 | * NOTICE: |
||
1515 | * Since this does a json_decode to determine its validity |
||
1516 | * you probably should consider, when using the variable |
||
1517 | * content afterwards, just to decode and check for yourself instead |
||
1518 | * of using this assertion. |
||
1519 | * |
||
1520 | * @param mixed $value |
||
1521 | * @param string|null $message |
||
1522 | * @param string|null $propertyPath |
||
1523 | * @return void |
||
1524 | * @throws \Assert\AssertionFailedException |
||
1525 | */ |
||
1526 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
1537 | |||
1538 | /** |
||
1539 | * Assert that the given string is a valid UUID |
||
1540 | * |
||
1541 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
1542 | * |
||
1543 | * @param string $value |
||
1544 | * @param string|null $message |
||
1545 | * @param string|null $propertyPath |
||
1546 | * @return void |
||
1547 | * @throws \Assert\AssertionFailedException |
||
1548 | */ |
||
1549 | public static function uuid($value, $message = null, $propertyPath = null) |
||
1566 | |||
1567 | /** |
||
1568 | * Assert that the given string is a valid E164 Phone Number |
||
1569 | * |
||
1570 | * @link https://en.wikipedia.org/wiki/E.164 |
||
1571 | * |
||
1572 | * @param string $value |
||
1573 | * @param string|null $message |
||
1574 | * @param string|null $propertyPath |
||
1575 | * @return void |
||
1576 | * @throws \Assert\AssertionFailedException |
||
1577 | */ |
||
1578 | public static function e164($value, $message = null, $propertyPath = null) |
||
1589 | |||
1590 | /** |
||
1591 | * Assert that the count of countable is equal to count. |
||
1592 | * |
||
1593 | * @param array|\Countable $countable |
||
1594 | * @param int $count |
||
1595 | * @param string $message |
||
1596 | * @param string $propertyPath |
||
1597 | * @return void |
||
1598 | * @throws \Assert\AssertionFailedException |
||
1599 | */ |
||
1600 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
1611 | |||
1612 | /** |
||
1613 | * static call handler to implement: |
||
1614 | * - "null or assertion" delegation |
||
1615 | * - "all" delegation |
||
1616 | */ |
||
1617 | public static function __callStatic($method, $args) |
||
1653 | |||
1654 | /** |
||
1655 | * Determines if the values array has every choice as key and that this choice has content. |
||
1656 | * |
||
1657 | * @param array $values |
||
1658 | * @param array $choices |
||
1659 | * @param null $message |
||
1660 | * @param null $propertyPath |
||
1661 | */ |
||
1662 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
1671 | |||
1672 | /** |
||
1673 | * Determines that the named method is defined in the provided object. |
||
1674 | * |
||
1675 | * @param string $value |
||
1676 | * @param mixed $object |
||
1677 | * @param null $message |
||
1678 | * @param null $propertyPath |
||
1679 | * |
||
1680 | * @throws |
||
1681 | */ |
||
1682 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
1695 | |||
1696 | /** |
||
1697 | * Determines that the provided value is an object. |
||
1698 | * |
||
1699 | * @param mixed $value |
||
1700 | * @param null $message |
||
1701 | * @param null $propertyPath |
||
1702 | */ |
||
1703 | public static function isObject($value, $message = null, $propertyPath = null) |
||
1715 | |||
1716 | /** |
||
1717 | * Determines if the value is less than given limit. |
||
1718 | * |
||
1719 | * @param mixed $value |
||
1720 | * @param mixed $limit |
||
1721 | * @param null $message |
||
1722 | * @param null $propertyPath |
||
1723 | */ |
||
1724 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
1736 | |||
1737 | /** |
||
1738 | * Determines if the value is less or than given limit. |
||
1739 | * |
||
1740 | * @param mixed $value |
||
1741 | * @param mixed $limit |
||
1742 | * @param null $message |
||
1743 | * @param null $propertyPath |
||
1744 | */ |
||
1745 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1757 | |||
1758 | /** |
||
1759 | * Determines if the value is greater than given limit. |
||
1760 | * |
||
1761 | * @param mixed $value |
||
1762 | * @param mixed $limit |
||
1763 | * @param null $message |
||
1764 | * @param null $propertyPath |
||
1765 | */ |
||
1766 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
1778 | |||
1779 | /** |
||
1780 | * Determines if the value is greater or equal than given limit. |
||
1781 | * |
||
1782 | * @param mixed $value |
||
1783 | * @param mixed $limit |
||
1784 | * @param null $message |
||
1785 | * @param null $propertyPath |
||
1786 | */ |
||
1787 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
1799 | |||
1800 | /** |
||
1801 | * Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit. |
||
1802 | * |
||
1803 | * @param mixed $value |
||
1804 | * @param mixed $lowerLimit |
||
1805 | * @param mixed $upperLimit |
||
1806 | * @param string $message |
||
1807 | * @param string $propertyPath |
||
1808 | */ |
||
1809 | public static function between($value, $lowerLimit, $upperLimit, $message = null, $propertyPath = null) |
||
1822 | |||
1823 | /** |
||
1824 | * Assert that a value is greater than a lower limit, and less than an upper limit. |
||
1825 | * |
||
1826 | * @param mixed $value |
||
1827 | * @param mixed $lowerLimit |
||
1828 | * @param mixed $upperLimit |
||
1829 | * @param string $message |
||
1830 | * @param string $propertyPath |
||
1831 | */ |
||
1832 | public static function betweenExclusive($value, $lowerLimit, $upperLimit, $message = null, $propertyPath = null) |
||
1845 | |||
1846 | /** |
||
1847 | * Assert that date is valid and corresponds to the given format. |
||
1848 | * |
||
1849 | * @param string $value |
||
1850 | * @param string $format supports all of the options date(), except for the following: |
||
1851 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
1852 | * @param string|null $message |
||
1853 | * @param string|null $propertyPath |
||
1854 | * |
||
1855 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
1856 | */ |
||
1857 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
1874 | |||
1875 | /** |
||
1876 | * Determines that the provided value is callable. |
||
1877 | * |
||
1878 | * @param mixed $value |
||
1879 | * @param null $message |
||
1880 | * @param null $propertyPath |
||
1881 | */ |
||
1882 | public static function isCallable($value, $message = null, $propertyPath = null) |
||
1893 | |||
1894 | /** |
||
1895 | * Assert that the provided value is valid according to a callback. |
||
1896 | * |
||
1897 | * If the callback returns `false` the assertion will fail. |
||
1898 | * |
||
1899 | * @param mixed $value |
||
1900 | * @param callable $callback |
||
1901 | * @param string|null $message |
||
1902 | * @param string|null $propertyPath |
||
1903 | */ |
||
1904 | public static function satisfy($value, $callback, $message = null, $propertyPath = null) |
||
1917 | |||
1918 | /** |
||
1919 | * Assert that value is an IPv4 or IPv6 address |
||
1920 | * (using input_filter/FILTER_VALIDATE_IP). |
||
1921 | * |
||
1922 | * @param string $value |
||
1923 | * @param null|int $flag |
||
1924 | * @param string|null $message |
||
1925 | * @param string|null $propertyPath |
||
1926 | * |
||
1927 | * @link http://php.net/manual/filter.filters.flags.php |
||
1928 | */ |
||
1929 | public static function ip($value, $flag = null, $message = null, $propertyPath = null) |
||
1940 | |||
1941 | /** |
||
1942 | * Assert that value is an IPv4 address |
||
1943 | * (using input_filter/FILTER_VALIDATE_IP). |
||
1944 | * |
||
1945 | * @param string $value |
||
1946 | * @param null|int $flag |
||
1947 | * @param string|null $message |
||
1948 | * @param string|null $propertyPath |
||
1949 | * |
||
1950 | * @link http://php.net/manual/filter.filters.flags.php |
||
1951 | */ |
||
1952 | public static function ipv4($value, $flag = null, $message = null, $propertyPath = null) |
||
1956 | |||
1957 | /** |
||
1958 | * Assert that value is an IPv6 address |
||
1959 | * (using input_filter/FILTER_VALIDATE_IP). |
||
1960 | * |
||
1961 | * @param string $value |
||
1962 | * @param null|int $flag |
||
1963 | * @param string|null $message |
||
1964 | * @param string|null $propertyPath |
||
1965 | * |
||
1966 | * @link http://php.net/manual/filter.filters.flags.php |
||
1967 | */ |
||
1968 | public static function ipv6($value, $flag = null, $message = null, $propertyPath = null) |
||
1972 | |||
1973 | /** |
||
1974 | * Make a string version of a value. |
||
1975 | * |
||
1976 | * @param mixed $value |
||
1977 | * @return string |
||
1978 | */ |
||
1979 | protected static function stringify($value) |
||
2013 | } |
||
2014 |