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 |
||
| 156 | class Assertion |
||
| 157 | { |
||
| 158 | const INVALID_FLOAT = 9; |
||
| 159 | const INVALID_INTEGER = 10; |
||
| 160 | const INVALID_DIGIT = 11; |
||
| 161 | const INVALID_INTEGERISH = 12; |
||
| 162 | const INVALID_BOOLEAN = 13; |
||
| 163 | const VALUE_EMPTY = 14; |
||
| 164 | const VALUE_NULL = 15; |
||
| 165 | const INVALID_STRING = 16; |
||
| 166 | const INVALID_REGEX = 17; |
||
| 167 | const INVALID_MIN_LENGTH = 18; |
||
| 168 | const INVALID_MAX_LENGTH = 19; |
||
| 169 | const INVALID_STRING_START = 20; |
||
| 170 | const INVALID_STRING_CONTAINS = 21; |
||
| 171 | const INVALID_CHOICE = 22; |
||
| 172 | const INVALID_NUMERIC = 23; |
||
| 173 | const INVALID_ARRAY = 24; |
||
| 174 | const INVALID_KEY_EXISTS = 26; |
||
| 175 | const INVALID_NOT_BLANK = 27; |
||
| 176 | const INVALID_INSTANCE_OF = 28; |
||
| 177 | const INVALID_SUBCLASS_OF = 29; |
||
| 178 | const INVALID_RANGE = 30; |
||
| 179 | const INVALID_ALNUM = 31; |
||
| 180 | const INVALID_TRUE = 32; |
||
| 181 | const INVALID_EQ = 33; |
||
| 182 | const INVALID_SAME = 34; |
||
| 183 | const INVALID_MIN = 35; |
||
| 184 | const INVALID_MAX = 36; |
||
| 185 | const INVALID_LENGTH = 37; |
||
| 186 | const INVALID_FALSE = 38; |
||
| 187 | const INVALID_STRING_END = 39; |
||
| 188 | const INVALID_UUID = 40; |
||
| 189 | const INVALID_COUNT = 41; |
||
| 190 | const INVALID_NOT_EQ = 42; |
||
| 191 | const INVALID_NOT_SAME = 43; |
||
| 192 | const INVALID_TRAVERSABLE = 44; |
||
| 193 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
| 194 | const INVALID_KEY_ISSET = 46; |
||
| 195 | const INVALID_VALUE_IN_ARRAY = 47; |
||
| 196 | const INVALID_E164 = 48; |
||
| 197 | const INVALID_DIRECTORY = 101; |
||
| 198 | const INVALID_FILE = 102; |
||
| 199 | const INVALID_READABLE = 103; |
||
| 200 | const INVALID_WRITEABLE = 104; |
||
| 201 | const INVALID_CLASS = 105; |
||
| 202 | const INVALID_INTERFACE = 106; |
||
| 203 | const INVALID_EMAIL = 201; |
||
| 204 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
| 205 | const INVALID_URL = 203; |
||
| 206 | const INVALID_NOT_INSTANCE_OF = 204; |
||
| 207 | const VALUE_NOT_EMPTY = 205; |
||
| 208 | const INVALID_JSON_STRING = 206; |
||
| 209 | const INVALID_OBJECT = 207; |
||
| 210 | const INVALID_METHOD = 208; |
||
| 211 | const INVALID_SCALAR = 209; |
||
| 212 | const INVALID_LESS = 210; |
||
| 213 | const INVALID_LESS_OR_EQUAL = 211; |
||
| 214 | const INVALID_GREATER = 212; |
||
| 215 | const INVALID_GREATER_OR_EQUAL = 213; |
||
| 216 | const INVALID_DATE = 214; |
||
| 217 | const INVALID_CALLABLE = 215; |
||
| 218 | const INVALID_KEY_NOT_EXISTS = 216; |
||
| 219 | const INVALID_SATISFY = 217; |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Exception to throw when an assertion failed. |
||
| 223 | * |
||
| 224 | * @var string |
||
| 225 | */ |
||
| 226 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Helper method that handles building the assertion failure exceptions. |
||
| 230 | * They are returned from this method so that the stack trace still shows |
||
| 231 | * the assertions method. |
||
| 232 | */ |
||
| 233 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
| 238 | |||
| 239 | /** |
||
| 240 | * Assert that two values are equal (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 eq($value, $value2, $message = null, $propertyPath = null) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Assert that two values are the same (using ===). |
||
| 264 | * |
||
| 265 | * @param mixed $value |
||
| 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 same($value, $value2, $message = null, $propertyPath = null) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Assert that two values are not equal (using == ). |
||
| 287 | * |
||
| 288 | * @param mixed $value1 |
||
| 289 | * @param mixed $value2 |
||
| 290 | * @param string|null $message |
||
| 291 | * @param string|null $propertyPath |
||
| 292 | * @return void |
||
| 293 | * @throws \Assert\AssertionFailedException |
||
| 294 | */ |
||
| 295 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Assert that two values are not the same (using === ). |
||
| 309 | * |
||
| 310 | * @param mixed $value1 |
||
| 311 | * @param mixed $value2 |
||
| 312 | * @param string|null $message |
||
| 313 | * @param string|null $propertyPath |
||
| 314 | * @return void |
||
| 315 | * @throws \Assert\AssertionFailedException |
||
| 316 | */ |
||
| 317 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Assert that value is not in array of choices. |
||
| 331 | * |
||
| 332 | * @param mixed $value |
||
| 333 | * @param array $choices |
||
| 334 | * @param string|null $message |
||
| 335 | * @param string|null $propertyPath |
||
| 336 | * @return void |
||
| 337 | * @throws \Assert\AssertionFailedException |
||
| 338 | */ |
||
| 339 | public static function notInArray($value, array $choices, $message = null, $propertyPath = null) |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Assert that value is a php integer. |
||
| 353 | * |
||
| 354 | * @param mixed $value |
||
| 355 | * @param string|null $message |
||
| 356 | * @param string|null $propertyPath |
||
| 357 | * @return void |
||
| 358 | * @throws \Assert\AssertionFailedException |
||
| 359 | */ |
||
| 360 | public static function integer($value, $message = null, $propertyPath = null) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Assert that value is a php float. |
||
| 374 | * |
||
| 375 | * @param mixed $value |
||
| 376 | * @param string|null $message |
||
| 377 | * @param string|null $propertyPath |
||
| 378 | * @return void |
||
| 379 | * @throws \Assert\AssertionFailedException |
||
| 380 | */ |
||
| 381 | public static function float($value, $message = null, $propertyPath = null) |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Validates if an integer or integerish is a digit. |
||
| 395 | * |
||
| 396 | * @param mixed $value |
||
| 397 | * @param string|null $message |
||
| 398 | * @param string|null $propertyPath |
||
| 399 | * @return void |
||
| 400 | * @throws \Assert\AssertionFailedException |
||
| 401 | */ |
||
| 402 | public static function digit($value, $message = null, $propertyPath = null) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Assert that value is a php integer'ish. |
||
| 416 | * |
||
| 417 | * @param mixed $value |
||
| 418 | * @param string|null $message |
||
| 419 | * @param string|null $propertyPath |
||
| 420 | * @return void |
||
| 421 | * @throws \Assert\AssertionFailedException |
||
| 422 | */ |
||
| 423 | public static function integerish($value, $message = null, $propertyPath = null) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Assert that value is php boolean |
||
| 437 | * |
||
| 438 | * @param mixed $value |
||
| 439 | * @param string|null $message |
||
| 440 | * @param string|null $propertyPath |
||
| 441 | * @return void |
||
| 442 | * @throws \Assert\AssertionFailedException |
||
| 443 | */ |
||
| 444 | public static function boolean($value, $message = null, $propertyPath = null) |
||
| 455 | |||
| 456 | /** |
||
| 457 | * Assert that value is a PHP scalar |
||
| 458 | * |
||
| 459 | * @param mixed $value |
||
| 460 | * @param string|null $message |
||
| 461 | * @param string|null $propertyPath |
||
| 462 | * @return void |
||
| 463 | * @throws \Assert\AssertionFailedException |
||
| 464 | */ |
||
| 465 | public static function scalar($value, $message = null, $propertyPath = null) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Assert that value is not empty |
||
| 479 | * |
||
| 480 | * @param mixed $value |
||
| 481 | * @param string|null $message |
||
| 482 | * @param string|null $propertyPath |
||
| 483 | * @return void |
||
| 484 | * @throws \Assert\AssertionFailedException |
||
| 485 | */ |
||
| 486 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Assert that value is empty |
||
| 500 | * |
||
| 501 | * @param mixed $value |
||
| 502 | * @param string|null $message |
||
| 503 | * @param string|null $propertyPath |
||
| 504 | * @return void |
||
| 505 | * @throws \Assert\AssertionFailedException |
||
| 506 | */ |
||
| 507 | public static function noContent($value, $message = null, $propertyPath = null) |
||
| 518 | |||
| 519 | /** |
||
| 520 | * Assert that value is not null |
||
| 521 | * |
||
| 522 | * @param mixed $value |
||
| 523 | * @param string|null $message |
||
| 524 | * @param string|null $propertyPath |
||
| 525 | * @return void |
||
| 526 | * @throws \Assert\AssertionFailedException |
||
| 527 | */ |
||
| 528 | public static function notNull($value, $message = null, $propertyPath = null) |
||
| 539 | |||
| 540 | /** |
||
| 541 | * Assert that value is a string |
||
| 542 | * |
||
| 543 | * @param mixed $value |
||
| 544 | * @param string|null $message |
||
| 545 | * @param string|null $propertyPath |
||
| 546 | * @return void |
||
| 547 | * @throws \Assert\AssertionFailedException |
||
| 548 | */ |
||
| 549 | public static function string($value, $message = null, $propertyPath = null) |
||
| 561 | |||
| 562 | /** |
||
| 563 | * Assert that value matches a regex |
||
| 564 | * |
||
| 565 | * @param mixed $value |
||
| 566 | * @param string $pattern |
||
| 567 | * @param string|null $message |
||
| 568 | * @param string|null $propertyPath |
||
| 569 | * @return void |
||
| 570 | * @throws \Assert\AssertionFailedException |
||
| 571 | */ |
||
| 572 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
| 585 | |||
| 586 | /** |
||
| 587 | * Assert that string has a given length. |
||
| 588 | * |
||
| 589 | * @param mixed $value |
||
| 590 | * @param int $length |
||
| 591 | * @param string|null $message |
||
| 592 | * @param string|null $propertyPath |
||
| 593 | * @param string $encoding |
||
| 594 | * @return void |
||
| 595 | * @throws \Assert\AssertionFailedException |
||
| 596 | */ |
||
| 597 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 613 | |||
| 614 | /** |
||
| 615 | * Assert that a string is at least $minLength chars long. |
||
| 616 | * |
||
| 617 | * @param mixed $value |
||
| 618 | * @param int $minLength |
||
| 619 | * @param string|null $message |
||
| 620 | * @param string|null $propertyPath |
||
| 621 | * @param string $encoding |
||
| 622 | * @return void |
||
| 623 | * @throws \Assert\AssertionFailedException |
||
| 624 | */ |
||
| 625 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 641 | |||
| 642 | /** |
||
| 643 | * Assert that string value is not longer than $maxLength chars. |
||
| 644 | * |
||
| 645 | * @param mixed $value |
||
| 646 | * @param integer $maxLength |
||
| 647 | * @param string|null $message |
||
| 648 | * @param string|null $propertyPath |
||
| 649 | * @param string $encoding |
||
| 650 | * @return void |
||
| 651 | * @throws \Assert\AssertionFailedException |
||
| 652 | */ |
||
| 653 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 669 | |||
| 670 | /** |
||
| 671 | * Assert that string length is between min,max lengths. |
||
| 672 | * |
||
| 673 | * @param mixed $value |
||
| 674 | * @param integer $minLength |
||
| 675 | * @param integer $maxLength |
||
| 676 | * @param string|null $message |
||
| 677 | * @param string|null $propertyPath |
||
| 678 | * @param string $encoding |
||
| 679 | * @return void |
||
| 680 | * @throws \Assert\AssertionFailedException |
||
| 681 | */ |
||
| 682 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Assert that string starts with a sequence of chars. |
||
| 713 | * |
||
| 714 | * @param mixed $string |
||
| 715 | * @param string $needle |
||
| 716 | * @param string|null $message |
||
| 717 | * @param string|null $propertyPath |
||
| 718 | * @param string $encoding |
||
| 719 | * @return void |
||
| 720 | * @throws \Assert\AssertionFailedException |
||
| 721 | */ |
||
| 722 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 737 | |||
| 738 | /** |
||
| 739 | * Assert that string ends with a sequence of chars. |
||
| 740 | * |
||
| 741 | * @param mixed $string |
||
| 742 | * @param string $needle |
||
| 743 | * @param string|null $message |
||
| 744 | * @param string|null $propertyPath |
||
| 745 | * @param string $encoding |
||
| 746 | * @return void |
||
| 747 | * @throws \Assert\AssertionFailedException |
||
| 748 | */ |
||
| 749 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 766 | |||
| 767 | /** |
||
| 768 | * Assert that string contains a sequence of chars. |
||
| 769 | * |
||
| 770 | * @param mixed $string |
||
| 771 | * @param string $needle |
||
| 772 | * @param string|null $message |
||
| 773 | * @param string|null $propertyPath |
||
| 774 | * @param string $encoding |
||
| 775 | * @return void |
||
| 776 | * @throws \Assert\AssertionFailedException |
||
| 777 | */ |
||
| 778 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 793 | |||
| 794 | /** |
||
| 795 | * Assert that value is in array of choices. |
||
| 796 | * |
||
| 797 | * @param mixed $value |
||
| 798 | * @param array $choices |
||
| 799 | * @param string|null $message |
||
| 800 | * @param string|null $propertyPath |
||
| 801 | * @return void |
||
| 802 | * @throws \Assert\AssertionFailedException |
||
| 803 | */ |
||
| 804 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Alias of {@see choice()} |
||
| 819 | * |
||
| 820 | * @throws \Assert\AssertionFailedException |
||
| 821 | */ |
||
| 822 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
| 826 | |||
| 827 | /** |
||
| 828 | * Assert that value is numeric. |
||
| 829 | * |
||
| 830 | * @param mixed $value |
||
| 831 | * @param string|null $message |
||
| 832 | * @param string|null $propertyPath |
||
| 833 | * @return void |
||
| 834 | * @throws \Assert\AssertionFailedException |
||
| 835 | */ |
||
| 836 | public static function numeric($value, $message = null, $propertyPath = null) |
||
| 847 | |||
| 848 | /** |
||
| 849 | * Assert that value is an array. |
||
| 850 | * |
||
| 851 | * @param mixed $value |
||
| 852 | * @param string|null $message |
||
| 853 | * @param string|null $propertyPath |
||
| 854 | * @return void |
||
| 855 | * @throws \Assert\AssertionFailedException |
||
| 856 | */ |
||
| 857 | public static function isArray($value, $message = null, $propertyPath = null) |
||
| 868 | |||
| 869 | /** |
||
| 870 | * Assert that value is an array or a traversable object. |
||
| 871 | * |
||
| 872 | * @param mixed $value |
||
| 873 | * @param string|null $message |
||
| 874 | * @param string|null $propertyPath |
||
| 875 | * @return void |
||
| 876 | * @throws \Assert\AssertionFailedException |
||
| 877 | */ |
||
| 878 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Assert that value is an array or an array-accessible object. |
||
| 892 | * |
||
| 893 | * @param mixed $value |
||
| 894 | * @param string|null $message |
||
| 895 | * @param string|null $propertyPath |
||
| 896 | * @return void |
||
| 897 | * @throws \Assert\AssertionFailedException |
||
| 898 | */ |
||
| 899 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
| 910 | |||
| 911 | /** |
||
| 912 | * Assert that key exists in an array |
||
| 913 | * |
||
| 914 | * @param mixed $value |
||
| 915 | * @param string|integer $key |
||
| 916 | * @param string|null $message |
||
| 917 | * @param string|null $propertyPath |
||
| 918 | * @return void |
||
| 919 | * @throws \Assert\AssertionFailedException |
||
| 920 | */ |
||
| 921 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Assert that key does not exist in an array |
||
| 937 | * |
||
| 938 | * @param mixed $value |
||
| 939 | * @param string|integer $key |
||
| 940 | * @param string|null $message |
||
| 941 | * @param string|null $propertyPath |
||
| 942 | * @return void |
||
| 943 | * @throws \Assert\AssertionFailedException |
||
| 944 | */ |
||
| 945 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null) |
||
| 958 | |||
| 959 | /** |
||
| 960 | * Assert that key exists in an array/array-accessible object using isset() |
||
| 961 | * |
||
| 962 | * @param mixed $value |
||
| 963 | * @param string|integer $key |
||
| 964 | * @param string|null $message |
||
| 965 | * @param string|null $propertyPath |
||
| 966 | * @return void |
||
| 967 | * @throws \Assert\AssertionFailedException |
||
| 968 | */ |
||
| 969 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
| 982 | |||
| 983 | /** |
||
| 984 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
| 985 | * |
||
| 986 | * @param mixed $value |
||
| 987 | * @param string|integer $key |
||
| 988 | * @param string|null $message |
||
| 989 | * @param string|null $propertyPath |
||
| 990 | * @return void |
||
| 991 | * @throws \Assert\AssertionFailedException |
||
| 992 | */ |
||
| 993 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
| 998 | |||
| 999 | /** |
||
| 1000 | * Assert that value is not blank |
||
| 1001 | * |
||
| 1002 | * @param mixed $value |
||
| 1003 | * @param string|null $message |
||
| 1004 | * @param string|null $propertyPath |
||
| 1005 | * @return void |
||
| 1006 | * @throws \Assert\AssertionFailedException |
||
| 1007 | */ |
||
| 1008 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
| 1019 | |||
| 1020 | /** |
||
| 1021 | * Assert that value is instance of given class-name. |
||
| 1022 | * |
||
| 1023 | * @param mixed $value |
||
| 1024 | * @param string $className |
||
| 1025 | * @param string|null $message |
||
| 1026 | * @param string|null $propertyPath |
||
| 1027 | * @return void |
||
| 1028 | * @throws \Assert\AssertionFailedException |
||
| 1029 | */ |
||
| 1030 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * Assert that value is not instance of given class-name. |
||
| 1045 | * |
||
| 1046 | * @param mixed $value |
||
| 1047 | * @param string $className |
||
| 1048 | * @param string|null $message |
||
| 1049 | * @param string|null $propertyPath |
||
| 1050 | * @return void |
||
| 1051 | * @throws \Assert\AssertionFailedException |
||
| 1052 | */ |
||
| 1053 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
| 1065 | |||
| 1066 | /** |
||
| 1067 | * Assert that value is subclass of given class-name. |
||
| 1068 | * |
||
| 1069 | * @param mixed $value |
||
| 1070 | * @param string $className |
||
| 1071 | * @param string|null $message |
||
| 1072 | * @param string|null $propertyPath |
||
| 1073 | * @return void |
||
| 1074 | * @throws \Assert\AssertionFailedException |
||
| 1075 | */ |
||
| 1076 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
| 1088 | |||
| 1089 | /** |
||
| 1090 | * Assert that value is in range of numbers. |
||
| 1091 | * |
||
| 1092 | * @param mixed $value |
||
| 1093 | * @param integer $minValue |
||
| 1094 | * @param integer $maxValue |
||
| 1095 | * @param string|null $message |
||
| 1096 | * @param string|null $propertyPath |
||
| 1097 | * @return void |
||
| 1098 | * @throws \Assert\AssertionFailedException |
||
| 1099 | */ |
||
| 1100 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
| 1115 | |||
| 1116 | /** |
||
| 1117 | * Assert that a value is at least as big as a given limit |
||
| 1118 | * |
||
| 1119 | * @param mixed $value |
||
| 1120 | * @param mixed $minValue |
||
| 1121 | * @param string|null $message |
||
| 1122 | * @param string|null $propertyPath |
||
| 1123 | * @return void |
||
| 1124 | * @throws \Assert\AssertionFailedException |
||
| 1125 | */ |
||
| 1126 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
| 1140 | |||
| 1141 | /** |
||
| 1142 | * Assert that a number is smaller as a given limit |
||
| 1143 | * |
||
| 1144 | * @param mixed $value |
||
| 1145 | * @param mixed $maxValue |
||
| 1146 | * @param string|null $message |
||
| 1147 | * @param string|null $propertyPath |
||
| 1148 | * @return void |
||
| 1149 | * @throws \Assert\AssertionFailedException |
||
| 1150 | */ |
||
| 1151 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
| 1165 | |||
| 1166 | /** |
||
| 1167 | * Assert that a file exists |
||
| 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 file($value, $message = null, $propertyPath = null) |
||
| 1189 | |||
| 1190 | /** |
||
| 1191 | * Assert that a directory exists |
||
| 1192 | * |
||
| 1193 | * @param string $value |
||
| 1194 | * @param string|null $message |
||
| 1195 | * @param string|null $propertyPath |
||
| 1196 | * @return void |
||
| 1197 | * @throws \Assert\AssertionFailedException |
||
| 1198 | */ |
||
| 1199 | public static function directory($value, $message = null, $propertyPath = null) |
||
| 1212 | |||
| 1213 | /** |
||
| 1214 | * Assert that the value is something readable |
||
| 1215 | * |
||
| 1216 | * @param string $value |
||
| 1217 | * @param string|null $message |
||
| 1218 | * @param string|null $propertyPath |
||
| 1219 | * @return void |
||
| 1220 | * @throws \Assert\AssertionFailedException |
||
| 1221 | */ |
||
| 1222 | public static function readable($value, $message = null, $propertyPath = null) |
||
| 1235 | |||
| 1236 | /** |
||
| 1237 | * Assert that the value is something writeable |
||
| 1238 | * |
||
| 1239 | * @param string $value |
||
| 1240 | * @param string|null $message |
||
| 1241 | * @param string|null $propertyPath |
||
| 1242 | * @return void |
||
| 1243 | * @throws \Assert\AssertionFailedException |
||
| 1244 | */ |
||
| 1245 | public static function writeable($value, $message = null, $propertyPath = null) |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL). |
||
| 1261 | * |
||
| 1262 | * @param mixed $value |
||
| 1263 | * @param string|null $message |
||
| 1264 | * @param string|null $propertyPath |
||
| 1265 | * @return void |
||
| 1266 | * @throws \Assert\AssertionFailedException |
||
| 1267 | */ |
||
| 1268 | public static function email($value, $message = null, $propertyPath = null) |
||
| 1293 | |||
| 1294 | /** |
||
| 1295 | * Assert that value is an URL. |
||
| 1296 | * |
||
| 1297 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
| 1298 | * |
||
| 1299 | * @param mixed $value |
||
| 1300 | * @param string|null $message |
||
| 1301 | * @param string|null $propertyPath |
||
| 1302 | * @return void |
||
| 1303 | * @throws \Assert\AssertionFailedException |
||
| 1304 | * |
||
| 1305 | * |
||
| 1306 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
| 1307 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
| 1308 | */ |
||
| 1309 | public static function url($value, $message = null, $propertyPath = null) |
||
| 1342 | |||
| 1343 | /** |
||
| 1344 | * Assert that value is alphanumeric. |
||
| 1345 | * |
||
| 1346 | * @param mixed $value |
||
| 1347 | * @param string|null $message |
||
| 1348 | * @param string|null $propertyPath |
||
| 1349 | * @return void |
||
| 1350 | * @throws \Assert\AssertionFailedException |
||
| 1351 | */ |
||
| 1352 | public static function alnum($value, $message = null, $propertyPath = null) |
||
| 1365 | |||
| 1366 | /** |
||
| 1367 | * Assert that the value is boolean True. |
||
| 1368 | * |
||
| 1369 | * @param mixed $value |
||
| 1370 | * @param string|null $message |
||
| 1371 | * @param string|null $propertyPath |
||
| 1372 | * @return void |
||
| 1373 | * @throws \Assert\AssertionFailedException |
||
| 1374 | */ |
||
| 1375 | public static function true($value, $message = null, $propertyPath = null) |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * Assert that the value is boolean False. |
||
| 1389 | * |
||
| 1390 | * @param mixed $value |
||
| 1391 | * @param string|null $message |
||
| 1392 | * @param string|null $propertyPath |
||
| 1393 | * @return void |
||
| 1394 | * @throws \Assert\AssertionFailedException |
||
| 1395 | */ |
||
| 1396 | public static function false($value, $message = null, $propertyPath = null) |
||
| 1407 | |||
| 1408 | /** |
||
| 1409 | * Assert that the class exists. |
||
| 1410 | * |
||
| 1411 | * @param mixed $value |
||
| 1412 | * @param string|null $message |
||
| 1413 | * @param string|null $propertyPath |
||
| 1414 | * @return void |
||
| 1415 | * @throws \Assert\AssertionFailedException |
||
| 1416 | */ |
||
| 1417 | public static function classExists($value, $message = null, $propertyPath = null) |
||
| 1428 | |||
| 1429 | /** |
||
| 1430 | * Assert that the interface exists. |
||
| 1431 | * |
||
| 1432 | * @param mixed $value |
||
| 1433 | * @param string|null $message |
||
| 1434 | * @param string|null $propertyPath |
||
| 1435 | * @return void |
||
| 1436 | * @throws \Assert\AssertionFailedException |
||
| 1437 | */ |
||
| 1438 | public static function interfaceExists($value, $message = null, $propertyPath = null) |
||
| 1449 | |||
| 1450 | /** |
||
| 1451 | * Assert that the class implements the interface |
||
| 1452 | * |
||
| 1453 | * @param mixed $class |
||
| 1454 | * @param string $interfaceName |
||
| 1455 | * @param string|null $message |
||
| 1456 | * @param string|null $propertyPath |
||
| 1457 | * @return void |
||
| 1458 | * @throws \Assert\AssertionFailedException |
||
| 1459 | */ |
||
| 1460 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
| 1473 | |||
| 1474 | /** |
||
| 1475 | * Assert that the given string is a valid json string. |
||
| 1476 | * |
||
| 1477 | * NOTICE: |
||
| 1478 | * Since this does a json_decode to determine its validity |
||
| 1479 | * you probably should consider, when using the variable |
||
| 1480 | * content afterwards, just to decode and check for yourself instead |
||
| 1481 | * of using this assertion. |
||
| 1482 | * |
||
| 1483 | * @param mixed $value |
||
| 1484 | * @param string|null $message |
||
| 1485 | * @param string|null $propertyPath |
||
| 1486 | * @return void |
||
| 1487 | * @throws \Assert\AssertionFailedException |
||
| 1488 | */ |
||
| 1489 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
| 1500 | |||
| 1501 | /** |
||
| 1502 | * Assert that the given string is a valid UUID |
||
| 1503 | * |
||
| 1504 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
| 1505 | * |
||
| 1506 | * @param string $value |
||
| 1507 | * @param string|null $message |
||
| 1508 | * @param string|null $propertyPath |
||
| 1509 | * @return void |
||
| 1510 | * @throws \Assert\AssertionFailedException |
||
| 1511 | */ |
||
| 1512 | public static function uuid($value, $message = null, $propertyPath = null) |
||
| 1529 | |||
| 1530 | /** |
||
| 1531 | * Assert that the given string is a valid E164 Phone Number |
||
| 1532 | * |
||
| 1533 | * @link https://en.wikipedia.org/wiki/E.164 |
||
| 1534 | * |
||
| 1535 | * @param string $value |
||
| 1536 | * @param string|null $message |
||
| 1537 | * @param string|null $propertyPath |
||
| 1538 | * @return void |
||
| 1539 | * @throws \Assert\AssertionFailedException |
||
| 1540 | */ |
||
| 1541 | public static function e164($value, $message = null, $propertyPath = null) |
||
| 1552 | |||
| 1553 | /** |
||
| 1554 | * Assert that the count of countable is equal to count. |
||
| 1555 | * |
||
| 1556 | * @param array|\Countable $countable |
||
| 1557 | * @param int $count |
||
| 1558 | * @param string $message |
||
| 1559 | * @param string $propertyPath |
||
| 1560 | * @return void |
||
| 1561 | * @throws \Assert\AssertionFailedException |
||
| 1562 | */ |
||
| 1563 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
| 1574 | |||
| 1575 | /** |
||
| 1576 | * static call handler to implement: |
||
| 1577 | * - "null or assertion" delegation |
||
| 1578 | * - "all" delegation |
||
| 1579 | */ |
||
| 1580 | public static function __callStatic($method, $args) |
||
| 1616 | |||
| 1617 | /** |
||
| 1618 | * Determines if the values array has every choice as key and that this choice has content. |
||
| 1619 | * |
||
| 1620 | * @param array $values |
||
| 1621 | * @param array $choices |
||
| 1622 | * @param null $message |
||
| 1623 | * @param null $propertyPath |
||
| 1624 | */ |
||
| 1625 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
| 1634 | |||
| 1635 | /** |
||
| 1636 | * Determines that the named method is defined in the provided object. |
||
| 1637 | * |
||
| 1638 | * @param string $value |
||
| 1639 | * @param mixed $object |
||
| 1640 | * @param null $message |
||
| 1641 | * @param null $propertyPath |
||
| 1642 | * |
||
| 1643 | * @throws |
||
| 1644 | */ |
||
| 1645 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
| 1658 | |||
| 1659 | /** |
||
| 1660 | * Determines that the provided value is an object. |
||
| 1661 | * |
||
| 1662 | * @param mixed $value |
||
| 1663 | * @param null $message |
||
| 1664 | * @param null $propertyPath |
||
| 1665 | */ |
||
| 1666 | public static function isObject($value, $message = null, $propertyPath = null) |
||
| 1678 | |||
| 1679 | /** |
||
| 1680 | * Determines if the value is less than given limit. |
||
| 1681 | * |
||
| 1682 | * @param mixed $value |
||
| 1683 | * @param mixed $limit |
||
| 1684 | * @param null $message |
||
| 1685 | * @param null $propertyPath |
||
| 1686 | */ |
||
| 1687 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1699 | |||
| 1700 | /** |
||
| 1701 | * Determines if the value is less or than given limit. |
||
| 1702 | * |
||
| 1703 | * @param mixed $value |
||
| 1704 | * @param mixed $limit |
||
| 1705 | * @param null $message |
||
| 1706 | * @param null $propertyPath |
||
| 1707 | */ |
||
| 1708 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1720 | |||
| 1721 | /** |
||
| 1722 | * Determines if the value is greater than given limit. |
||
| 1723 | * |
||
| 1724 | * @param mixed $value |
||
| 1725 | * @param mixed $limit |
||
| 1726 | * @param null $message |
||
| 1727 | * @param null $propertyPath |
||
| 1728 | */ |
||
| 1729 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1741 | |||
| 1742 | /** |
||
| 1743 | * Determines if the value is greater or equal than given limit. |
||
| 1744 | * |
||
| 1745 | * @param mixed $value |
||
| 1746 | * @param mixed $limit |
||
| 1747 | * @param null $message |
||
| 1748 | * @param null $propertyPath |
||
| 1749 | */ |
||
| 1750 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1762 | |||
| 1763 | /** |
||
| 1764 | * Assert that date is valid and corresponds to the given format. |
||
| 1765 | * |
||
| 1766 | * @param string $value |
||
| 1767 | * @param string $format supports all of the options date(), except for the following: |
||
| 1768 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
| 1769 | * @param string|null $message |
||
| 1770 | * @param string|null $propertyPath |
||
| 1771 | * |
||
| 1772 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
| 1773 | */ |
||
| 1774 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
| 1791 | |||
| 1792 | /** |
||
| 1793 | * Determines that the provided value is callable. |
||
| 1794 | * |
||
| 1795 | * @param mixed $value |
||
| 1796 | * @param null $message |
||
| 1797 | * @param null $propertyPath |
||
| 1798 | */ |
||
| 1799 | public static function isCallable($value, $message = null, $propertyPath = null) |
||
| 1810 | |||
| 1811 | /** |
||
| 1812 | * Assert that the provided value is valid according to a callback. |
||
| 1813 | * |
||
| 1814 | * If the callback returns `false` the assertion will fail. |
||
| 1815 | * |
||
| 1816 | * @param mixed $value |
||
| 1817 | * @param callable $callback |
||
| 1818 | * @param string|null $message |
||
| 1819 | * @param string|null $propertyPath |
||
| 1820 | */ |
||
| 1821 | public static function satisfy($value, $callback, $message = null, $propertyPath = null) |
||
| 1834 | |||
| 1835 | /** |
||
| 1836 | * Make a string version of a value. |
||
| 1837 | * |
||
| 1838 | * @param mixed $value |
||
| 1839 | * @return string |
||
| 1840 | */ |
||
| 1841 | protected static function stringify($value) |
||
| 1875 | } |
||
| 1876 | |||
| 1877 |