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