Complex classes like Assertion often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Assertion, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 140 | class Assertion |
||
| 141 | { |
||
| 142 | const INVALID_FLOAT = 9; |
||
| 143 | const INVALID_INTEGER = 10; |
||
| 144 | const INVALID_DIGIT = 11; |
||
| 145 | const INVALID_INTEGERISH = 12; |
||
| 146 | const INVALID_BOOLEAN = 13; |
||
| 147 | const VALUE_EMPTY = 14; |
||
| 148 | const VALUE_NULL = 15; |
||
| 149 | const INVALID_STRING = 16; |
||
| 150 | const INVALID_REGEX = 17; |
||
| 151 | const INVALID_MIN_LENGTH = 18; |
||
| 152 | const INVALID_MAX_LENGTH = 19; |
||
| 153 | const INVALID_STRING_START = 20; |
||
| 154 | const INVALID_STRING_CONTAINS = 21; |
||
| 155 | const INVALID_CHOICE = 22; |
||
| 156 | const INVALID_NUMERIC = 23; |
||
| 157 | const INVALID_ARRAY = 24; |
||
| 158 | const INVALID_KEY_EXISTS = 26; |
||
| 159 | const INVALID_NOT_BLANK = 27; |
||
| 160 | const INVALID_INSTANCE_OF = 28; |
||
| 161 | const INVALID_SUBCLASS_OF = 29; |
||
| 162 | const INVALID_RANGE = 30; |
||
| 163 | const INVALID_ALNUM = 31; |
||
| 164 | const INVALID_TRUE = 32; |
||
| 165 | const INVALID_EQ = 33; |
||
| 166 | const INVALID_SAME = 34; |
||
| 167 | const INVALID_MIN = 35; |
||
| 168 | const INVALID_MAX = 36; |
||
| 169 | const INVALID_LENGTH = 37; |
||
| 170 | const INVALID_FALSE = 38; |
||
| 171 | const INVALID_STRING_END = 39; |
||
| 172 | const INVALID_UUID = 40; |
||
| 173 | const INVALID_COUNT = 41; |
||
| 174 | const INVALID_NOT_EQ = 42; |
||
| 175 | const INVALID_NOT_SAME = 43; |
||
| 176 | const INVALID_TRAVERSABLE = 44; |
||
| 177 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
| 178 | const INVALID_KEY_ISSET = 46; |
||
| 179 | const INVALID_DIRECTORY = 101; |
||
| 180 | const INVALID_FILE = 102; |
||
| 181 | const INVALID_READABLE = 103; |
||
| 182 | const INVALID_WRITEABLE = 104; |
||
| 183 | const INVALID_CLASS = 105; |
||
| 184 | const INVALID_EMAIL = 201; |
||
| 185 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
| 186 | const INVALID_URL = 203; |
||
| 187 | const INVALID_NOT_INSTANCE_OF = 204; |
||
| 188 | const VALUE_NOT_EMPTY = 205; |
||
| 189 | const INVALID_JSON_STRING = 206; |
||
| 190 | const INVALID_OBJECT = 207; |
||
| 191 | const INVALID_METHOD = 208; |
||
| 192 | const INVALID_SCALAR = 209; |
||
| 193 | const INVALID_LESS = 210; |
||
| 194 | const INVALID_LESS_OR_EQUAL = 211; |
||
| 195 | const INVALID_GREATER = 212; |
||
| 196 | const INVALID_GREATER_OR_EQUAL = 212; |
||
| 197 | const INVALID_DATE = 213; |
||
| 198 | const INVALID_KEY_NOT_EXISTS = 214; |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Exception to throw when an assertion failed. |
||
| 202 | * |
||
| 203 | * @var string |
||
| 204 | */ |
||
| 205 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Helper method that handles building the assertion failure exceptions. |
||
| 209 | * They are returned from this method so that the stack trace still shows |
||
| 210 | * the assertions method. |
||
| 211 | */ |
||
| 212 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Assert that two values are equal (using == ). |
||
| 220 | * |
||
| 221 | * @param mixed $value |
||
| 222 | * @param mixed $value2 |
||
| 223 | * @param string|null $message |
||
| 224 | * @param string|null $propertyPath |
||
| 225 | * @return void |
||
| 226 | * @throws \Assert\AssertionFailedException |
||
| 227 | */ |
||
| 228 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Assert that two values are the same (using ===). |
||
| 243 | * |
||
| 244 | * @param mixed $value |
||
| 245 | * @param mixed $value2 |
||
| 246 | * @param string|null $message |
||
| 247 | * @param string|null $propertyPath |
||
| 248 | * @return void |
||
| 249 | * @throws \Assert\AssertionFailedException |
||
| 250 | */ |
||
| 251 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Assert that two values are not equal (using == ). |
||
| 266 | * |
||
| 267 | * @param mixed $value1 |
||
| 268 | * @param mixed $value2 |
||
| 269 | * @param string|null $message |
||
| 270 | * @param string|null $propertyPath |
||
| 271 | * @return void |
||
| 272 | * @throws \Assert\AssertionFailedException |
||
| 273 | */ |
||
| 274 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Assert that two values are not the same (using === ). |
||
| 288 | * |
||
| 289 | * @param mixed $value1 |
||
| 290 | * @param mixed $value2 |
||
| 291 | * @param string|null $message |
||
| 292 | * @param string|null $propertyPath |
||
| 293 | * @return void |
||
| 294 | * @throws \Assert\AssertionFailedException |
||
| 295 | */ |
||
| 296 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Assert that value is a php integer. |
||
| 310 | * |
||
| 311 | * @param mixed $value |
||
| 312 | * @param string|null $message |
||
| 313 | * @param string|null $propertyPath |
||
| 314 | * @return void |
||
| 315 | * @throws \Assert\AssertionFailedException |
||
| 316 | */ |
||
| 317 | public static function integer($value, $message = null, $propertyPath = null) |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Assert that value is a php float. |
||
| 331 | * |
||
| 332 | * @param mixed $value |
||
| 333 | * @param string|null $message |
||
| 334 | * @param string|null $propertyPath |
||
| 335 | * @return void |
||
| 336 | * @throws \Assert\AssertionFailedException |
||
| 337 | */ |
||
| 338 | public static function float($value, $message = null, $propertyPath = null) |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Validates if an integer or integerish is a digit. |
||
| 352 | * |
||
| 353 | * @param mixed $value |
||
| 354 | * @param string|null $message |
||
| 355 | * @param string|null $propertyPath |
||
| 356 | * @return void |
||
| 357 | * @throws \Assert\AssertionFailedException |
||
| 358 | */ |
||
| 359 | public static function digit($value, $message = null, $propertyPath = null) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Assert that value is a php integer'ish. |
||
| 373 | * @param mixed $value |
||
| 374 | * @param string|null $message |
||
| 375 | * @param string|null $propertyPath |
||
| 376 | * @return void |
||
| 377 | * @throws \Assert\AssertionFailedException |
||
| 378 | */ |
||
| 379 | public static function integerish($value, $message = null, $propertyPath = null) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Assert that value is php boolean |
||
| 393 | * |
||
| 394 | * @param mixed $value |
||
| 395 | * @param string|null $message |
||
| 396 | * @param string|null $propertyPath |
||
| 397 | * @return void |
||
| 398 | * @throws \Assert\AssertionFailedException |
||
| 399 | */ |
||
| 400 | public static function boolean($value, $message = null, $propertyPath = null) |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Assert that value is a PHP scalar |
||
| 414 | * |
||
| 415 | * @param mixed $value |
||
| 416 | * @param string|null $message |
||
| 417 | * @param string|null $propertyPath |
||
| 418 | * @return void |
||
| 419 | * @throws \Assert\AssertionFailedException |
||
| 420 | */ |
||
| 421 | public static function scalar($value, $message = null, $propertyPath = null) |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Assert that value is not empty |
||
| 435 | * |
||
| 436 | * @param mixed $value |
||
| 437 | * @param string|null $message |
||
| 438 | * @param string|null $propertyPath |
||
| 439 | * @return void |
||
| 440 | * @throws \Assert\AssertionFailedException |
||
| 441 | */ |
||
| 442 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Assert that value is empty |
||
| 456 | * |
||
| 457 | * @param mixed $value |
||
| 458 | * @param string|null $message |
||
| 459 | * @param string|null $propertyPath |
||
| 460 | * @return void |
||
| 461 | * @throws \Assert\AssertionFailedException |
||
| 462 | */ |
||
| 463 | public static function noContent($value, $message = null, $propertyPath = null) |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Assert that value is not null |
||
| 477 | * |
||
| 478 | * @param mixed $value |
||
| 479 | * @param string|null $message |
||
| 480 | * @param string|null $propertyPath |
||
| 481 | * @return void |
||
| 482 | * @throws \Assert\AssertionFailedException |
||
| 483 | */ |
||
| 484 | public static function notNull($value, $message = null, $propertyPath = null) |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Assert that value is a string |
||
| 498 | * |
||
| 499 | * @param mixed $value |
||
| 500 | * @param string|null $message |
||
| 501 | * @param string|null $propertyPath |
||
| 502 | * @return void |
||
| 503 | * @throws \Assert\AssertionFailedException |
||
| 504 | */ |
||
| 505 | public static function string($value, $message = null, $propertyPath = null) |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Assert that value matches a regex |
||
| 520 | * |
||
| 521 | * @param mixed $value |
||
| 522 | * @param string $pattern |
||
| 523 | * @param string|null $message |
||
| 524 | * @param string|null $propertyPath |
||
| 525 | * @return void |
||
| 526 | * @throws \Assert\AssertionFailedException |
||
| 527 | */ |
||
| 528 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Assert that string has a given length. |
||
| 544 | * |
||
| 545 | * @param mixed $value |
||
| 546 | * @param int $length |
||
| 547 | * @param string|null $message |
||
| 548 | * @param string|null $propertyPath |
||
| 549 | * @param string $encoding |
||
| 550 | * @return void |
||
| 551 | * @throws \Assert\AssertionFailedException |
||
| 552 | */ |
||
| 553 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 569 | |||
| 570 | /** |
||
| 571 | * Assert that a string is at least $minLength chars long. |
||
| 572 | * |
||
| 573 | * @param mixed $value |
||
| 574 | * @param int $minLength |
||
| 575 | * @param string|null $message |
||
| 576 | * @param string|null $propertyPath |
||
| 577 | * @param string $encoding |
||
| 578 | * @return void |
||
| 579 | * @throws \Assert\AssertionFailedException |
||
| 580 | */ |
||
| 581 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Assert that string value is not longer than $maxLength chars. |
||
| 600 | * |
||
| 601 | * @param mixed $value |
||
| 602 | * @param integer $maxLength |
||
| 603 | * @param string|null $message |
||
| 604 | * @param string|null $propertyPath |
||
| 605 | * @param string $encoding |
||
| 606 | * @return void |
||
| 607 | * @throws \Assert\AssertionFailedException |
||
| 608 | */ |
||
| 609 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 625 | |||
| 626 | /** |
||
| 627 | * Assert that string length is between min,max lengths. |
||
| 628 | * |
||
| 629 | * @param mixed $value |
||
| 630 | * @param integer $minLength |
||
| 631 | * @param integer $maxLength |
||
| 632 | * @param string|null $message |
||
| 633 | * @param string|null $propertyPath |
||
| 634 | * @param string $encoding |
||
| 635 | * @return void |
||
| 636 | * @throws \Assert\AssertionFailedException |
||
| 637 | */ |
||
| 638 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 666 | |||
| 667 | /** |
||
| 668 | * Assert that string starts with a sequence of chars. |
||
| 669 | * |
||
| 670 | * @param mixed $string |
||
| 671 | * @param string $needle |
||
| 672 | * @param string|null $message |
||
| 673 | * @param string|null $propertyPath |
||
| 674 | * @param string $encoding |
||
| 675 | * @return void |
||
| 676 | * @throws \Assert\AssertionFailedException |
||
| 677 | */ |
||
| 678 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Assert that string ends with a sequence of chars. |
||
| 696 | * |
||
| 697 | * @param mixed $string |
||
| 698 | * @param string $needle |
||
| 699 | * @param string|null $message |
||
| 700 | * @param string|null $propertyPath |
||
| 701 | * @param string $encoding |
||
| 702 | * @return void |
||
| 703 | * @throws \Assert\AssertionFailedException |
||
| 704 | */ |
||
| 705 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 722 | |||
| 723 | /** |
||
| 724 | * Assert that string contains a sequence of chars. |
||
| 725 | * |
||
| 726 | * @param mixed $string |
||
| 727 | * @param string $needle |
||
| 728 | * @param string|null $message |
||
| 729 | * @param string|null $propertyPath |
||
| 730 | * @param string $encoding |
||
| 731 | * @return void |
||
| 732 | * @throws \Assert\AssertionFailedException |
||
| 733 | */ |
||
| 734 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 749 | |||
| 750 | /** |
||
| 751 | * Assert that value is in array of choices. |
||
| 752 | * |
||
| 753 | * @param mixed $value |
||
| 754 | * @param array $choices |
||
| 755 | * @param string|null $message |
||
| 756 | * @param string|null $propertyPath |
||
| 757 | * @return void |
||
| 758 | * @throws \Assert\AssertionFailedException |
||
| 759 | */ |
||
| 760 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Alias of {@see choice()} |
||
| 775 | * |
||
| 776 | * @throws \Assert\AssertionFailedException |
||
| 777 | */ |
||
| 778 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Assert that value is numeric. |
||
| 785 | * |
||
| 786 | * @param mixed $value |
||
| 787 | * @param string|null $message |
||
| 788 | * @param string|null $propertyPath |
||
| 789 | * @return void |
||
| 790 | * @throws \Assert\AssertionFailedException |
||
| 791 | */ |
||
| 792 | public static function numeric($value, $message = null, $propertyPath = null) |
||
| 803 | |||
| 804 | /** |
||
| 805 | * Assert that value is an array. |
||
| 806 | * |
||
| 807 | * @param mixed $value |
||
| 808 | * @param string|null $message |
||
| 809 | * @param string|null $propertyPath |
||
| 810 | * @return void |
||
| 811 | * @throws \Assert\AssertionFailedException |
||
| 812 | */ |
||
| 813 | public static function isArray($value, $message = null, $propertyPath = null) |
||
| 824 | |||
| 825 | /** |
||
| 826 | * Assert that value is an array or a traversable object. |
||
| 827 | * |
||
| 828 | * @param mixed $value |
||
| 829 | * @param string|null $message |
||
| 830 | * @param string|null $propertyPath |
||
| 831 | * @return void |
||
| 832 | * @throws \Assert\AssertionFailedException |
||
| 833 | */ |
||
| 834 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
| 845 | |||
| 846 | /** |
||
| 847 | * Assert that value is an array or an array-accessible object. |
||
| 848 | * |
||
| 849 | * @param mixed $value |
||
| 850 | * @param string|null $message |
||
| 851 | * @param string|null $propertyPath |
||
| 852 | * @return void |
||
| 853 | * @throws \Assert\AssertionFailedException |
||
| 854 | */ |
||
| 855 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
| 866 | |||
| 867 | /** |
||
| 868 | * Assert that key exists in an array |
||
| 869 | * |
||
| 870 | * @param mixed $value |
||
| 871 | * @param string|integer $key |
||
| 872 | * @param string|null $message |
||
| 873 | * @param string|null $propertyPath |
||
| 874 | * @return void |
||
| 875 | * @throws \Assert\AssertionFailedException |
||
| 876 | */ |
||
| 877 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
| 890 | |||
| 891 | /** |
||
| 892 | * Assert that key does not exist in an array |
||
| 893 | * |
||
| 894 | * @param mixed $value |
||
| 895 | * @param string|integer $key |
||
| 896 | * @param string|null $message |
||
| 897 | * @param string|null $propertyPath |
||
| 898 | * @return void |
||
| 899 | * @throws \Assert\AssertionFailedException |
||
| 900 | */ |
||
| 901 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null) |
||
| 914 | |||
| 915 | /** |
||
| 916 | * Assert that key exists in an array/array-accessible object using isset() |
||
| 917 | * |
||
| 918 | * @param mixed $value |
||
| 919 | * @param string|integer $key |
||
| 920 | * @param string|null $message |
||
| 921 | * @param string|null $propertyPath |
||
| 922 | * @return void |
||
| 923 | * @throws \Assert\AssertionFailedException |
||
| 924 | */ |
||
| 925 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
| 938 | |||
| 939 | /** |
||
| 940 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
| 941 | * |
||
| 942 | * @param mixed $value |
||
| 943 | * @param string|integer $key |
||
| 944 | * @param string|null $message |
||
| 945 | * @param string|null $propertyPath |
||
| 946 | * @return void |
||
| 947 | * @throws \Assert\AssertionFailedException |
||
| 948 | */ |
||
| 949 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
| 954 | |||
| 955 | /** |
||
| 956 | * Assert that value is not blank |
||
| 957 | * |
||
| 958 | * @param mixed $value |
||
| 959 | * @param string|null $message |
||
| 960 | * @param string|null $propertyPath |
||
| 961 | * @return void |
||
| 962 | * @throws \Assert\AssertionFailedException |
||
| 963 | */ |
||
| 964 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
| 975 | |||
| 976 | /** |
||
| 977 | * Assert that value is instance of given class-name. |
||
| 978 | * |
||
| 979 | * @param mixed $value |
||
| 980 | * @param string $className |
||
| 981 | * @param string|null $message |
||
| 982 | * @param string|null $propertyPath |
||
| 983 | * @return void |
||
| 984 | * @throws \Assert\AssertionFailedException |
||
| 985 | */ |
||
| 986 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * Assert that value is not instance of given class-name. |
||
| 1001 | * |
||
| 1002 | * @param mixed $value |
||
| 1003 | * @param string $className |
||
| 1004 | * @param string|null $message |
||
| 1005 | * @param string|null $propertyPath |
||
| 1006 | * @return void |
||
| 1007 | * @throws \Assert\AssertionFailedException |
||
| 1008 | */ |
||
| 1009 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * Assert that value is subclass of given class-name. |
||
| 1024 | * |
||
| 1025 | * @param mixed $value |
||
| 1026 | * @param string $className |
||
| 1027 | * @param string|null $message |
||
| 1028 | * @param string|null $propertyPath |
||
| 1029 | * @return void |
||
| 1030 | * @throws \Assert\AssertionFailedException |
||
| 1031 | */ |
||
| 1032 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Assert that value is in range of numbers. |
||
| 1047 | * |
||
| 1048 | * @param mixed $value |
||
| 1049 | * @param integer $minValue |
||
| 1050 | * @param integer $maxValue |
||
| 1051 | * @param string|null $message |
||
| 1052 | * @param string|null $propertyPath |
||
| 1053 | * @return void |
||
| 1054 | * @throws \Assert\AssertionFailedException |
||
| 1055 | */ |
||
| 1056 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
| 1071 | |||
| 1072 | /** |
||
| 1073 | * Assert that a value is at least as big as a given limit |
||
| 1074 | * |
||
| 1075 | * @param mixed $value |
||
| 1076 | * @param mixed $minValue |
||
| 1077 | * @param string|null $message |
||
| 1078 | * @param string|null $propertyPath |
||
| 1079 | * @return void |
||
| 1080 | * @throws \Assert\AssertionFailedException |
||
| 1081 | */ |
||
| 1082 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Assert that a number is smaller as a given limit |
||
| 1099 | * |
||
| 1100 | * @param mixed $value |
||
| 1101 | * @param mixed $maxValue |
||
| 1102 | * @param string|null $message |
||
| 1103 | * @param string|null $propertyPath |
||
| 1104 | * @return void |
||
| 1105 | * @throws \Assert\AssertionFailedException |
||
| 1106 | */ |
||
| 1107 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
| 1121 | |||
| 1122 | /** |
||
| 1123 | * Assert that a file exists |
||
| 1124 | * |
||
| 1125 | * @param string $value |
||
| 1126 | * @param string|null $message |
||
| 1127 | * @param string|null $propertyPath |
||
| 1128 | * @return void |
||
| 1129 | * @throws \Assert\AssertionFailedException |
||
| 1130 | */ |
||
| 1131 | public static function file($value, $message = null, $propertyPath = null) |
||
| 1145 | |||
| 1146 | /** |
||
| 1147 | * Assert that a directory exists |
||
| 1148 | * |
||
| 1149 | * @param string $value |
||
| 1150 | * @param string|null $message |
||
| 1151 | * @param string|null $propertyPath |
||
| 1152 | * @return void |
||
| 1153 | * @throws \Assert\AssertionFailedException |
||
| 1154 | */ |
||
| 1155 | public static function directory($value, $message = null, $propertyPath = null) |
||
| 1168 | |||
| 1169 | /** |
||
| 1170 | * Assert that the value is something readable |
||
| 1171 | * |
||
| 1172 | * @param string $value |
||
| 1173 | * @param string|null $message |
||
| 1174 | * @param string|null $propertyPath |
||
| 1175 | * @return void |
||
| 1176 | * @throws \Assert\AssertionFailedException |
||
| 1177 | */ |
||
| 1178 | public static function readable($value, $message = null, $propertyPath = null) |
||
| 1191 | |||
| 1192 | /** |
||
| 1193 | * Assert that the value is something writeable |
||
| 1194 | * |
||
| 1195 | * @param string $value |
||
| 1196 | * @param string|null $message |
||
| 1197 | * @param string|null $propertyPath |
||
| 1198 | * @return void |
||
| 1199 | * @throws \Assert\AssertionFailedException |
||
| 1200 | */ |
||
| 1201 | public static function writeable($value, $message = null, $propertyPath = null) |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Assert that value is an email adress (using |
||
| 1217 | * input_filter/FILTER_VALIDATE_EMAIL). |
||
| 1218 | * |
||
| 1219 | * @param mixed $value |
||
| 1220 | * @param string|null $message |
||
| 1221 | * @param string|null $propertyPath |
||
| 1222 | * @return void |
||
| 1223 | * @throws \Assert\AssertionFailedException |
||
| 1224 | */ |
||
| 1225 | public static function email($value, $message = null, $propertyPath = null) |
||
| 1250 | |||
| 1251 | /** |
||
| 1252 | * Assert that value is an URL. |
||
| 1253 | * |
||
| 1254 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
| 1255 | * |
||
| 1256 | * @param mixed $value |
||
| 1257 | * @param string|null $message |
||
| 1258 | * @param string|null $propertyPath |
||
| 1259 | * @return void |
||
| 1260 | * @throws \Assert\AssertionFailedException |
||
| 1261 | * |
||
| 1262 | * |
||
| 1263 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
| 1264 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
| 1265 | */ |
||
| 1266 | public static function url($value, $message = null, $propertyPath = null) |
||
| 1299 | |||
| 1300 | /** |
||
| 1301 | * Assert that value is alphanumeric. |
||
| 1302 | * |
||
| 1303 | * @param mixed $value |
||
| 1304 | * @param string|null $message |
||
| 1305 | * @param string|null $propertyPath |
||
| 1306 | * @return void |
||
| 1307 | * @throws \Assert\AssertionFailedException |
||
| 1308 | */ |
||
| 1309 | public static function alnum($value, $message = null, $propertyPath = null) |
||
| 1322 | |||
| 1323 | /** |
||
| 1324 | * Assert that the value is boolean True. |
||
| 1325 | * |
||
| 1326 | * @param mixed $value |
||
| 1327 | * @param string|null $message |
||
| 1328 | * @param string|null $propertyPath |
||
| 1329 | * @return void |
||
| 1330 | * @throws \Assert\AssertionFailedException |
||
| 1331 | */ |
||
| 1332 | public static function true($value, $message = null, $propertyPath = null) |
||
| 1343 | |||
| 1344 | /** |
||
| 1345 | * Assert that the value is boolean False. |
||
| 1346 | * |
||
| 1347 | * @param mixed $value |
||
| 1348 | * @param string|null $message |
||
| 1349 | * @param string|null $propertyPath |
||
| 1350 | * @return void |
||
| 1351 | * @throws \Assert\AssertionFailedException |
||
| 1352 | */ |
||
| 1353 | public static function false($value, $message = null, $propertyPath = null) |
||
| 1364 | |||
| 1365 | /** |
||
| 1366 | * Assert that the class exists. |
||
| 1367 | * |
||
| 1368 | * @param mixed $value |
||
| 1369 | * @param string|null $message |
||
| 1370 | * @param string|null $propertyPath |
||
| 1371 | * @return void |
||
| 1372 | * @throws \Assert\AssertionFailedException |
||
| 1373 | */ |
||
| 1374 | public static function classExists($value, $message = null, $propertyPath = null) |
||
| 1385 | |||
| 1386 | /** |
||
| 1387 | * Assert that the class implements the interface |
||
| 1388 | * |
||
| 1389 | * @param mixed $class |
||
| 1390 | * @param string $interfaceName |
||
| 1391 | * @param string|null $message |
||
| 1392 | * @param string|null $propertyPath |
||
| 1393 | * @return void |
||
| 1394 | * @throws \Assert\AssertionFailedException |
||
| 1395 | */ |
||
| 1396 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
| 1409 | |||
| 1410 | /** |
||
| 1411 | * Assert that the given string is a valid json string. |
||
| 1412 | * |
||
| 1413 | * NOTICE: |
||
| 1414 | * Since this does a json_decode to determine its validity |
||
| 1415 | * you probably should consider, when using the variable |
||
| 1416 | * content afterwards, just to decode and check for yourself instead |
||
| 1417 | * of using this assertion. |
||
| 1418 | * |
||
| 1419 | * @param mixed $value |
||
| 1420 | * @param string|null $message |
||
| 1421 | * @param string|null $propertyPath |
||
| 1422 | * @return void |
||
| 1423 | * @throws \Assert\AssertionFailedException |
||
| 1424 | */ |
||
| 1425 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
| 1436 | |||
| 1437 | /** |
||
| 1438 | * Assert that the given string is a valid UUID |
||
| 1439 | * |
||
| 1440 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
| 1441 | * |
||
| 1442 | * @param string $value |
||
| 1443 | * @param string|null $message |
||
| 1444 | * @param string|null $propertyPath |
||
| 1445 | * @return void |
||
| 1446 | * @throws \Assert\AssertionFailedException |
||
| 1447 | */ |
||
| 1448 | public static function uuid($value, $message = null, $propertyPath = null) |
||
| 1465 | |||
| 1466 | /** |
||
| 1467 | * Assert that the count of countable is equal to count. |
||
| 1468 | * |
||
| 1469 | * @param array|\Countable $countable |
||
| 1470 | * @param int $count |
||
| 1471 | * @param string $message |
||
| 1472 | * @param string $propertyPath |
||
| 1473 | * @return void |
||
| 1474 | * @throws \Assert\AssertionFailedException |
||
| 1475 | */ |
||
| 1476 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
| 1487 | |||
| 1488 | /** |
||
| 1489 | * static call handler to implement: |
||
| 1490 | * - "null or assertion" delegation |
||
| 1491 | * - "all" delegation |
||
| 1492 | */ |
||
| 1493 | public static function __callStatic($method, $args) |
||
| 1529 | |||
| 1530 | /** |
||
| 1531 | * Determines if the values array has every choice as key and that this choice has content. |
||
| 1532 | * |
||
| 1533 | * @param array $values |
||
| 1534 | * @param array $choices |
||
| 1535 | * @param null $message |
||
| 1536 | * @param null $propertyPath |
||
| 1537 | */ |
||
| 1538 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
| 1547 | |||
| 1548 | /** |
||
| 1549 | * Determines that the named method is defined in the provided object. |
||
| 1550 | * |
||
| 1551 | * @param string $value |
||
| 1552 | * @param mixed $object |
||
| 1553 | * @param null $message |
||
| 1554 | * @param null $propertyPath |
||
| 1555 | * |
||
| 1556 | * @throws |
||
| 1557 | */ |
||
| 1558 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
| 1571 | |||
| 1572 | /** |
||
| 1573 | * Determines that the provided value is an object. |
||
| 1574 | * |
||
| 1575 | * @param mixed $value |
||
| 1576 | * @param null $message |
||
| 1577 | * @param null $propertyPath |
||
| 1578 | */ |
||
| 1579 | public static function isObject($value, $message = null, $propertyPath = null) |
||
| 1591 | |||
| 1592 | /** |
||
| 1593 | * Determines if the value is less than given limit. |
||
| 1594 | * |
||
| 1595 | * @param mixed $value |
||
| 1596 | * @param mixed $limit |
||
| 1597 | * @param null $message |
||
| 1598 | * @param null $propertyPath |
||
| 1599 | */ |
||
| 1600 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1612 | |||
| 1613 | /** |
||
| 1614 | * Determines if the value is less or than given limit. |
||
| 1615 | * |
||
| 1616 | * @param mixed $value |
||
| 1617 | * @param mixed $limit |
||
| 1618 | * @param null $message |
||
| 1619 | * @param null $propertyPath |
||
| 1620 | */ |
||
| 1621 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1633 | |||
| 1634 | /** |
||
| 1635 | * Determines if the value is greater than given limit. |
||
| 1636 | * |
||
| 1637 | * @param mixed $value |
||
| 1638 | * @param mixed $limit |
||
| 1639 | * @param null $message |
||
| 1640 | * @param null $propertyPath |
||
| 1641 | */ |
||
| 1642 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1654 | |||
| 1655 | /** |
||
| 1656 | * Determines if the value is greater or equal than given limit. |
||
| 1657 | * |
||
| 1658 | * @param mixed $value |
||
| 1659 | * @param mixed $limit |
||
| 1660 | * @param null $message |
||
| 1661 | * @param null $propertyPath |
||
| 1662 | */ |
||
| 1663 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1675 | |||
| 1676 | /** |
||
| 1677 | * Assert that date is valid and corresponds to the given format. |
||
| 1678 | * |
||
| 1679 | * @param string $value |
||
| 1680 | * @param string $format supports all of the options date(), except for the following: |
||
| 1681 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
| 1682 | * @param string|null $message |
||
| 1683 | * @param string|null $propertyPath |
||
| 1684 | * |
||
| 1685 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
| 1686 | */ |
||
| 1687 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
| 1704 | |||
| 1705 | /** |
||
| 1706 | * Make a string version of a value. |
||
| 1707 | * |
||
| 1708 | * @param mixed $value |
||
| 1709 | * @return string |
||
| 1710 | */ |
||
| 1711 | protected static function stringify($value) |
||
| 1745 | } |
||
| 1746 | |||
| 1747 |