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 |
||
| 150 | class Assertion |
||
| 151 | { |
||
| 152 | const INVALID_FLOAT = 9; |
||
| 153 | const INVALID_INTEGER = 10; |
||
| 154 | const INVALID_DIGIT = 11; |
||
| 155 | const INVALID_INTEGERISH = 12; |
||
| 156 | const INVALID_BOOLEAN = 13; |
||
| 157 | const VALUE_EMPTY = 14; |
||
| 158 | const VALUE_NULL = 15; |
||
| 159 | const INVALID_STRING = 16; |
||
| 160 | const INVALID_REGEX = 17; |
||
| 161 | const INVALID_MIN_LENGTH = 18; |
||
| 162 | const INVALID_MAX_LENGTH = 19; |
||
| 163 | const INVALID_STRING_START = 20; |
||
| 164 | const INVALID_STRING_CONTAINS = 21; |
||
| 165 | const INVALID_CHOICE = 22; |
||
| 166 | const INVALID_NUMERIC = 23; |
||
| 167 | const INVALID_ARRAY = 24; |
||
| 168 | const INVALID_KEY_EXISTS = 26; |
||
| 169 | const INVALID_NOT_BLANK = 27; |
||
| 170 | const INVALID_INSTANCE_OF = 28; |
||
| 171 | const INVALID_SUBCLASS_OF = 29; |
||
| 172 | const INVALID_RANGE = 30; |
||
| 173 | const INVALID_ALNUM = 31; |
||
| 174 | const INVALID_TRUE = 32; |
||
| 175 | const INVALID_EQ = 33; |
||
| 176 | const INVALID_SAME = 34; |
||
| 177 | const INVALID_MIN = 35; |
||
| 178 | const INVALID_MAX = 36; |
||
| 179 | const INVALID_LENGTH = 37; |
||
| 180 | const INVALID_FALSE = 38; |
||
| 181 | const INVALID_STRING_END = 39; |
||
| 182 | const INVALID_UUID = 40; |
||
| 183 | const INVALID_COUNT = 41; |
||
| 184 | const INVALID_NOT_EQ = 42; |
||
| 185 | const INVALID_NOT_SAME = 43; |
||
| 186 | const INVALID_TRAVERSABLE = 44; |
||
| 187 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
| 188 | const INVALID_KEY_ISSET = 46; |
||
| 189 | const INVALID_VALUE_IN_ARRAY = 47; |
||
| 190 | const INVALID_DIRECTORY = 101; |
||
| 191 | const INVALID_FILE = 102; |
||
| 192 | const INVALID_READABLE = 103; |
||
| 193 | const INVALID_WRITEABLE = 104; |
||
| 194 | const INVALID_CLASS = 105; |
||
| 195 | const INVALID_EMAIL = 201; |
||
| 196 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
| 197 | const INVALID_URL = 203; |
||
| 198 | const INVALID_NOT_INSTANCE_OF = 204; |
||
| 199 | const VALUE_NOT_EMPTY = 205; |
||
| 200 | const INVALID_JSON_STRING = 206; |
||
| 201 | const INVALID_OBJECT = 207; |
||
| 202 | const INVALID_METHOD = 208; |
||
| 203 | const INVALID_SCALAR = 209; |
||
| 204 | const INVALID_LESS = 210; |
||
| 205 | const INVALID_LESS_OR_EQUAL = 211; |
||
| 206 | const INVALID_GREATER = 212; |
||
| 207 | const INVALID_GREATER_OR_EQUAL = 213; |
||
| 208 | const INVALID_DATE = 214; |
||
| 209 | const INVALID_CALLABLE = 215; |
||
| 210 | const INVALID_KEY_NOT_EXISTS = 216; |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Exception to throw when an assertion failed. |
||
| 214 | * |
||
| 215 | * @var string |
||
| 216 | */ |
||
| 217 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Helper method that handles building the assertion failure exceptions. |
||
| 221 | * They are returned from this method so that the stack trace still shows |
||
| 222 | * the assertions method. |
||
| 223 | */ |
||
| 224 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Assert that two values are equal (using == ). |
||
| 232 | * |
||
| 233 | * @param mixed $value |
||
| 234 | * @param mixed $value2 |
||
| 235 | * @param string|null $message |
||
| 236 | * @param string|null $propertyPath |
||
| 237 | * @return void |
||
| 238 | * @throws \Assert\AssertionFailedException |
||
| 239 | */ |
||
| 240 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Assert that two values are the same (using ===). |
||
| 255 | * |
||
| 256 | * @param mixed $value |
||
| 257 | * @param mixed $value2 |
||
| 258 | * @param string|null $message |
||
| 259 | * @param string|null $propertyPath |
||
| 260 | * @return void |
||
| 261 | * @throws \Assert\AssertionFailedException |
||
| 262 | */ |
||
| 263 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Assert that two values are not equal (using == ). |
||
| 278 | * |
||
| 279 | * @param mixed $value1 |
||
| 280 | * @param mixed $value2 |
||
| 281 | * @param string|null $message |
||
| 282 | * @param string|null $propertyPath |
||
| 283 | * @return void |
||
| 284 | * @throws \Assert\AssertionFailedException |
||
| 285 | */ |
||
| 286 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Assert that two values are not the same (using === ). |
||
| 300 | * |
||
| 301 | * @param mixed $value1 |
||
| 302 | * @param mixed $value2 |
||
| 303 | * @param string|null $message |
||
| 304 | * @param string|null $propertyPath |
||
| 305 | * @return void |
||
| 306 | * @throws \Assert\AssertionFailedException |
||
| 307 | */ |
||
| 308 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Assert that value is not in array of choices. |
||
| 322 | * |
||
| 323 | * @param mixed $value |
||
| 324 | * @param array $choices |
||
| 325 | * @param string|null $message |
||
| 326 | * @param string|null $propertyPath |
||
| 327 | * @return void |
||
| 328 | * @throws \Assert\AssertionFailedException |
||
| 329 | */ |
||
| 330 | public static function notInArray($value, array $choices, $message = null, $propertyPath = null) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Assert that value is a php integer. |
||
| 344 | * |
||
| 345 | * @param mixed $value |
||
| 346 | * @param string|null $message |
||
| 347 | * @param string|null $propertyPath |
||
| 348 | * @return void |
||
| 349 | * @throws \Assert\AssertionFailedException |
||
| 350 | */ |
||
| 351 | public static function integer($value, $message = null, $propertyPath = null) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Assert that value is a php float. |
||
| 365 | * |
||
| 366 | * @param mixed $value |
||
| 367 | * @param string|null $message |
||
| 368 | * @param string|null $propertyPath |
||
| 369 | * @return void |
||
| 370 | * @throws \Assert\AssertionFailedException |
||
| 371 | */ |
||
| 372 | public static function float($value, $message = null, $propertyPath = null) |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Validates if an integer or integerish is a digit. |
||
| 386 | * |
||
| 387 | * @param mixed $value |
||
| 388 | * @param string|null $message |
||
| 389 | * @param string|null $propertyPath |
||
| 390 | * @return void |
||
| 391 | * @throws \Assert\AssertionFailedException |
||
| 392 | */ |
||
| 393 | public static function digit($value, $message = null, $propertyPath = null) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Assert that value is a php integer'ish. |
||
| 407 | * |
||
| 408 | * @param mixed $value |
||
| 409 | * @param string|null $message |
||
| 410 | * @param string|null $propertyPath |
||
| 411 | * @return void |
||
| 412 | * @throws \Assert\AssertionFailedException |
||
| 413 | */ |
||
| 414 | public static function integerish($value, $message = null, $propertyPath = null) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Assert that value is php boolean |
||
| 428 | * |
||
| 429 | * @param mixed $value |
||
| 430 | * @param string|null $message |
||
| 431 | * @param string|null $propertyPath |
||
| 432 | * @return void |
||
| 433 | * @throws \Assert\AssertionFailedException |
||
| 434 | */ |
||
| 435 | public static function boolean($value, $message = null, $propertyPath = null) |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Assert that value is a PHP scalar |
||
| 449 | * |
||
| 450 | * @param mixed $value |
||
| 451 | * @param string|null $message |
||
| 452 | * @param string|null $propertyPath |
||
| 453 | * @return void |
||
| 454 | * @throws \Assert\AssertionFailedException |
||
| 455 | */ |
||
| 456 | public static function scalar($value, $message = null, $propertyPath = null) |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Assert that value is not empty |
||
| 470 | * |
||
| 471 | * @param mixed $value |
||
| 472 | * @param string|null $message |
||
| 473 | * @param string|null $propertyPath |
||
| 474 | * @return void |
||
| 475 | * @throws \Assert\AssertionFailedException |
||
| 476 | */ |
||
| 477 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
| 488 | |||
| 489 | /** |
||
| 490 | * Assert that value is empty |
||
| 491 | * |
||
| 492 | * @param mixed $value |
||
| 493 | * @param string|null $message |
||
| 494 | * @param string|null $propertyPath |
||
| 495 | * @return void |
||
| 496 | * @throws \Assert\AssertionFailedException |
||
| 497 | */ |
||
| 498 | public static function noContent($value, $message = null, $propertyPath = null) |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Assert that value is not null |
||
| 512 | * |
||
| 513 | * @param mixed $value |
||
| 514 | * @param string|null $message |
||
| 515 | * @param string|null $propertyPath |
||
| 516 | * @return void |
||
| 517 | * @throws \Assert\AssertionFailedException |
||
| 518 | */ |
||
| 519 | public static function notNull($value, $message = null, $propertyPath = null) |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Assert that value is a string |
||
| 533 | * |
||
| 534 | * @param mixed $value |
||
| 535 | * @param string|null $message |
||
| 536 | * @param string|null $propertyPath |
||
| 537 | * @return void |
||
| 538 | * @throws \Assert\AssertionFailedException |
||
| 539 | */ |
||
| 540 | public static function string($value, $message = null, $propertyPath = null) |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Assert that value matches a regex |
||
| 555 | * |
||
| 556 | * @param mixed $value |
||
| 557 | * @param string $pattern |
||
| 558 | * @param string|null $message |
||
| 559 | * @param string|null $propertyPath |
||
| 560 | * @return void |
||
| 561 | * @throws \Assert\AssertionFailedException |
||
| 562 | */ |
||
| 563 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
| 576 | |||
| 577 | /** |
||
| 578 | * Assert that string has a given length. |
||
| 579 | * |
||
| 580 | * @param mixed $value |
||
| 581 | * @param int $length |
||
| 582 | * @param string|null $message |
||
| 583 | * @param string|null $propertyPath |
||
| 584 | * @param string $encoding |
||
| 585 | * @return void |
||
| 586 | * @throws \Assert\AssertionFailedException |
||
| 587 | */ |
||
| 588 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 604 | |||
| 605 | /** |
||
| 606 | * Assert that a string is at least $minLength chars long. |
||
| 607 | * |
||
| 608 | * @param mixed $value |
||
| 609 | * @param int $minLength |
||
| 610 | * @param string|null $message |
||
| 611 | * @param string|null $propertyPath |
||
| 612 | * @param string $encoding |
||
| 613 | * @return void |
||
| 614 | * @throws \Assert\AssertionFailedException |
||
| 615 | */ |
||
| 616 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Assert that string value is not longer than $maxLength chars. |
||
| 635 | * |
||
| 636 | * @param mixed $value |
||
| 637 | * @param integer $maxLength |
||
| 638 | * @param string|null $message |
||
| 639 | * @param string|null $propertyPath |
||
| 640 | * @param string $encoding |
||
| 641 | * @return void |
||
| 642 | * @throws \Assert\AssertionFailedException |
||
| 643 | */ |
||
| 644 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Assert that string length is between min,max lengths. |
||
| 663 | * |
||
| 664 | * @param mixed $value |
||
| 665 | * @param integer $minLength |
||
| 666 | * @param integer $maxLength |
||
| 667 | * @param string|null $message |
||
| 668 | * @param string|null $propertyPath |
||
| 669 | * @param string $encoding |
||
| 670 | * @return void |
||
| 671 | * @throws \Assert\AssertionFailedException |
||
| 672 | */ |
||
| 673 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Assert that string starts with a sequence of chars. |
||
| 704 | * |
||
| 705 | * @param mixed $string |
||
| 706 | * @param string $needle |
||
| 707 | * @param string|null $message |
||
| 708 | * @param string|null $propertyPath |
||
| 709 | * @param string $encoding |
||
| 710 | * @return void |
||
| 711 | * @throws \Assert\AssertionFailedException |
||
| 712 | */ |
||
| 713 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Assert that string ends with a sequence of chars. |
||
| 731 | * |
||
| 732 | * @param mixed $string |
||
| 733 | * @param string $needle |
||
| 734 | * @param string|null $message |
||
| 735 | * @param string|null $propertyPath |
||
| 736 | * @param string $encoding |
||
| 737 | * @return void |
||
| 738 | * @throws \Assert\AssertionFailedException |
||
| 739 | */ |
||
| 740 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 757 | |||
| 758 | /** |
||
| 759 | * Assert that string contains a sequence of chars. |
||
| 760 | * |
||
| 761 | * @param mixed $string |
||
| 762 | * @param string $needle |
||
| 763 | * @param string|null $message |
||
| 764 | * @param string|null $propertyPath |
||
| 765 | * @param string $encoding |
||
| 766 | * @return void |
||
| 767 | * @throws \Assert\AssertionFailedException |
||
| 768 | */ |
||
| 769 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 784 | |||
| 785 | /** |
||
| 786 | * Assert that value is in array of choices. |
||
| 787 | * |
||
| 788 | * @param mixed $value |
||
| 789 | * @param array $choices |
||
| 790 | * @param string|null $message |
||
| 791 | * @param string|null $propertyPath |
||
| 792 | * @return void |
||
| 793 | * @throws \Assert\AssertionFailedException |
||
| 794 | */ |
||
| 795 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
| 807 | |||
| 808 | /** |
||
| 809 | * Alias of {@see choice()} |
||
| 810 | * |
||
| 811 | * @throws \Assert\AssertionFailedException |
||
| 812 | */ |
||
| 813 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
| 817 | |||
| 818 | /** |
||
| 819 | * Assert that value is numeric. |
||
| 820 | * |
||
| 821 | * @param mixed $value |
||
| 822 | * @param string|null $message |
||
| 823 | * @param string|null $propertyPath |
||
| 824 | * @return void |
||
| 825 | * @throws \Assert\AssertionFailedException |
||
| 826 | */ |
||
| 827 | public static function numeric($value, $message = null, $propertyPath = null) |
||
| 838 | |||
| 839 | /** |
||
| 840 | * Assert that value is an array. |
||
| 841 | * |
||
| 842 | * @param mixed $value |
||
| 843 | * @param string|null $message |
||
| 844 | * @param string|null $propertyPath |
||
| 845 | * @return void |
||
| 846 | * @throws \Assert\AssertionFailedException |
||
| 847 | */ |
||
| 848 | public static function isArray($value, $message = null, $propertyPath = null) |
||
| 859 | |||
| 860 | /** |
||
| 861 | * Assert that value is an array or a traversable object. |
||
| 862 | * |
||
| 863 | * @param mixed $value |
||
| 864 | * @param string|null $message |
||
| 865 | * @param string|null $propertyPath |
||
| 866 | * @return void |
||
| 867 | * @throws \Assert\AssertionFailedException |
||
| 868 | */ |
||
| 869 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
| 880 | |||
| 881 | /** |
||
| 882 | * Assert that value is an array or an array-accessible object. |
||
| 883 | * |
||
| 884 | * @param mixed $value |
||
| 885 | * @param string|null $message |
||
| 886 | * @param string|null $propertyPath |
||
| 887 | * @return void |
||
| 888 | * @throws \Assert\AssertionFailedException |
||
| 889 | */ |
||
| 890 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
| 901 | |||
| 902 | /** |
||
| 903 | * Assert that key exists in an array |
||
| 904 | * |
||
| 905 | * @param mixed $value |
||
| 906 | * @param string|integer $key |
||
| 907 | * @param string|null $message |
||
| 908 | * @param string|null $propertyPath |
||
| 909 | * @return void |
||
| 910 | * @throws \Assert\AssertionFailedException |
||
| 911 | */ |
||
| 912 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
| 925 | |||
| 926 | /** |
||
| 927 | * Assert that key does not exist in an array |
||
| 928 | * |
||
| 929 | * @param mixed $value |
||
| 930 | * @param string|integer $key |
||
| 931 | * @param string|null $message |
||
| 932 | * @param string|null $propertyPath |
||
| 933 | * @return void |
||
| 934 | * @throws \Assert\AssertionFailedException |
||
| 935 | */ |
||
| 936 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null) |
||
| 949 | |||
| 950 | /** |
||
| 951 | * Assert that key exists in an array/array-accessible object using isset() |
||
| 952 | * |
||
| 953 | * @param mixed $value |
||
| 954 | * @param string|integer $key |
||
| 955 | * @param string|null $message |
||
| 956 | * @param string|null $propertyPath |
||
| 957 | * @return void |
||
| 958 | * @throws \Assert\AssertionFailedException |
||
| 959 | */ |
||
| 960 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
| 973 | |||
| 974 | /** |
||
| 975 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
| 976 | * |
||
| 977 | * @param mixed $value |
||
| 978 | * @param string|integer $key |
||
| 979 | * @param string|null $message |
||
| 980 | * @param string|null $propertyPath |
||
| 981 | * @return void |
||
| 982 | * @throws \Assert\AssertionFailedException |
||
| 983 | */ |
||
| 984 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
| 989 | |||
| 990 | /** |
||
| 991 | * Assert that value is not blank |
||
| 992 | * |
||
| 993 | * @param mixed $value |
||
| 994 | * @param string|null $message |
||
| 995 | * @param string|null $propertyPath |
||
| 996 | * @return void |
||
| 997 | * @throws \Assert\AssertionFailedException |
||
| 998 | */ |
||
| 999 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
| 1010 | |||
| 1011 | /** |
||
| 1012 | * Assert that value is instance of given class-name. |
||
| 1013 | * |
||
| 1014 | * @param mixed $value |
||
| 1015 | * @param string $className |
||
| 1016 | * @param string|null $message |
||
| 1017 | * @param string|null $propertyPath |
||
| 1018 | * @return void |
||
| 1019 | * @throws \Assert\AssertionFailedException |
||
| 1020 | */ |
||
| 1021 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
| 1033 | |||
| 1034 | /** |
||
| 1035 | * Assert that value is not instance of given class-name. |
||
| 1036 | * |
||
| 1037 | * @param mixed $value |
||
| 1038 | * @param string $className |
||
| 1039 | * @param string|null $message |
||
| 1040 | * @param string|null $propertyPath |
||
| 1041 | * @return void |
||
| 1042 | * @throws \Assert\AssertionFailedException |
||
| 1043 | */ |
||
| 1044 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
| 1056 | |||
| 1057 | /** |
||
| 1058 | * Assert that value is subclass 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 subclassOf($value, $className, $message = null, $propertyPath = null) |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * Assert that value is in range of numbers. |
||
| 1082 | * |
||
| 1083 | * @param mixed $value |
||
| 1084 | * @param integer $minValue |
||
| 1085 | * @param integer $maxValue |
||
| 1086 | * @param string|null $message |
||
| 1087 | * @param string|null $propertyPath |
||
| 1088 | * @return void |
||
| 1089 | * @throws \Assert\AssertionFailedException |
||
| 1090 | */ |
||
| 1091 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
| 1106 | |||
| 1107 | /** |
||
| 1108 | * Assert that a value is at least as big as a given limit |
||
| 1109 | * |
||
| 1110 | * @param mixed $value |
||
| 1111 | * @param mixed $minValue |
||
| 1112 | * @param string|null $message |
||
| 1113 | * @param string|null $propertyPath |
||
| 1114 | * @return void |
||
| 1115 | * @throws \Assert\AssertionFailedException |
||
| 1116 | */ |
||
| 1117 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
| 1131 | |||
| 1132 | /** |
||
| 1133 | * Assert that a number is smaller as a given limit |
||
| 1134 | * |
||
| 1135 | * @param mixed $value |
||
| 1136 | * @param mixed $maxValue |
||
| 1137 | * @param string|null $message |
||
| 1138 | * @param string|null $propertyPath |
||
| 1139 | * @return void |
||
| 1140 | * @throws \Assert\AssertionFailedException |
||
| 1141 | */ |
||
| 1142 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
| 1156 | |||
| 1157 | /** |
||
| 1158 | * Assert that a file exists |
||
| 1159 | * |
||
| 1160 | * @param string $value |
||
| 1161 | * @param string|null $message |
||
| 1162 | * @param string|null $propertyPath |
||
| 1163 | * @return void |
||
| 1164 | * @throws \Assert\AssertionFailedException |
||
| 1165 | */ |
||
| 1166 | public static function file($value, $message = null, $propertyPath = null) |
||
| 1180 | |||
| 1181 | /** |
||
| 1182 | * Assert that a directory exists |
||
| 1183 | * |
||
| 1184 | * @param string $value |
||
| 1185 | * @param string|null $message |
||
| 1186 | * @param string|null $propertyPath |
||
| 1187 | * @return void |
||
| 1188 | * @throws \Assert\AssertionFailedException |
||
| 1189 | */ |
||
| 1190 | public static function directory($value, $message = null, $propertyPath = null) |
||
| 1203 | |||
| 1204 | /** |
||
| 1205 | * Assert that the value is something readable |
||
| 1206 | * |
||
| 1207 | * @param string $value |
||
| 1208 | * @param string|null $message |
||
| 1209 | * @param string|null $propertyPath |
||
| 1210 | * @return void |
||
| 1211 | * @throws \Assert\AssertionFailedException |
||
| 1212 | */ |
||
| 1213 | public static function readable($value, $message = null, $propertyPath = null) |
||
| 1226 | |||
| 1227 | /** |
||
| 1228 | * Assert that the value is something writeable |
||
| 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 writeable($value, $message = null, $propertyPath = null) |
||
| 1249 | |||
| 1250 | /** |
||
| 1251 | * Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL). |
||
| 1252 | * |
||
| 1253 | * @param mixed $value |
||
| 1254 | * @param string|null $message |
||
| 1255 | * @param string|null $propertyPath |
||
| 1256 | * @return void |
||
| 1257 | * @throws \Assert\AssertionFailedException |
||
| 1258 | */ |
||
| 1259 | public static function email($value, $message = null, $propertyPath = null) |
||
| 1284 | |||
| 1285 | /** |
||
| 1286 | * Assert that value is an URL. |
||
| 1287 | * |
||
| 1288 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
| 1289 | * |
||
| 1290 | * @param mixed $value |
||
| 1291 | * @param string|null $message |
||
| 1292 | * @param string|null $propertyPath |
||
| 1293 | * @return void |
||
| 1294 | * @throws \Assert\AssertionFailedException |
||
| 1295 | * |
||
| 1296 | * |
||
| 1297 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
| 1298 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
| 1299 | */ |
||
| 1300 | public static function url($value, $message = null, $propertyPath = null) |
||
| 1333 | |||
| 1334 | /** |
||
| 1335 | * Assert that value is alphanumeric. |
||
| 1336 | * |
||
| 1337 | * @param mixed $value |
||
| 1338 | * @param string|null $message |
||
| 1339 | * @param string|null $propertyPath |
||
| 1340 | * @return void |
||
| 1341 | * @throws \Assert\AssertionFailedException |
||
| 1342 | */ |
||
| 1343 | public static function alnum($value, $message = null, $propertyPath = null) |
||
| 1356 | |||
| 1357 | /** |
||
| 1358 | * Assert that the value is boolean True. |
||
| 1359 | * |
||
| 1360 | * @param mixed $value |
||
| 1361 | * @param string|null $message |
||
| 1362 | * @param string|null $propertyPath |
||
| 1363 | * @return void |
||
| 1364 | * @throws \Assert\AssertionFailedException |
||
| 1365 | */ |
||
| 1366 | public static function true($value, $message = null, $propertyPath = null) |
||
| 1377 | |||
| 1378 | /** |
||
| 1379 | * Assert that the value is boolean False. |
||
| 1380 | * |
||
| 1381 | * @param mixed $value |
||
| 1382 | * @param string|null $message |
||
| 1383 | * @param string|null $propertyPath |
||
| 1384 | * @return void |
||
| 1385 | * @throws \Assert\AssertionFailedException |
||
| 1386 | */ |
||
| 1387 | public static function false($value, $message = null, $propertyPath = null) |
||
| 1398 | |||
| 1399 | /** |
||
| 1400 | * Assert that the class exists. |
||
| 1401 | * |
||
| 1402 | * @param mixed $value |
||
| 1403 | * @param string|null $message |
||
| 1404 | * @param string|null $propertyPath |
||
| 1405 | * @return void |
||
| 1406 | * @throws \Assert\AssertionFailedException |
||
| 1407 | */ |
||
| 1408 | public static function classExists($value, $message = null, $propertyPath = null) |
||
| 1419 | |||
| 1420 | /** |
||
| 1421 | * Assert that the class implements the interface |
||
| 1422 | * |
||
| 1423 | * @param mixed $class |
||
| 1424 | * @param string $interfaceName |
||
| 1425 | * @param string|null $message |
||
| 1426 | * @param string|null $propertyPath |
||
| 1427 | * @return void |
||
| 1428 | * @throws \Assert\AssertionFailedException |
||
| 1429 | */ |
||
| 1430 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
| 1443 | |||
| 1444 | /** |
||
| 1445 | * Assert that the given string is a valid json string. |
||
| 1446 | * |
||
| 1447 | * NOTICE: |
||
| 1448 | * Since this does a json_decode to determine its validity |
||
| 1449 | * you probably should consider, when using the variable |
||
| 1450 | * content afterwards, just to decode and check for yourself instead |
||
| 1451 | * of using this assertion. |
||
| 1452 | * |
||
| 1453 | * @param mixed $value |
||
| 1454 | * @param string|null $message |
||
| 1455 | * @param string|null $propertyPath |
||
| 1456 | * @return void |
||
| 1457 | * @throws \Assert\AssertionFailedException |
||
| 1458 | */ |
||
| 1459 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
| 1470 | |||
| 1471 | /** |
||
| 1472 | * Assert that the given string is a valid UUID |
||
| 1473 | * |
||
| 1474 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
| 1475 | * |
||
| 1476 | * @param string $value |
||
| 1477 | * @param string|null $message |
||
| 1478 | * @param string|null $propertyPath |
||
| 1479 | * @return void |
||
| 1480 | * @throws \Assert\AssertionFailedException |
||
| 1481 | */ |
||
| 1482 | public static function uuid($value, $message = null, $propertyPath = null) |
||
| 1499 | |||
| 1500 | /** |
||
| 1501 | * Assert that the count of countable is equal to count. |
||
| 1502 | * |
||
| 1503 | * @param array|\Countable $countable |
||
| 1504 | * @param int $count |
||
| 1505 | * @param string $message |
||
| 1506 | * @param string $propertyPath |
||
| 1507 | * @return void |
||
| 1508 | * @throws \Assert\AssertionFailedException |
||
| 1509 | */ |
||
| 1510 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
| 1521 | |||
| 1522 | /** |
||
| 1523 | * static call handler to implement: |
||
| 1524 | * - "null or assertion" delegation |
||
| 1525 | * - "all" delegation |
||
| 1526 | */ |
||
| 1527 | public static function __callStatic($method, $args) |
||
| 1563 | |||
| 1564 | /** |
||
| 1565 | * Determines if the values array has every choice as key and that this choice has content. |
||
| 1566 | * |
||
| 1567 | * @param array $values |
||
| 1568 | * @param array $choices |
||
| 1569 | * @param null $message |
||
| 1570 | * @param null $propertyPath |
||
| 1571 | */ |
||
| 1572 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
| 1581 | |||
| 1582 | /** |
||
| 1583 | * Determines that the named method is defined in the provided object. |
||
| 1584 | * |
||
| 1585 | * @param string $value |
||
| 1586 | * @param mixed $object |
||
| 1587 | * @param null $message |
||
| 1588 | * @param null $propertyPath |
||
| 1589 | * |
||
| 1590 | * @throws |
||
| 1591 | */ |
||
| 1592 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
| 1605 | |||
| 1606 | /** |
||
| 1607 | * Determines that the provided value is an object. |
||
| 1608 | * |
||
| 1609 | * @param mixed $value |
||
| 1610 | * @param null $message |
||
| 1611 | * @param null $propertyPath |
||
| 1612 | */ |
||
| 1613 | public static function isObject($value, $message = null, $propertyPath = null) |
||
| 1625 | |||
| 1626 | /** |
||
| 1627 | * Determines if the value is less than given limit. |
||
| 1628 | * |
||
| 1629 | * @param mixed $value |
||
| 1630 | * @param mixed $limit |
||
| 1631 | * @param null $message |
||
| 1632 | * @param null $propertyPath |
||
| 1633 | */ |
||
| 1634 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1646 | |||
| 1647 | /** |
||
| 1648 | * Determines if the value is less or than given limit. |
||
| 1649 | * |
||
| 1650 | * @param mixed $value |
||
| 1651 | * @param mixed $limit |
||
| 1652 | * @param null $message |
||
| 1653 | * @param null $propertyPath |
||
| 1654 | */ |
||
| 1655 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1667 | |||
| 1668 | /** |
||
| 1669 | * Determines if the value is greater than given limit. |
||
| 1670 | * |
||
| 1671 | * @param mixed $value |
||
| 1672 | * @param mixed $limit |
||
| 1673 | * @param null $message |
||
| 1674 | * @param null $propertyPath |
||
| 1675 | */ |
||
| 1676 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1688 | |||
| 1689 | /** |
||
| 1690 | * Determines if the value is greater or equal than given limit. |
||
| 1691 | * |
||
| 1692 | * @param mixed $value |
||
| 1693 | * @param mixed $limit |
||
| 1694 | * @param null $message |
||
| 1695 | * @param null $propertyPath |
||
| 1696 | */ |
||
| 1697 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1709 | |||
| 1710 | /** |
||
| 1711 | * Assert that date is valid and corresponds to the given format. |
||
| 1712 | * |
||
| 1713 | * @param string $value |
||
| 1714 | * @param string $format supports all of the options date(), except for the following: |
||
| 1715 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
| 1716 | * @param string|null $message |
||
| 1717 | * @param string|null $propertyPath |
||
| 1718 | * |
||
| 1719 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
| 1720 | */ |
||
| 1721 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
| 1738 | |||
| 1739 | /** |
||
| 1740 | * Determines that the provided value is callable. |
||
| 1741 | * |
||
| 1742 | * @param mixed $value |
||
| 1743 | * @param null $message |
||
| 1744 | * @param null $propertyPath |
||
| 1745 | */ |
||
| 1746 | public static function isCallable($value, $message = null, $propertyPath = null) |
||
| 1757 | |||
| 1758 | /** |
||
| 1759 | * Make a string version of a value. |
||
| 1760 | * |
||
| 1761 | * @param mixed $value |
||
| 1762 | * @return string |
||
| 1763 | */ |
||
| 1764 | protected static function stringify($value) |
||
| 1798 | } |
||
| 1799 | |||
| 1800 |