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 |
||
| 170 | class Assertion |
||
| 171 | { |
||
| 172 | const INVALID_FLOAT = 9; |
||
| 173 | const INVALID_INTEGER = 10; |
||
| 174 | const INVALID_DIGIT = 11; |
||
| 175 | const INVALID_INTEGERISH = 12; |
||
| 176 | const INVALID_BOOLEAN = 13; |
||
| 177 | const VALUE_EMPTY = 14; |
||
| 178 | const VALUE_NULL = 15; |
||
| 179 | const VALUE_NOT_NULL = 25; |
||
| 180 | const INVALID_STRING = 16; |
||
| 181 | const INVALID_REGEX = 17; |
||
| 182 | const INVALID_MIN_LENGTH = 18; |
||
| 183 | const INVALID_MAX_LENGTH = 19; |
||
| 184 | const INVALID_STRING_START = 20; |
||
| 185 | const INVALID_STRING_CONTAINS = 21; |
||
| 186 | const INVALID_CHOICE = 22; |
||
| 187 | const INVALID_NUMERIC = 23; |
||
| 188 | const INVALID_ARRAY = 24; |
||
| 189 | const INVALID_KEY_EXISTS = 26; |
||
| 190 | const INVALID_NOT_BLANK = 27; |
||
| 191 | const INVALID_INSTANCE_OF = 28; |
||
| 192 | const INVALID_SUBCLASS_OF = 29; |
||
| 193 | const INVALID_RANGE = 30; |
||
| 194 | const INVALID_ALNUM = 31; |
||
| 195 | const INVALID_TRUE = 32; |
||
| 196 | const INVALID_EQ = 33; |
||
| 197 | const INVALID_SAME = 34; |
||
| 198 | const INVALID_MIN = 35; |
||
| 199 | const INVALID_MAX = 36; |
||
| 200 | const INVALID_LENGTH = 37; |
||
| 201 | const INVALID_FALSE = 38; |
||
| 202 | const INVALID_STRING_END = 39; |
||
| 203 | const INVALID_UUID = 40; |
||
| 204 | const INVALID_COUNT = 41; |
||
| 205 | const INVALID_NOT_EQ = 42; |
||
| 206 | const INVALID_NOT_SAME = 43; |
||
| 207 | const INVALID_TRAVERSABLE = 44; |
||
| 208 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
| 209 | const INVALID_KEY_ISSET = 46; |
||
| 210 | const INVALID_VALUE_IN_ARRAY = 47; |
||
| 211 | const INVALID_E164 = 48; |
||
| 212 | const INVALID_DIRECTORY = 101; |
||
| 213 | const INVALID_FILE = 102; |
||
| 214 | const INVALID_READABLE = 103; |
||
| 215 | const INVALID_WRITEABLE = 104; |
||
| 216 | const INVALID_CLASS = 105; |
||
| 217 | const INVALID_INTERFACE = 106; |
||
| 218 | const INVALID_EMAIL = 201; |
||
| 219 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
| 220 | const INVALID_URL = 203; |
||
| 221 | const INVALID_NOT_INSTANCE_OF = 204; |
||
| 222 | const VALUE_NOT_EMPTY = 205; |
||
| 223 | const INVALID_JSON_STRING = 206; |
||
| 224 | const INVALID_OBJECT = 207; |
||
| 225 | const INVALID_METHOD = 208; |
||
| 226 | const INVALID_SCALAR = 209; |
||
| 227 | const INVALID_LESS = 210; |
||
| 228 | const INVALID_LESS_OR_EQUAL = 211; |
||
| 229 | const INVALID_GREATER = 212; |
||
| 230 | const INVALID_GREATER_OR_EQUAL = 213; |
||
| 231 | const INVALID_DATE = 214; |
||
| 232 | const INVALID_CALLABLE = 215; |
||
| 233 | const INVALID_KEY_NOT_EXISTS = 216; |
||
| 234 | const INVALID_SATISFY = 217; |
||
| 235 | const INVALID_IP = 218; |
||
| 236 | const INVALID_BETWEEN = 219; |
||
| 237 | const INVALID_BETWEEN_EXCLUSIVE = 220; |
||
| 238 | const INVALID_CONSTANT = 221; |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Exception to throw when an assertion failed. |
||
| 242 | * |
||
| 243 | * @var string |
||
| 244 | */ |
||
| 245 | protected static $exceptionClass = 'Assert\InvalidArgumentException'; |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Helper method that handles building the assertion failure exceptions. |
||
| 249 | * They are returned from this method so that the stack trace still shows |
||
| 250 | * the assertions method. |
||
| 251 | * |
||
| 252 | * @param mixed $value |
||
| 253 | * @param string $message |
||
| 254 | * @param int $code |
||
| 255 | * @param string|null $propertyPath |
||
| 256 | * @param array $constraints |
||
| 257 | * |
||
| 258 | * @return mixed |
||
|
|
|||
| 259 | */ |
||
| 260 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Assert that two values are equal (using == ). |
||
| 268 | * |
||
| 269 | * @param mixed $value |
||
| 270 | * @param mixed $value2 |
||
| 271 | * @param string|null $message |
||
| 272 | * @param string|null $propertyPath |
||
| 273 | * @return bool |
||
| 274 | * @throws \Assert\AssertionFailedException |
||
| 275 | */ |
||
| 276 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Assert that two values are the same (using ===). |
||
| 293 | * |
||
| 294 | * @param mixed $value |
||
| 295 | * @param mixed $value2 |
||
| 296 | * @param string|null $message |
||
| 297 | * @param string|null $propertyPath |
||
| 298 | * @return bool |
||
| 299 | * @throws \Assert\AssertionFailedException |
||
| 300 | */ |
||
| 301 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Assert that two values are not equal (using == ). |
||
| 318 | * |
||
| 319 | * @param mixed $value1 |
||
| 320 | * @param mixed $value2 |
||
| 321 | * @param string|null $message |
||
| 322 | * @param string|null $propertyPath |
||
| 323 | * @return bool |
||
| 324 | * @throws \Assert\AssertionFailedException |
||
| 325 | */ |
||
| 326 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Assert that two values are not the same (using === ). |
||
| 342 | * |
||
| 343 | * @param mixed $value1 |
||
| 344 | * @param mixed $value2 |
||
| 345 | * @param string|null $message |
||
| 346 | * @param string|null $propertyPath |
||
| 347 | * @return bool |
||
| 348 | * @throws \Assert\AssertionFailedException |
||
| 349 | */ |
||
| 350 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Assert that value is not in array of choices. |
||
| 366 | * |
||
| 367 | * @param mixed $value |
||
| 368 | * @param array $choices |
||
| 369 | * @param string|null $message |
||
| 370 | * @param string|null $propertyPath |
||
| 371 | * @return bool |
||
| 372 | * @throws \Assert\AssertionFailedException |
||
| 373 | */ |
||
| 374 | public static function notInArray($value, array $choices, $message = null, $propertyPath = null) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Assert that value is a php integer. |
||
| 390 | * |
||
| 391 | * @param mixed $value |
||
| 392 | * @param string|null $message |
||
| 393 | * @param string|null $propertyPath |
||
| 394 | * @return bool |
||
| 395 | * @throws \Assert\AssertionFailedException |
||
| 396 | */ |
||
| 397 | public static function integer($value, $message = null, $propertyPath = null) |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Assert that value is a php float. |
||
| 413 | * |
||
| 414 | * @param mixed $value |
||
| 415 | * @param string|null $message |
||
| 416 | * @param string|null $propertyPath |
||
| 417 | * @return bool |
||
| 418 | * @throws \Assert\AssertionFailedException |
||
| 419 | */ |
||
| 420 | public static function float($value, $message = null, $propertyPath = null) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Validates if an integer or integerish is a digit. |
||
| 436 | * |
||
| 437 | * @param mixed $value |
||
| 438 | * @param string|null $message |
||
| 439 | * @param string|null $propertyPath |
||
| 440 | * @return bool |
||
| 441 | * @throws \Assert\AssertionFailedException |
||
| 442 | */ |
||
| 443 | public static function digit($value, $message = null, $propertyPath = null) |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Assert that value is a php integer'ish. |
||
| 459 | * |
||
| 460 | * @param mixed $value |
||
| 461 | * @param string|null $message |
||
| 462 | * @param string|null $propertyPath |
||
| 463 | * @return bool |
||
| 464 | * @throws \Assert\AssertionFailedException |
||
| 465 | */ |
||
| 466 | public static function integerish($value, $message = null, $propertyPath = null) |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Assert that value is php boolean |
||
| 482 | * |
||
| 483 | * @param mixed $value |
||
| 484 | * @param string|null $message |
||
| 485 | * @param string|null $propertyPath |
||
| 486 | * @return bool |
||
| 487 | * @throws \Assert\AssertionFailedException |
||
| 488 | */ |
||
| 489 | public static function boolean($value, $message = null, $propertyPath = null) |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Assert that value is a PHP scalar |
||
| 505 | * |
||
| 506 | * @param mixed $value |
||
| 507 | * @param string|null $message |
||
| 508 | * @param string|null $propertyPath |
||
| 509 | * @return bool |
||
| 510 | * @throws \Assert\AssertionFailedException |
||
| 511 | */ |
||
| 512 | public static function scalar($value, $message = null, $propertyPath = null) |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Assert that value is not empty |
||
| 528 | * |
||
| 529 | * @param mixed $value |
||
| 530 | * @param string|null $message |
||
| 531 | * @param string|null $propertyPath |
||
| 532 | * @return bool |
||
| 533 | * @throws \Assert\AssertionFailedException |
||
| 534 | */ |
||
| 535 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Assert that value is empty |
||
| 551 | * |
||
| 552 | * @param mixed $value |
||
| 553 | * @param string|null $message |
||
| 554 | * @param string|null $propertyPath |
||
| 555 | * @return bool |
||
| 556 | * @throws \Assert\AssertionFailedException |
||
| 557 | */ |
||
| 558 | public static function noContent($value, $message = null, $propertyPath = null) |
||
| 571 | |||
| 572 | /** |
||
| 573 | * Assert that value is null |
||
| 574 | * |
||
| 575 | * @param mixed $value |
||
| 576 | * @param string|null $message |
||
| 577 | * @param string|null $propertyPath |
||
| 578 | * @return bool |
||
| 579 | * @throws \Assert\AssertionFailedException |
||
| 580 | */ |
||
| 581 | public static function null($value, $message = null, $propertyPath = null) |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Assert that value is not null |
||
| 597 | * |
||
| 598 | * @param mixed $value |
||
| 599 | * @param string|null $message |
||
| 600 | * @param string|null $propertyPath |
||
| 601 | * @return bool |
||
| 602 | * @throws \Assert\AssertionFailedException |
||
| 603 | */ |
||
| 604 | public static function notNull($value, $message = null, $propertyPath = null) |
||
| 617 | |||
| 618 | /** |
||
| 619 | * Assert that value is a string |
||
| 620 | * |
||
| 621 | * @param mixed $value |
||
| 622 | * @param string|null $message |
||
| 623 | * @param string|null $propertyPath |
||
| 624 | * @return bool |
||
| 625 | * @throws \Assert\AssertionFailedException |
||
| 626 | */ |
||
| 627 | public static function string($value, $message = null, $propertyPath = null) |
||
| 641 | |||
| 642 | /** |
||
| 643 | * Assert that value matches a regex |
||
| 644 | * |
||
| 645 | * @param mixed $value |
||
| 646 | * @param string $pattern |
||
| 647 | * @param string|null $message |
||
| 648 | * @param string|null $propertyPath |
||
| 649 | * @return bool |
||
| 650 | * @throws \Assert\AssertionFailedException |
||
| 651 | */ |
||
| 652 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Assert that string has a given length. |
||
| 670 | * |
||
| 671 | * @param mixed $value |
||
| 672 | * @param int $length |
||
| 673 | * @param string|null $message |
||
| 674 | * @param string|null $propertyPath |
||
| 675 | * @param string $encoding |
||
| 676 | * @return bool |
||
| 677 | * @throws \Assert\AssertionFailedException |
||
| 678 | */ |
||
| 679 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 697 | |||
| 698 | /** |
||
| 699 | * Assert that a string is at least $minLength chars long. |
||
| 700 | * |
||
| 701 | * @param mixed $value |
||
| 702 | * @param int $minLength |
||
| 703 | * @param string|null $message |
||
| 704 | * @param string|null $propertyPath |
||
| 705 | * @param string $encoding |
||
| 706 | * @return bool |
||
| 707 | * @throws \Assert\AssertionFailedException |
||
| 708 | */ |
||
| 709 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 727 | |||
| 728 | /** |
||
| 729 | * Assert that string value is not longer than $maxLength chars. |
||
| 730 | * |
||
| 731 | * @param mixed $value |
||
| 732 | * @param integer $maxLength |
||
| 733 | * @param string|null $message |
||
| 734 | * @param string|null $propertyPath |
||
| 735 | * @param string $encoding |
||
| 736 | * @return bool |
||
| 737 | * @throws \Assert\AssertionFailedException |
||
| 738 | */ |
||
| 739 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 757 | |||
| 758 | /** |
||
| 759 | * Assert that string length is between min,max lengths. |
||
| 760 | * |
||
| 761 | * @param mixed $value |
||
| 762 | * @param integer $minLength |
||
| 763 | * @param integer $maxLength |
||
| 764 | * @param string|null $message |
||
| 765 | * @param string|null $propertyPath |
||
| 766 | * @param string $encoding |
||
| 767 | * @return bool |
||
| 768 | * @throws \Assert\AssertionFailedException |
||
| 769 | */ |
||
| 770 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 800 | |||
| 801 | /** |
||
| 802 | * Assert that string starts with a sequence of chars. |
||
| 803 | * |
||
| 804 | * @param mixed $string |
||
| 805 | * @param string $needle |
||
| 806 | * @param string|null $message |
||
| 807 | * @param string|null $propertyPath |
||
| 808 | * @param string $encoding |
||
| 809 | * @return bool |
||
| 810 | * @throws \Assert\AssertionFailedException |
||
| 811 | */ |
||
| 812 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Assert that string ends with a sequence of chars. |
||
| 832 | * |
||
| 833 | * @param mixed $string |
||
| 834 | * @param string $needle |
||
| 835 | * @param string|null $message |
||
| 836 | * @param string|null $propertyPath |
||
| 837 | * @param string $encoding |
||
| 838 | * @return bool |
||
| 839 | * @throws \Assert\AssertionFailedException |
||
| 840 | */ |
||
| 841 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 860 | |||
| 861 | /** |
||
| 862 | * Assert that string contains a sequence of chars. |
||
| 863 | * |
||
| 864 | * @param mixed $string |
||
| 865 | * @param string $needle |
||
| 866 | * @param string|null $message |
||
| 867 | * @param string|null $propertyPath |
||
| 868 | * @param string $encoding |
||
| 869 | * @return bool |
||
| 870 | * @throws \Assert\AssertionFailedException |
||
| 871 | */ |
||
| 872 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Assert that value is in array of choices. |
||
| 892 | * |
||
| 893 | * @param mixed $value |
||
| 894 | * @param array $choices |
||
| 895 | * @param string|null $message |
||
| 896 | * @param string|null $propertyPath |
||
| 897 | * @return bool |
||
| 898 | * @throws \Assert\AssertionFailedException |
||
| 899 | */ |
||
| 900 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
| 914 | |||
| 915 | /** |
||
| 916 | * Alias of {@see choice()} |
||
| 917 | * |
||
| 918 | * @param mixed $value |
||
| 919 | * @param array $choices |
||
| 920 | * @param string|null $message |
||
| 921 | * @param string|null $propertyPath |
||
| 922 | * @return bool |
||
| 923 | */ |
||
| 924 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
| 928 | |||
| 929 | /** |
||
| 930 | * Assert that value is numeric. |
||
| 931 | * |
||
| 932 | * @param mixed $value |
||
| 933 | * @param string|null $message |
||
| 934 | * @param string|null $propertyPath |
||
| 935 | * @return bool |
||
| 936 | * @throws \Assert\AssertionFailedException |
||
| 937 | */ |
||
| 938 | public static function numeric($value, $message = null, $propertyPath = null) |
||
| 951 | |||
| 952 | /** |
||
| 953 | * Assert that value is an array. |
||
| 954 | * |
||
| 955 | * @param mixed $value |
||
| 956 | * @param string|null $message |
||
| 957 | * @param string|null $propertyPath |
||
| 958 | * @return bool |
||
| 959 | * @throws \Assert\AssertionFailedException |
||
| 960 | */ |
||
| 961 | public static function isArray($value, $message = null, $propertyPath = null) |
||
| 974 | |||
| 975 | /** |
||
| 976 | * Assert that value is an array or a traversable object. |
||
| 977 | * |
||
| 978 | * @param mixed $value |
||
| 979 | * @param string|null $message |
||
| 980 | * @param string|null $propertyPath |
||
| 981 | * @return bool |
||
| 982 | * @throws \Assert\AssertionFailedException |
||
| 983 | */ |
||
| 984 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
| 997 | |||
| 998 | /** |
||
| 999 | * Assert that value is an array or an array-accessible object. |
||
| 1000 | * |
||
| 1001 | * @param mixed $value |
||
| 1002 | * @param string|null $message |
||
| 1003 | * @param string|null $propertyPath |
||
| 1004 | * @return bool |
||
| 1005 | * @throws \Assert\AssertionFailedException |
||
| 1006 | */ |
||
| 1007 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
| 1020 | |||
| 1021 | /** |
||
| 1022 | * Assert that key exists in an array |
||
| 1023 | * |
||
| 1024 | * @param mixed $value |
||
| 1025 | * @param string|integer $key |
||
| 1026 | * @param string|null $message |
||
| 1027 | * @param string|null $propertyPath |
||
| 1028 | * @return bool |
||
| 1029 | * @throws \Assert\AssertionFailedException |
||
| 1030 | */ |
||
| 1031 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
| 1046 | |||
| 1047 | /** |
||
| 1048 | * Assert that key does not exist in an array |
||
| 1049 | * |
||
| 1050 | * @param mixed $value |
||
| 1051 | * @param string|integer $key |
||
| 1052 | * @param string|null $message |
||
| 1053 | * @param string|null $propertyPath |
||
| 1054 | * @return bool |
||
| 1055 | * @throws \Assert\AssertionFailedException |
||
| 1056 | */ |
||
| 1057 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null) |
||
| 1072 | |||
| 1073 | /** |
||
| 1074 | * Assert that key exists in an array/array-accessible object using isset() |
||
| 1075 | * |
||
| 1076 | * @param mixed $value |
||
| 1077 | * @param string|integer $key |
||
| 1078 | * @param string|null $message |
||
| 1079 | * @param string|null $propertyPath |
||
| 1080 | * @return bool |
||
| 1081 | * @throws \Assert\AssertionFailedException |
||
| 1082 | */ |
||
| 1083 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
| 1098 | |||
| 1099 | /** |
||
| 1100 | * Assert that key exists in an array/array-accessible object and its value is not empty. |
||
| 1101 | * |
||
| 1102 | * @param mixed $value |
||
| 1103 | * @param string|integer $key |
||
| 1104 | * @param string|null $message |
||
| 1105 | * @param string|null $propertyPath |
||
| 1106 | * @return bool |
||
| 1107 | * @throws \Assert\AssertionFailedException |
||
| 1108 | */ |
||
| 1109 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
| 1116 | |||
| 1117 | /** |
||
| 1118 | * Assert that value is not blank |
||
| 1119 | * |
||
| 1120 | * @param mixed $value |
||
| 1121 | * @param string|null $message |
||
| 1122 | * @param string|null $propertyPath |
||
| 1123 | * @return bool |
||
| 1124 | * @throws \Assert\AssertionFailedException |
||
| 1125 | */ |
||
| 1126 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Assert that value is instance of given class-name. |
||
| 1142 | * |
||
| 1143 | * @param mixed $value |
||
| 1144 | * @param string $className |
||
| 1145 | * @param string|null $message |
||
| 1146 | * @param string|null $propertyPath |
||
| 1147 | * @return bool |
||
| 1148 | * @throws \Assert\AssertionFailedException |
||
| 1149 | */ |
||
| 1150 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
| 1164 | |||
| 1165 | /** |
||
| 1166 | * Assert that value is not instance of given class-name. |
||
| 1167 | * |
||
| 1168 | * @param mixed $value |
||
| 1169 | * @param string $className |
||
| 1170 | * @param string|null $message |
||
| 1171 | * @param string|null $propertyPath |
||
| 1172 | * @return bool |
||
| 1173 | * @throws \Assert\AssertionFailedException |
||
| 1174 | */ |
||
| 1175 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
| 1189 | |||
| 1190 | /** |
||
| 1191 | * Assert that value is subclass of given class-name. |
||
| 1192 | * |
||
| 1193 | * @param mixed $value |
||
| 1194 | * @param string $className |
||
| 1195 | * @param string|null $message |
||
| 1196 | * @param string|null $propertyPath |
||
| 1197 | * @return bool |
||
| 1198 | * @throws \Assert\AssertionFailedException |
||
| 1199 | */ |
||
| 1200 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Assert that value is in range of numbers. |
||
| 1217 | * |
||
| 1218 | * @param mixed $value |
||
| 1219 | * @param integer $minValue |
||
| 1220 | * @param integer $maxValue |
||
| 1221 | * @param string|null $message |
||
| 1222 | * @param string|null $propertyPath |
||
| 1223 | * @return bool |
||
| 1224 | * @throws \Assert\AssertionFailedException |
||
| 1225 | */ |
||
| 1226 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
| 1243 | |||
| 1244 | /** |
||
| 1245 | * Assert that a value is at least as big as a given limit |
||
| 1246 | * |
||
| 1247 | * @param mixed $value |
||
| 1248 | * @param mixed $minValue |
||
| 1249 | * @param string|null $message |
||
| 1250 | * @param string|null $propertyPath |
||
| 1251 | * @return bool |
||
| 1252 | * @throws \Assert\AssertionFailedException |
||
| 1253 | */ |
||
| 1254 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * Assert that a number is smaller as a given limit |
||
| 1273 | * |
||
| 1274 | * @param mixed $value |
||
| 1275 | * @param mixed $maxValue |
||
| 1276 | * @param string|null $message |
||
| 1277 | * @param string|null $propertyPath |
||
| 1278 | * @return bool |
||
| 1279 | * @throws \Assert\AssertionFailedException |
||
| 1280 | */ |
||
| 1281 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
| 1297 | |||
| 1298 | /** |
||
| 1299 | * Assert that a file exists |
||
| 1300 | * |
||
| 1301 | * @param string $value |
||
| 1302 | * @param string|null $message |
||
| 1303 | * @param string|null $propertyPath |
||
| 1304 | * @return bool |
||
| 1305 | * @throws \Assert\AssertionFailedException |
||
| 1306 | */ |
||
| 1307 | public static function file($value, $message = null, $propertyPath = null) |
||
| 1323 | |||
| 1324 | /** |
||
| 1325 | * Assert that a directory exists |
||
| 1326 | * |
||
| 1327 | * @param string $value |
||
| 1328 | * @param string|null $message |
||
| 1329 | * @param string|null $propertyPath |
||
| 1330 | * @return bool |
||
| 1331 | * @throws \Assert\AssertionFailedException |
||
| 1332 | */ |
||
| 1333 | public static function directory($value, $message = null, $propertyPath = null) |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Assert that the value is something readable |
||
| 1351 | * |
||
| 1352 | * @param string $value |
||
| 1353 | * @param string|null $message |
||
| 1354 | * @param string|null $propertyPath |
||
| 1355 | * @return bool |
||
| 1356 | * @throws \Assert\AssertionFailedException |
||
| 1357 | */ |
||
| 1358 | public static function readable($value, $message = null, $propertyPath = null) |
||
| 1373 | |||
| 1374 | /** |
||
| 1375 | * Assert that the value is something writeable |
||
| 1376 | * |
||
| 1377 | * @param string $value |
||
| 1378 | * @param string|null $message |
||
| 1379 | * @param string|null $propertyPath |
||
| 1380 | * @return bool |
||
| 1381 | * @throws \Assert\AssertionFailedException |
||
| 1382 | */ |
||
| 1383 | public static function writeable($value, $message = null, $propertyPath = null) |
||
| 1398 | |||
| 1399 | /** |
||
| 1400 | * Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL). |
||
| 1401 | * |
||
| 1402 | * @param mixed $value |
||
| 1403 | * @param string|null $message |
||
| 1404 | * @param string|null $propertyPath |
||
| 1405 | * @return bool |
||
| 1406 | * @throws \Assert\AssertionFailedException |
||
| 1407 | */ |
||
| 1408 | public static function email($value, $message = null, $propertyPath = null) |
||
| 1435 | |||
| 1436 | /** |
||
| 1437 | * Assert that value is an URL. |
||
| 1438 | * |
||
| 1439 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
| 1440 | * |
||
| 1441 | * @param mixed $value |
||
| 1442 | * @param string|null $message |
||
| 1443 | * @param string|null $propertyPath |
||
| 1444 | * @return bool |
||
| 1445 | * @throws \Assert\AssertionFailedException |
||
| 1446 | * |
||
| 1447 | * |
||
| 1448 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
| 1449 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
| 1450 | */ |
||
| 1451 | public static function url($value, $message = null, $propertyPath = null) |
||
| 1486 | |||
| 1487 | /** |
||
| 1488 | * Assert that value is alphanumeric. |
||
| 1489 | * |
||
| 1490 | * @param mixed $value |
||
| 1491 | * @param string|null $message |
||
| 1492 | * @param string|null $propertyPath |
||
| 1493 | * @return bool |
||
| 1494 | * @throws \Assert\AssertionFailedException |
||
| 1495 | */ |
||
| 1496 | public static function alnum($value, $message = null, $propertyPath = null) |
||
| 1511 | |||
| 1512 | /** |
||
| 1513 | * Assert that the value is boolean True. |
||
| 1514 | * |
||
| 1515 | * @param mixed $value |
||
| 1516 | * @param string|null $message |
||
| 1517 | * @param string|null $propertyPath |
||
| 1518 | * @return bool |
||
| 1519 | * @throws \Assert\AssertionFailedException |
||
| 1520 | */ |
||
| 1521 | public static function true($value, $message = null, $propertyPath = null) |
||
| 1534 | |||
| 1535 | /** |
||
| 1536 | * Assert that the value is boolean False. |
||
| 1537 | * |
||
| 1538 | * @param mixed $value |
||
| 1539 | * @param string|null $message |
||
| 1540 | * @param string|null $propertyPath |
||
| 1541 | * @return bool |
||
| 1542 | * @throws \Assert\AssertionFailedException |
||
| 1543 | */ |
||
| 1544 | public static function false($value, $message = null, $propertyPath = null) |
||
| 1557 | |||
| 1558 | /** |
||
| 1559 | * Assert that the class exists. |
||
| 1560 | * |
||
| 1561 | * @param mixed $value |
||
| 1562 | * @param string|null $message |
||
| 1563 | * @param string|null $propertyPath |
||
| 1564 | * @return bool |
||
| 1565 | * @throws \Assert\AssertionFailedException |
||
| 1566 | */ |
||
| 1567 | public static function classExists($value, $message = null, $propertyPath = null) |
||
| 1580 | |||
| 1581 | /** |
||
| 1582 | * Assert that the interface exists. |
||
| 1583 | * |
||
| 1584 | * @param mixed $value |
||
| 1585 | * @param string|null $message |
||
| 1586 | * @param string|null $propertyPath |
||
| 1587 | * @return bool |
||
| 1588 | * @throws \Assert\AssertionFailedException |
||
| 1589 | */ |
||
| 1590 | public static function interfaceExists($value, $message = null, $propertyPath = null) |
||
| 1603 | |||
| 1604 | /** |
||
| 1605 | * Assert that the class implements the interface |
||
| 1606 | * |
||
| 1607 | * @param mixed $class |
||
| 1608 | * @param string $interfaceName |
||
| 1609 | * @param string|null $message |
||
| 1610 | * @param string|null $propertyPath |
||
| 1611 | * @return bool |
||
| 1612 | * @throws \Assert\AssertionFailedException |
||
| 1613 | */ |
||
| 1614 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
| 1629 | |||
| 1630 | /** |
||
| 1631 | * Assert that the given string is a valid json string. |
||
| 1632 | * |
||
| 1633 | * NOTICE: |
||
| 1634 | * Since this does a json_decode to determine its validity |
||
| 1635 | * you probably should consider, when using the variable |
||
| 1636 | * content afterwards, just to decode and check for yourself instead |
||
| 1637 | * of using this assertion. |
||
| 1638 | * |
||
| 1639 | * @param mixed $value |
||
| 1640 | * @param string|null $message |
||
| 1641 | * @param string|null $propertyPath |
||
| 1642 | * @return bool |
||
| 1643 | * @throws \Assert\AssertionFailedException |
||
| 1644 | */ |
||
| 1645 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
| 1658 | |||
| 1659 | /** |
||
| 1660 | * Assert that the given string is a valid UUID |
||
| 1661 | * |
||
| 1662 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
| 1663 | * |
||
| 1664 | * @param string $value |
||
| 1665 | * @param string|null $message |
||
| 1666 | * @param string|null $propertyPath |
||
| 1667 | * @return bool |
||
| 1668 | * @throws \Assert\AssertionFailedException |
||
| 1669 | */ |
||
| 1670 | public static function uuid($value, $message = null, $propertyPath = null) |
||
| 1689 | |||
| 1690 | /** |
||
| 1691 | * Assert that the given string is a valid E164 Phone Number |
||
| 1692 | * |
||
| 1693 | * @link https://en.wikipedia.org/wiki/E.164 |
||
| 1694 | * |
||
| 1695 | * @param string $value |
||
| 1696 | * @param string|null $message |
||
| 1697 | * @param string|null $propertyPath |
||
| 1698 | * @return bool |
||
| 1699 | * @throws \Assert\AssertionFailedException |
||
| 1700 | */ |
||
| 1701 | public static function e164($value, $message = null, $propertyPath = null) |
||
| 1714 | |||
| 1715 | /** |
||
| 1716 | * Assert that the count of countable is equal to count. |
||
| 1717 | * |
||
| 1718 | * @param array|\Countable $countable |
||
| 1719 | * @param int $count |
||
| 1720 | * @param string $message |
||
| 1721 | * @param string $propertyPath |
||
| 1722 | * @return bool |
||
| 1723 | * @throws \Assert\AssertionFailedException |
||
| 1724 | */ |
||
| 1725 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
| 1738 | |||
| 1739 | /** |
||
| 1740 | * static call handler to implement: |
||
| 1741 | * - "null or assertion" delegation |
||
| 1742 | * - "all" delegation |
||
| 1743 | * |
||
| 1744 | * @param string $method |
||
| 1745 | * @param array $args |
||
| 1746 | * |
||
| 1747 | * @return bool|mixed |
||
| 1748 | */ |
||
| 1749 | public static function __callStatic($method, $args) |
||
| 1785 | |||
| 1786 | /** |
||
| 1787 | * Determines if the values array has every choice as key and that this choice has content. |
||
| 1788 | * |
||
| 1789 | * @param array $values |
||
| 1790 | * @param array $choices |
||
| 1791 | * @param null $message |
||
| 1792 | * @param null $propertyPath |
||
| 1793 | * @return bool |
||
| 1794 | */ |
||
| 1795 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
| 1805 | |||
| 1806 | /** |
||
| 1807 | * Determines that the named method is defined in the provided object. |
||
| 1808 | * |
||
| 1809 | * @param string $value |
||
| 1810 | * @param mixed $object |
||
| 1811 | * @param null $message |
||
| 1812 | * @param null $propertyPath |
||
| 1813 | * @return bool |
||
| 1814 | * @throws |
||
| 1815 | */ |
||
| 1816 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
| 1831 | |||
| 1832 | /** |
||
| 1833 | * Determines that the provided value is an object. |
||
| 1834 | * |
||
| 1835 | * @param mixed $value |
||
| 1836 | * @param null $message |
||
| 1837 | * @param null $propertyPath |
||
| 1838 | * @return bool |
||
| 1839 | */ |
||
| 1840 | public static function isObject($value, $message = null, $propertyPath = null) |
||
| 1853 | |||
| 1854 | /** |
||
| 1855 | * Determines if the value is less than given limit. |
||
| 1856 | * |
||
| 1857 | * @param mixed $value |
||
| 1858 | * @param mixed $limit |
||
| 1859 | * @param null $message |
||
| 1860 | * @param null $propertyPath |
||
| 1861 | * @return bool |
||
| 1862 | */ |
||
| 1863 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1877 | |||
| 1878 | /** |
||
| 1879 | * Determines if the value is less or than given limit. |
||
| 1880 | * |
||
| 1881 | * @param mixed $value |
||
| 1882 | * @param mixed $limit |
||
| 1883 | * @param null $message |
||
| 1884 | * @param null $propertyPath |
||
| 1885 | * @return bool |
||
| 1886 | */ |
||
| 1887 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1901 | |||
| 1902 | /** |
||
| 1903 | * Determines if the value is greater than given limit. |
||
| 1904 | * |
||
| 1905 | * @param mixed $value |
||
| 1906 | * @param mixed $limit |
||
| 1907 | * @param null $message |
||
| 1908 | * @param null $propertyPath |
||
| 1909 | * @return bool |
||
| 1910 | */ |
||
| 1911 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1925 | |||
| 1926 | /** |
||
| 1927 | * Determines if the value is greater or equal than given limit. |
||
| 1928 | * |
||
| 1929 | * @param mixed $value |
||
| 1930 | * @param mixed $limit |
||
| 1931 | * @param null $message |
||
| 1932 | * @param null $propertyPath |
||
| 1933 | * @return bool |
||
| 1934 | */ |
||
| 1935 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1949 | |||
| 1950 | /** |
||
| 1951 | * Assert that a value is greater or equal than a lower limit, and less than or equal to an upper limit. |
||
| 1952 | * |
||
| 1953 | * @param mixed $value |
||
| 1954 | * @param mixed $lowerLimit |
||
| 1955 | * @param mixed $upperLimit |
||
| 1956 | * @param string $message |
||
| 1957 | * @param string $propertyPath |
||
| 1958 | * @return bool |
||
| 1959 | */ |
||
| 1960 | public static function between($value, $lowerLimit, $upperLimit, $message = null, $propertyPath = null) |
||
| 1975 | |||
| 1976 | /** |
||
| 1977 | * Assert that a value is greater than a lower limit, and less than an upper limit. |
||
| 1978 | * |
||
| 1979 | * @param mixed $value |
||
| 1980 | * @param mixed $lowerLimit |
||
| 1981 | * @param mixed $upperLimit |
||
| 1982 | * @param string $message |
||
| 1983 | * @param string $propertyPath |
||
| 1984 | * @return bool |
||
| 1985 | */ |
||
| 1986 | public static function betweenExclusive($value, $lowerLimit, $upperLimit, $message = null, $propertyPath = null) |
||
| 2001 | |||
| 2002 | /** |
||
| 2003 | * Assert that date is valid and corresponds to the given format. |
||
| 2004 | * |
||
| 2005 | * @param string $value |
||
| 2006 | * @param string $format supports all of the options date(), except for the following: |
||
| 2007 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
| 2008 | * @param string|null $message |
||
| 2009 | * @param string|null $propertyPath |
||
| 2010 | * @return bool |
||
| 2011 | * |
||
| 2012 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
| 2013 | */ |
||
| 2014 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
| 2033 | |||
| 2034 | /** |
||
| 2035 | * Determines that the provided value is callable. |
||
| 2036 | * |
||
| 2037 | * @param mixed $value |
||
| 2038 | * @param null $message |
||
| 2039 | * @param null $propertyPath |
||
| 2040 | * @return bool |
||
| 2041 | */ |
||
| 2042 | public static function isCallable($value, $message = null, $propertyPath = null) |
||
| 2055 | |||
| 2056 | /** |
||
| 2057 | * Assert that the provided value is valid according to a callback. |
||
| 2058 | * |
||
| 2059 | * If the callback returns `false` the assertion will fail. |
||
| 2060 | * |
||
| 2061 | * @param mixed $value |
||
| 2062 | * @param callable $callback |
||
| 2063 | * @param string|null $message |
||
| 2064 | * @param string|null $propertyPath |
||
| 2065 | * @return bool |
||
| 2066 | */ |
||
| 2067 | public static function satisfy($value, $callback, $message = null, $propertyPath = null) |
||
| 2082 | |||
| 2083 | /** |
||
| 2084 | * Assert that value is an IPv4 or IPv6 address |
||
| 2085 | * (using input_filter/FILTER_VALIDATE_IP). |
||
| 2086 | * |
||
| 2087 | * @param string $value |
||
| 2088 | * @param null|int $flag |
||
| 2089 | * @param string|null $message |
||
| 2090 | * @param string|null $propertyPath |
||
| 2091 | * @return bool |
||
| 2092 | * |
||
| 2093 | * @link http://php.net/manual/filter.filters.flags.php |
||
| 2094 | */ |
||
| 2095 | public static function ip($value, $flag = null, $message = null, $propertyPath = null) |
||
| 2108 | |||
| 2109 | /** |
||
| 2110 | * Assert that value is an IPv4 address |
||
| 2111 | * (using input_filter/FILTER_VALIDATE_IP). |
||
| 2112 | * |
||
| 2113 | * @param string $value |
||
| 2114 | * @param null|int $flag |
||
| 2115 | * @param string|null $message |
||
| 2116 | * @param string|null $propertyPath |
||
| 2117 | * @return bool |
||
| 2118 | * |
||
| 2119 | * @link http://php.net/manual/filter.filters.flags.php |
||
| 2120 | */ |
||
| 2121 | public static function ipv4($value, $flag = null, $message = null, $propertyPath = null) |
||
| 2127 | |||
| 2128 | /** |
||
| 2129 | * Assert that value is an IPv6 address |
||
| 2130 | * (using input_filter/FILTER_VALIDATE_IP). |
||
| 2131 | * |
||
| 2132 | * @param string $value |
||
| 2133 | * @param null|int $flag |
||
| 2134 | * @param string|null $message |
||
| 2135 | * @param string|null $propertyPath |
||
| 2136 | * @return bool |
||
| 2137 | * |
||
| 2138 | * @link http://php.net/manual/filter.filters.flags.php |
||
| 2139 | */ |
||
| 2140 | public static function ipv6($value, $flag = null, $message = null, $propertyPath = null) |
||
| 2146 | |||
| 2147 | /** |
||
| 2148 | * Make a string version of a value. |
||
| 2149 | * |
||
| 2150 | * @param mixed $value |
||
| 2151 | * @return string |
||
| 2152 | */ |
||
| 2153 | protected static function stringify($value) |
||
| 2187 | |||
| 2188 | /** |
||
| 2189 | * Assert that a constant is defined. |
||
| 2190 | * |
||
| 2191 | * @param mixed $constant |
||
| 2192 | * @param string|null $message |
||
| 2193 | * @param string|null $propertyPath |
||
| 2194 | * @return bool |
||
| 2195 | * @throws \Assert\AssertionFailedException |
||
| 2196 | */ |
||
| 2197 | public static function defined($constant, $message = null, $propertyPath = null) |
||
| 2207 | } |
||
| 2208 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.