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 |
||
| 146 | class Assertion |
||
| 147 | { |
||
| 148 | const INVALID_FLOAT = 9; |
||
| 149 | const INVALID_INTEGER = 10; |
||
| 150 | const INVALID_DIGIT = 11; |
||
| 151 | const INVALID_INTEGERISH = 12; |
||
| 152 | const INVALID_BOOLEAN = 13; |
||
| 153 | const VALUE_EMPTY = 14; |
||
| 154 | const VALUE_NULL = 15; |
||
| 155 | const INVALID_STRING = 16; |
||
| 156 | const INVALID_REGEX = 17; |
||
| 157 | const INVALID_MIN_LENGTH = 18; |
||
| 158 | const INVALID_MAX_LENGTH = 19; |
||
| 159 | const INVALID_STRING_START = 20; |
||
| 160 | const INVALID_STRING_CONTAINS = 21; |
||
| 161 | const INVALID_CHOICE = 22; |
||
| 162 | const INVALID_NUMERIC = 23; |
||
| 163 | const INVALID_ARRAY = 24; |
||
| 164 | const INVALID_KEY_EXISTS = 26; |
||
| 165 | const INVALID_NOT_BLANK = 27; |
||
| 166 | const INVALID_INSTANCE_OF = 28; |
||
| 167 | const INVALID_SUBCLASS_OF = 29; |
||
| 168 | const INVALID_RANGE = 30; |
||
| 169 | const INVALID_ALNUM = 31; |
||
| 170 | const INVALID_TRUE = 32; |
||
| 171 | const INVALID_EQ = 33; |
||
| 172 | const INVALID_SAME = 34; |
||
| 173 | const INVALID_MIN = 35; |
||
| 174 | const INVALID_MAX = 36; |
||
| 175 | const INVALID_LENGTH = 37; |
||
| 176 | const INVALID_FALSE = 38; |
||
| 177 | const INVALID_STRING_END = 39; |
||
| 178 | const INVALID_UUID = 40; |
||
| 179 | const INVALID_COUNT = 41; |
||
| 180 | const INVALID_NOT_EQ = 42; |
||
| 181 | const INVALID_NOT_SAME = 43; |
||
| 182 | const INVALID_TRAVERSABLE = 44; |
||
| 183 | const INVALID_ARRAY_ACCESSIBLE = 45; |
||
| 184 | const INVALID_KEY_ISSET = 46; |
||
| 185 | const INVALID_DIRECTORY = 101; |
||
| 186 | const INVALID_FILE = 102; |
||
| 187 | const INVALID_READABLE = 103; |
||
| 188 | const INVALID_WRITEABLE = 104; |
||
| 189 | const INVALID_CLASS = 105; |
||
| 190 | const INVALID_EMAIL = 201; |
||
| 191 | const INTERFACE_NOT_IMPLEMENTED = 202; |
||
| 192 | const INVALID_URL = 203; |
||
| 193 | const INVALID_NOT_INSTANCE_OF = 204; |
||
| 194 | const VALUE_NOT_EMPTY = 205; |
||
| 195 | const INVALID_JSON_STRING = 206; |
||
| 196 | const INVALID_OBJECT = 207; |
||
| 197 | const INVALID_METHOD = 208; |
||
| 198 | const INVALID_SCALAR = 209; |
||
| 199 | const INVALID_LESS = 210; |
||
| 200 | const INVALID_LESS_OR_EQUAL = 211; |
||
| 201 | const INVALID_GREATER = 212; |
||
| 202 | const INVALID_GREATER_OR_EQUAL = 212; |
||
| 203 | const INVALID_DATE = 213; |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Exception to throw when an assertion failed. |
||
| 207 | * |
||
| 208 | * @var string |
||
| 209 | */ |
||
| 210 | static protected $exceptionClass = 'Assert\InvalidArgumentException'; |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Assertion class name. |
||
| 214 | * |
||
| 215 | * @var string |
||
| 216 | */ |
||
| 217 | static protected $assertionClass = 'Assert\Assertion'; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * AssertionChain class name. |
||
| 221 | * |
||
| 222 | * @var string |
||
| 223 | */ |
||
| 224 | static protected $chainClass = 'Assert\AssertionChain'; |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Lazy Assertion class name. |
||
| 228 | * |
||
| 229 | * @var string |
||
| 230 | */ |
||
| 231 | static protected $lazyClass = 'Assert\LazyAssertion'; |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @return string |
||
| 235 | */ |
||
| 236 | public static function getAssertionClass() |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @return string |
||
| 243 | */ |
||
| 244 | public static function getChainClass() |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @return string |
||
| 251 | */ |
||
| 252 | public static function getLazyClass() |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Helper method that handles building the assertion failure exceptions. |
||
| 259 | * They are returned from this method so that the stack trace still shows |
||
| 260 | * the assertions method. |
||
| 261 | */ |
||
| 262 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array()) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Assert that two values are equal (using == ). |
||
| 270 | * |
||
| 271 | * @param mixed $value |
||
| 272 | * @param mixed $value2 |
||
| 273 | * @param string|null $message |
||
| 274 | * @param string|null $propertyPath |
||
| 275 | * @return void |
||
| 276 | * @throws \Assert\AssertionFailedException |
||
| 277 | */ |
||
| 278 | public static function eq($value, $value2, $message = null, $propertyPath = null) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Assert that two values are the same (using ===). |
||
| 293 | * |
||
| 294 | * @param mixed $value |
||
| 295 | * @param mixed $value2 |
||
| 296 | * @param string|null $message |
||
| 297 | * @param string|null $propertyPath |
||
| 298 | * @return void |
||
| 299 | * @throws \Assert\AssertionFailedException |
||
| 300 | */ |
||
| 301 | public static function same($value, $value2, $message = null, $propertyPath = null) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Assert that two values are not equal (using == ). |
||
| 316 | * |
||
| 317 | * @param mixed $value1 |
||
| 318 | * @param mixed $value2 |
||
| 319 | * @param string|null $message |
||
| 320 | * @param string|null $propertyPath |
||
| 321 | * @return void |
||
| 322 | * @throws \Assert\AssertionFailedException |
||
| 323 | */ |
||
| 324 | public static function notEq($value1, $value2, $message = null, $propertyPath = null) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Assert that two values are not the same (using === ). |
||
| 338 | * |
||
| 339 | * @param mixed $value1 |
||
| 340 | * @param mixed $value2 |
||
| 341 | * @param string|null $message |
||
| 342 | * @param string|null $propertyPath |
||
| 343 | * @return void |
||
| 344 | * @throws \Assert\AssertionFailedException |
||
| 345 | */ |
||
| 346 | public static function notSame($value1, $value2, $message = null, $propertyPath = null) |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Assert that value is a php integer. |
||
| 360 | * |
||
| 361 | * @param mixed $value |
||
| 362 | * @param string|null $message |
||
| 363 | * @param string|null $propertyPath |
||
| 364 | * @return void |
||
| 365 | * @throws \Assert\AssertionFailedException |
||
| 366 | */ |
||
| 367 | public static function integer($value, $message = null, $propertyPath = null) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Assert that value is a php float. |
||
| 381 | * |
||
| 382 | * @param mixed $value |
||
| 383 | * @param string|null $message |
||
| 384 | * @param string|null $propertyPath |
||
| 385 | * @return void |
||
| 386 | * @throws \Assert\AssertionFailedException |
||
| 387 | */ |
||
| 388 | public static function float($value, $message = null, $propertyPath = null) |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Validates if an integer or integerish is a digit. |
||
| 402 | * |
||
| 403 | * @param mixed $value |
||
| 404 | * @param string|null $message |
||
| 405 | * @param string|null $propertyPath |
||
| 406 | * @return void |
||
| 407 | * @throws \Assert\AssertionFailedException |
||
| 408 | */ |
||
| 409 | public static function digit($value, $message = null, $propertyPath = null) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Assert that value is a php integer'ish. |
||
| 423 | * @param mixed $value |
||
| 424 | * @param string|null $message |
||
| 425 | * @param string|null $propertyPath |
||
| 426 | * @return void |
||
| 427 | * @throws \Assert\AssertionFailedException |
||
| 428 | */ |
||
| 429 | public static function integerish($value, $message = null, $propertyPath = null) |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Assert that value is php boolean |
||
| 443 | * |
||
| 444 | * @param mixed $value |
||
| 445 | * @param string|null $message |
||
| 446 | * @param string|null $propertyPath |
||
| 447 | * @return void |
||
| 448 | * @throws \Assert\AssertionFailedException |
||
| 449 | */ |
||
| 450 | public static function boolean($value, $message = null, $propertyPath = null) |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Assert that value is a PHP scalar |
||
| 464 | * |
||
| 465 | * @param mixed $value |
||
| 466 | * @param string|null $message |
||
| 467 | * @param string|null $propertyPath |
||
| 468 | * @return void |
||
| 469 | * @throws \Assert\AssertionFailedException |
||
| 470 | */ |
||
| 471 | public static function scalar($value, $message = null, $propertyPath = null) |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Assert that value is not empty |
||
| 485 | * |
||
| 486 | * @param mixed $value |
||
| 487 | * @param string|null $message |
||
| 488 | * @param string|null $propertyPath |
||
| 489 | * @return void |
||
| 490 | * @throws \Assert\AssertionFailedException |
||
| 491 | */ |
||
| 492 | public static function notEmpty($value, $message = null, $propertyPath = null) |
||
| 503 | |||
| 504 | /** |
||
| 505 | * Assert that value is empty |
||
| 506 | * |
||
| 507 | * @param mixed $value |
||
| 508 | * @param string|null $message |
||
| 509 | * @param string|null $propertyPath |
||
| 510 | * @return void |
||
| 511 | * @throws \Assert\AssertionFailedException |
||
| 512 | */ |
||
| 513 | public static function noContent($value, $message = null, $propertyPath = null) |
||
| 524 | |||
| 525 | /** |
||
| 526 | * Assert that value is not null |
||
| 527 | * |
||
| 528 | * @param mixed $value |
||
| 529 | * @param string|null $message |
||
| 530 | * @param string|null $propertyPath |
||
| 531 | * @return void |
||
| 532 | * @throws \Assert\AssertionFailedException |
||
| 533 | */ |
||
| 534 | public static function notNull($value, $message = null, $propertyPath = null) |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Assert that value is a string |
||
| 548 | * |
||
| 549 | * @param mixed $value |
||
| 550 | * @param string|null $message |
||
| 551 | * @param string|null $propertyPath |
||
| 552 | * @return void |
||
| 553 | * @throws \Assert\AssertionFailedException |
||
| 554 | */ |
||
| 555 | public static function string($value, $message = null, $propertyPath = null) |
||
| 567 | |||
| 568 | /** |
||
| 569 | * Assert that value matches a regex |
||
| 570 | * |
||
| 571 | * @param mixed $value |
||
| 572 | * @param string $pattern |
||
| 573 | * @param string|null $message |
||
| 574 | * @param string|null $propertyPath |
||
| 575 | * @return void |
||
| 576 | * @throws \Assert\AssertionFailedException |
||
| 577 | */ |
||
| 578 | public static function regex($value, $pattern, $message = null, $propertyPath = null) |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Assert that string has a given length. |
||
| 594 | * |
||
| 595 | * @param mixed $value |
||
| 596 | * @param int $length |
||
| 597 | * @param string|null $message |
||
| 598 | * @param string|null $propertyPath |
||
| 599 | * @param string $encoding |
||
| 600 | * @return void |
||
| 601 | * @throws \Assert\AssertionFailedException |
||
| 602 | */ |
||
| 603 | public static function length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Assert that a string is at least $minLength chars long. |
||
| 622 | * |
||
| 623 | * @param mixed $value |
||
| 624 | * @param int $minLength |
||
| 625 | * @param string|null $message |
||
| 626 | * @param string|null $propertyPath |
||
| 627 | * @param string $encoding |
||
| 628 | * @return void |
||
| 629 | * @throws \Assert\AssertionFailedException |
||
| 630 | */ |
||
| 631 | public static function minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 647 | |||
| 648 | /** |
||
| 649 | * Assert that string value is not longer than $maxLength chars. |
||
| 650 | * |
||
| 651 | * @param mixed $value |
||
| 652 | * @param integer $maxLength |
||
| 653 | * @param string|null $message |
||
| 654 | * @param string|null $propertyPath |
||
| 655 | * @param string $encoding |
||
| 656 | * @return void |
||
| 657 | * @throws \Assert\AssertionFailedException |
||
| 658 | */ |
||
| 659 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 675 | |||
| 676 | /** |
||
| 677 | * Assert that string length is between min,max lengths. |
||
| 678 | * |
||
| 679 | * @param mixed $value |
||
| 680 | * @param integer $minLength |
||
| 681 | * @param integer $maxLength |
||
| 682 | * @param string|null $message |
||
| 683 | * @param string|null $propertyPath |
||
| 684 | * @param string $encoding |
||
| 685 | * @return void |
||
| 686 | * @throws \Assert\AssertionFailedException |
||
| 687 | */ |
||
| 688 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 716 | |||
| 717 | /** |
||
| 718 | * Assert that string starts with a sequence of chars. |
||
| 719 | * |
||
| 720 | * @param mixed $string |
||
| 721 | * @param string $needle |
||
| 722 | * @param string|null $message |
||
| 723 | * @param string|null $propertyPath |
||
| 724 | * @param string $encoding |
||
| 725 | * @return void |
||
| 726 | * @throws \Assert\AssertionFailedException |
||
| 727 | */ |
||
| 728 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 743 | |||
| 744 | /** |
||
| 745 | * Assert that string ends with a sequence of chars. |
||
| 746 | * |
||
| 747 | * @param mixed $string |
||
| 748 | * @param string $needle |
||
| 749 | * @param string|null $message |
||
| 750 | * @param string|null $propertyPath |
||
| 751 | * @param string $encoding |
||
| 752 | * @return void |
||
| 753 | * @throws \Assert\AssertionFailedException |
||
| 754 | */ |
||
| 755 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Assert that string contains a sequence of chars. |
||
| 775 | * |
||
| 776 | * @param mixed $string |
||
| 777 | * @param string $needle |
||
| 778 | * @param string|null $message |
||
| 779 | * @param string|null $propertyPath |
||
| 780 | * @param string $encoding |
||
| 781 | * @return void |
||
| 782 | * @throws \Assert\AssertionFailedException |
||
| 783 | */ |
||
| 784 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8') |
||
| 799 | |||
| 800 | /** |
||
| 801 | * Assert that value is in array of choices. |
||
| 802 | * |
||
| 803 | * @param mixed $value |
||
| 804 | * @param array $choices |
||
| 805 | * @param string|null $message |
||
| 806 | * @param string|null $propertyPath |
||
| 807 | * @return void |
||
| 808 | * @throws \Assert\AssertionFailedException |
||
| 809 | */ |
||
| 810 | public static function choice($value, array $choices, $message = null, $propertyPath = null) |
||
| 822 | |||
| 823 | /** |
||
| 824 | * Alias of {@see choice()} |
||
| 825 | * |
||
| 826 | * @throws \Assert\AssertionFailedException |
||
| 827 | */ |
||
| 828 | public static function inArray($value, array $choices, $message = null, $propertyPath = null) |
||
| 832 | |||
| 833 | /** |
||
| 834 | * Assert that value is numeric. |
||
| 835 | * |
||
| 836 | * @param mixed $value |
||
| 837 | * @param string|null $message |
||
| 838 | * @param string|null $propertyPath |
||
| 839 | * @return void |
||
| 840 | * @throws \Assert\AssertionFailedException |
||
| 841 | */ |
||
| 842 | public static function numeric($value, $message = null, $propertyPath = null) |
||
| 853 | |||
| 854 | /** |
||
| 855 | * Assert that value is an array. |
||
| 856 | * |
||
| 857 | * @param mixed $value |
||
| 858 | * @param string|null $message |
||
| 859 | * @param string|null $propertyPath |
||
| 860 | * @return void |
||
| 861 | * @throws \Assert\AssertionFailedException |
||
| 862 | */ |
||
| 863 | public static function isArray($value, $message = null, $propertyPath = null) |
||
| 874 | |||
| 875 | /** |
||
| 876 | * Assert that value is an array or a traversable object. |
||
| 877 | * |
||
| 878 | * @param mixed $value |
||
| 879 | * @param string|null $message |
||
| 880 | * @param string|null $propertyPath |
||
| 881 | * @return void |
||
| 882 | * @throws \Assert\AssertionFailedException |
||
| 883 | */ |
||
| 884 | public static function isTraversable($value, $message = null, $propertyPath = null) |
||
| 895 | |||
| 896 | /** |
||
| 897 | * Assert that value is an array or an array-accessible object. |
||
| 898 | * |
||
| 899 | * @param mixed $value |
||
| 900 | * @param string|null $message |
||
| 901 | * @param string|null $propertyPath |
||
| 902 | * @return void |
||
| 903 | * @throws \Assert\AssertionFailedException |
||
| 904 | */ |
||
| 905 | public static function isArrayAccessible($value, $message = null, $propertyPath = null) |
||
| 916 | |||
| 917 | /** |
||
| 918 | * Assert that key exists in an array |
||
| 919 | * |
||
| 920 | * @param mixed $value |
||
| 921 | * @param string|integer $key |
||
| 922 | * @param string|null $message |
||
| 923 | * @param string|null $propertyPath |
||
| 924 | * @return void |
||
| 925 | * @throws \Assert\AssertionFailedException |
||
| 926 | */ |
||
| 927 | public static function keyExists($value, $key, $message = null, $propertyPath = null) |
||
| 940 | |||
| 941 | /** |
||
| 942 | * Assert that key exists in an array/array-accessible object using isset() |
||
| 943 | * |
||
| 944 | * @param mixed $value |
||
| 945 | * @param string|integer $key |
||
| 946 | * @param string|null $message |
||
| 947 | * @param string|null $propertyPath |
||
| 948 | * @return void |
||
| 949 | * @throws \Assert\AssertionFailedException |
||
| 950 | */ |
||
| 951 | public static function keyIsset($value, $key, $message = null, $propertyPath = null) |
||
| 964 | |||
| 965 | /** |
||
| 966 | * Assert that key exists in an array/array-accessible object and it's value is not empty. |
||
| 967 | * |
||
| 968 | * @param mixed $value |
||
| 969 | * @param string|integer $key |
||
| 970 | * @param string|null $message |
||
| 971 | * @param string|null $propertyPath |
||
| 972 | * @return void |
||
| 973 | * @throws \Assert\AssertionFailedException |
||
| 974 | */ |
||
| 975 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null) |
||
| 980 | |||
| 981 | /** |
||
| 982 | * Assert that value is not blank |
||
| 983 | * |
||
| 984 | * @param mixed $value |
||
| 985 | * @param string|null $message |
||
| 986 | * @param string|null $propertyPath |
||
| 987 | * @return void |
||
| 988 | * @throws \Assert\AssertionFailedException |
||
| 989 | */ |
||
| 990 | public static function notBlank($value, $message = null, $propertyPath = null) |
||
| 1001 | |||
| 1002 | /** |
||
| 1003 | * Assert that value is instance of given class-name. |
||
| 1004 | * |
||
| 1005 | * @param mixed $value |
||
| 1006 | * @param string $className |
||
| 1007 | * @param string|null $message |
||
| 1008 | * @param string|null $propertyPath |
||
| 1009 | * @return void |
||
| 1010 | * @throws \Assert\AssertionFailedException |
||
| 1011 | */ |
||
| 1012 | public static function isInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Assert that value is not instance of given class-name. |
||
| 1027 | * |
||
| 1028 | * @param mixed $value |
||
| 1029 | * @param string $className |
||
| 1030 | * @param string|null $message |
||
| 1031 | * @param string|null $propertyPath |
||
| 1032 | * @return void |
||
| 1033 | * @throws \Assert\AssertionFailedException |
||
| 1034 | */ |
||
| 1035 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null) |
||
| 1047 | |||
| 1048 | /** |
||
| 1049 | * Assert that value is subclass of given class-name. |
||
| 1050 | * |
||
| 1051 | * @param mixed $value |
||
| 1052 | * @param string $className |
||
| 1053 | * @param string|null $message |
||
| 1054 | * @param string|null $propertyPath |
||
| 1055 | * @return void |
||
| 1056 | * @throws \Assert\AssertionFailedException |
||
| 1057 | */ |
||
| 1058 | public static function subclassOf($value, $className, $message = null, $propertyPath = null) |
||
| 1070 | |||
| 1071 | /** |
||
| 1072 | * Assert that value is in range of numbers. |
||
| 1073 | * |
||
| 1074 | * @param mixed $value |
||
| 1075 | * @param integer $minValue |
||
| 1076 | * @param integer $maxValue |
||
| 1077 | * @param string|null $message |
||
| 1078 | * @param string|null $propertyPath |
||
| 1079 | * @return void |
||
| 1080 | * @throws \Assert\AssertionFailedException |
||
| 1081 | */ |
||
| 1082 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null) |
||
| 1097 | |||
| 1098 | /** |
||
| 1099 | * Assert that a value is at least as big as a given limit |
||
| 1100 | * |
||
| 1101 | * @param mixed $value |
||
| 1102 | * @param mixed $minValue |
||
| 1103 | * @param string|null $message |
||
| 1104 | * @param string|null $propertyPath |
||
| 1105 | * @return void |
||
| 1106 | * @throws \Assert\AssertionFailedException |
||
| 1107 | */ |
||
| 1108 | public static function min($value, $minValue, $message = null, $propertyPath = null) |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Assert that a number is smaller as a given limit |
||
| 1125 | * |
||
| 1126 | * @param mixed $value |
||
| 1127 | * @param mixed $maxValue |
||
| 1128 | * @param string|null $message |
||
| 1129 | * @param string|null $propertyPath |
||
| 1130 | * @return void |
||
| 1131 | * @throws \Assert\AssertionFailedException |
||
| 1132 | */ |
||
| 1133 | public static function max($value, $maxValue, $message = null, $propertyPath = null) |
||
| 1147 | |||
| 1148 | /** |
||
| 1149 | * Assert that a file exists |
||
| 1150 | * |
||
| 1151 | * @param string $value |
||
| 1152 | * @param string|null $message |
||
| 1153 | * @param string|null $propertyPath |
||
| 1154 | * @return void |
||
| 1155 | * @throws \Assert\AssertionFailedException |
||
| 1156 | */ |
||
| 1157 | public static function file($value, $message = null, $propertyPath = null) |
||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Assert that a directory exists |
||
| 1174 | * |
||
| 1175 | * @param string $value |
||
| 1176 | * @param string|null $message |
||
| 1177 | * @param string|null $propertyPath |
||
| 1178 | * @return void |
||
| 1179 | * @throws \Assert\AssertionFailedException |
||
| 1180 | */ |
||
| 1181 | public static function directory($value, $message = null, $propertyPath = null) |
||
| 1194 | |||
| 1195 | /** |
||
| 1196 | * Assert that the value is something readable |
||
| 1197 | * |
||
| 1198 | * @param string $value |
||
| 1199 | * @param string|null $message |
||
| 1200 | * @param string|null $propertyPath |
||
| 1201 | * @return void |
||
| 1202 | * @throws \Assert\AssertionFailedException |
||
| 1203 | */ |
||
| 1204 | public static function readable($value, $message = null, $propertyPath = null) |
||
| 1217 | |||
| 1218 | /** |
||
| 1219 | * Assert that the value is something writeable |
||
| 1220 | * |
||
| 1221 | * @param string $value |
||
| 1222 | * @param string|null $message |
||
| 1223 | * @param string|null $propertyPath |
||
| 1224 | * @return void |
||
| 1225 | * @throws \Assert\AssertionFailedException |
||
| 1226 | */ |
||
| 1227 | public static function writeable($value, $message = null, $propertyPath = null) |
||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * Assert that value is an email adress (using |
||
| 1243 | * input_filter/FILTER_VALIDATE_EMAIL). |
||
| 1244 | * |
||
| 1245 | * @param mixed $value |
||
| 1246 | * @param string|null $message |
||
| 1247 | * @param string|null $propertyPath |
||
| 1248 | * @return void |
||
| 1249 | * @throws \Assert\AssertionFailedException |
||
| 1250 | */ |
||
| 1251 | public static function email($value, $message = null, $propertyPath = null) |
||
| 1276 | |||
| 1277 | /** |
||
| 1278 | * Assert that value is an URL. |
||
| 1279 | * |
||
| 1280 | * This code snipped was taken from the Symfony project and modified to the special demands of this method. |
||
| 1281 | * |
||
| 1282 | * @param mixed $value |
||
| 1283 | * @param string|null $message |
||
| 1284 | * @param string|null $propertyPath |
||
| 1285 | * @return void |
||
| 1286 | * @throws \Assert\AssertionFailedException |
||
| 1287 | * |
||
| 1288 | * |
||
| 1289 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php |
||
| 1290 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php |
||
| 1291 | */ |
||
| 1292 | public static function url($value, $message = null, $propertyPath = null) |
||
| 1325 | |||
| 1326 | /** |
||
| 1327 | * Assert that value is alphanumeric. |
||
| 1328 | * |
||
| 1329 | * @param mixed $value |
||
| 1330 | * @param string|null $message |
||
| 1331 | * @param string|null $propertyPath |
||
| 1332 | * @return void |
||
| 1333 | * @throws \Assert\AssertionFailedException |
||
| 1334 | */ |
||
| 1335 | public static function alnum($value, $message = null, $propertyPath = null) |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Assert that the value is boolean True. |
||
| 1351 | * |
||
| 1352 | * @param mixed $value |
||
| 1353 | * @param string|null $message |
||
| 1354 | * @param string|null $propertyPath |
||
| 1355 | * @return void |
||
| 1356 | * @throws \Assert\AssertionFailedException |
||
| 1357 | */ |
||
| 1358 | public static function true($value, $message = null, $propertyPath = null) |
||
| 1369 | |||
| 1370 | /** |
||
| 1371 | * Assert that the value is boolean False. |
||
| 1372 | * |
||
| 1373 | * @param mixed $value |
||
| 1374 | * @param string|null $message |
||
| 1375 | * @param string|null $propertyPath |
||
| 1376 | * @return void |
||
| 1377 | * @throws \Assert\AssertionFailedException |
||
| 1378 | */ |
||
| 1379 | public static function false($value, $message = null, $propertyPath = null) |
||
| 1390 | |||
| 1391 | /** |
||
| 1392 | * Assert that the class exists. |
||
| 1393 | * |
||
| 1394 | * @param mixed $value |
||
| 1395 | * @param string|null $message |
||
| 1396 | * @param string|null $propertyPath |
||
| 1397 | * @return void |
||
| 1398 | * @throws \Assert\AssertionFailedException |
||
| 1399 | */ |
||
| 1400 | public static function classExists($value, $message = null, $propertyPath = null) |
||
| 1411 | |||
| 1412 | /** |
||
| 1413 | * Assert that the class implements the interface |
||
| 1414 | * |
||
| 1415 | * @param mixed $class |
||
| 1416 | * @param string $interfaceName |
||
| 1417 | * @param string|null $message |
||
| 1418 | * @param string|null $propertyPath |
||
| 1419 | * @return void |
||
| 1420 | * @throws \Assert\AssertionFailedException |
||
| 1421 | */ |
||
| 1422 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null) |
||
| 1435 | |||
| 1436 | /** |
||
| 1437 | * Assert that the given string is a valid json string. |
||
| 1438 | * |
||
| 1439 | * NOTICE: |
||
| 1440 | * Since this does a json_decode to determine its validity |
||
| 1441 | * you probably should consider, when using the variable |
||
| 1442 | * content afterwards, just to decode and check for yourself instead |
||
| 1443 | * of using this assertion. |
||
| 1444 | * |
||
| 1445 | * @param mixed $value |
||
| 1446 | * @param string|null $message |
||
| 1447 | * @param string|null $propertyPath |
||
| 1448 | * @return void |
||
| 1449 | * @throws \Assert\AssertionFailedException |
||
| 1450 | */ |
||
| 1451 | public static function isJsonString($value, $message = null, $propertyPath = null) |
||
| 1462 | |||
| 1463 | /** |
||
| 1464 | * Assert that the given string is a valid UUID |
||
| 1465 | * |
||
| 1466 | * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. |
||
| 1467 | * |
||
| 1468 | * @param string $value |
||
| 1469 | * @param string|null $message |
||
| 1470 | * @param string|null $propertyPath |
||
| 1471 | * @return void |
||
| 1472 | * @throws \Assert\AssertionFailedException |
||
| 1473 | */ |
||
| 1474 | public static function uuid($value, $message = null, $propertyPath = null) |
||
| 1491 | |||
| 1492 | /** |
||
| 1493 | * Assert that the count of countable is equal to count. |
||
| 1494 | * |
||
| 1495 | * @param array|\Countable $countable |
||
| 1496 | * @param int $count |
||
| 1497 | * @param string $message |
||
| 1498 | * @param string $propertyPath |
||
| 1499 | * @return void |
||
| 1500 | * @throws \Assert\AssertionFailedException |
||
| 1501 | */ |
||
| 1502 | public static function count($countable, $count, $message = null, $propertyPath = null) |
||
| 1513 | |||
| 1514 | /** |
||
| 1515 | * static call handler to implement: |
||
| 1516 | * - "null or assertion" delegation |
||
| 1517 | * - "all" delegation |
||
| 1518 | */ |
||
| 1519 | public static function __callStatic($method, $args) |
||
| 1555 | |||
| 1556 | /** |
||
| 1557 | * Determines if the values array has every choice as key and that this choice has content. |
||
| 1558 | * |
||
| 1559 | * @param array $values |
||
| 1560 | * @param array $choices |
||
| 1561 | * @param null $message |
||
| 1562 | * @param null $propertyPath |
||
| 1563 | */ |
||
| 1564 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null) |
||
| 1573 | |||
| 1574 | /** |
||
| 1575 | * Determines that the named method is defined in the provided object. |
||
| 1576 | * |
||
| 1577 | * @param string $value |
||
| 1578 | * @param mixed $object |
||
| 1579 | * @param null $message |
||
| 1580 | * @param null $propertyPath |
||
| 1581 | * |
||
| 1582 | * @throws |
||
| 1583 | */ |
||
| 1584 | public static function methodExists($value, $object, $message = null, $propertyPath = null) |
||
| 1597 | |||
| 1598 | /** |
||
| 1599 | * Determines that the provided value is an object. |
||
| 1600 | * |
||
| 1601 | * @param mixed $value |
||
| 1602 | * @param null $message |
||
| 1603 | * @param null $propertyPath |
||
| 1604 | */ |
||
| 1605 | public static function isObject($value, $message = null, $propertyPath = null) |
||
| 1617 | |||
| 1618 | /** |
||
| 1619 | * Determines if the value is less than given limit. |
||
| 1620 | * |
||
| 1621 | * @param mixed $value |
||
| 1622 | * @param mixed $limit |
||
| 1623 | * @param null $message |
||
| 1624 | * @param null $propertyPath |
||
| 1625 | */ |
||
| 1626 | public static function lessThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1638 | |||
| 1639 | /** |
||
| 1640 | * Determines if the value is less or than given limit. |
||
| 1641 | * |
||
| 1642 | * @param mixed $value |
||
| 1643 | * @param mixed $limit |
||
| 1644 | * @param null $message |
||
| 1645 | * @param null $propertyPath |
||
| 1646 | */ |
||
| 1647 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1659 | |||
| 1660 | /** |
||
| 1661 | * Determines if the value is greater than given limit. |
||
| 1662 | * |
||
| 1663 | * @param mixed $value |
||
| 1664 | * @param mixed $limit |
||
| 1665 | * @param null $message |
||
| 1666 | * @param null $propertyPath |
||
| 1667 | */ |
||
| 1668 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * Determines if the value is greater or equal than given limit. |
||
| 1683 | * |
||
| 1684 | * @param mixed $value |
||
| 1685 | * @param mixed $limit |
||
| 1686 | * @param null $message |
||
| 1687 | * @param null $propertyPath |
||
| 1688 | */ |
||
| 1689 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null) |
||
| 1701 | |||
| 1702 | /** |
||
| 1703 | * Assert that date is valid and corresponds to the given format. |
||
| 1704 | * |
||
| 1705 | * @param string $value |
||
| 1706 | * @param string $format supports all of the options date(), except for the following: |
||
| 1707 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r. |
||
| 1708 | * @param string|null $message |
||
| 1709 | * @param string|null $propertyPath |
||
| 1710 | * |
||
| 1711 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters |
||
| 1712 | */ |
||
| 1713 | public static function date($value, $format, $message = null, $propertyPath = null) |
||
| 1730 | |||
| 1731 | /** |
||
| 1732 | * Make a string version of a value. |
||
| 1733 | * |
||
| 1734 | * @param mixed $value |
||
| 1735 | * @return string |
||
| 1736 | */ |
||
| 1737 | protected static function stringify($value) |
||
| 1771 | } |
||
| 1772 | |||
| 1773 |