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  | 
            ||
| 162 | class Assertion  | 
            ||
| 163 | { | 
            ||
| 164 | const INVALID_FLOAT = 9;  | 
            ||
| 165 | const INVALID_INTEGER = 10;  | 
            ||
| 166 | const INVALID_DIGIT = 11;  | 
            ||
| 167 | const INVALID_INTEGERISH = 12;  | 
            ||
| 168 | const INVALID_BOOLEAN = 13;  | 
            ||
| 169 | const VALUE_EMPTY = 14;  | 
            ||
| 170 | const VALUE_NULL = 15;  | 
            ||
| 171 | const VALUE_NOT_NULL = 25;  | 
            ||
| 172 | const INVALID_STRING = 16;  | 
            ||
| 173 | const INVALID_REGEX = 17;  | 
            ||
| 174 | const INVALID_MIN_LENGTH = 18;  | 
            ||
| 175 | const INVALID_MAX_LENGTH = 19;  | 
            ||
| 176 | const INVALID_STRING_START = 20;  | 
            ||
| 177 | const INVALID_STRING_CONTAINS = 21;  | 
            ||
| 178 | const INVALID_CHOICE = 22;  | 
            ||
| 179 | const INVALID_NUMERIC = 23;  | 
            ||
| 180 | const INVALID_ARRAY = 24;  | 
            ||
| 181 | const INVALID_KEY_EXISTS = 26;  | 
            ||
| 182 | const INVALID_NOT_BLANK = 27;  | 
            ||
| 183 | const INVALID_INSTANCE_OF = 28;  | 
            ||
| 184 | const INVALID_SUBCLASS_OF = 29;  | 
            ||
| 185 | const INVALID_RANGE = 30;  | 
            ||
| 186 | const INVALID_ALNUM = 31;  | 
            ||
| 187 | const INVALID_TRUE = 32;  | 
            ||
| 188 | const INVALID_EQ = 33;  | 
            ||
| 189 | const INVALID_SAME = 34;  | 
            ||
| 190 | const INVALID_MIN = 35;  | 
            ||
| 191 | const INVALID_MAX = 36;  | 
            ||
| 192 | const INVALID_LENGTH = 37;  | 
            ||
| 193 | const INVALID_FALSE = 38;  | 
            ||
| 194 | const INVALID_STRING_END = 39;  | 
            ||
| 195 | const INVALID_UUID = 40;  | 
            ||
| 196 | const INVALID_COUNT = 41;  | 
            ||
| 197 | const INVALID_NOT_EQ = 42;  | 
            ||
| 198 | const INVALID_NOT_SAME = 43;  | 
            ||
| 199 | const INVALID_TRAVERSABLE = 44;  | 
            ||
| 200 | const INVALID_ARRAY_ACCESSIBLE = 45;  | 
            ||
| 201 | const INVALID_KEY_ISSET = 46;  | 
            ||
| 202 | const INVALID_VALUE_IN_ARRAY = 47;  | 
            ||
| 203 | const INVALID_DIRECTORY = 101;  | 
            ||
| 204 | const INVALID_FILE = 102;  | 
            ||
| 205 | const INVALID_READABLE = 103;  | 
            ||
| 206 | const INVALID_WRITEABLE = 104;  | 
            ||
| 207 | const INVALID_CLASS = 105;  | 
            ||
| 208 | const INVALID_INTERFACE = 106;  | 
            ||
| 209 | const INVALID_EMAIL = 201;  | 
            ||
| 210 | const INTERFACE_NOT_IMPLEMENTED = 202;  | 
            ||
| 211 | const INVALID_URL = 203;  | 
            ||
| 212 | const INVALID_NOT_INSTANCE_OF = 204;  | 
            ||
| 213 | const VALUE_NOT_EMPTY = 205;  | 
            ||
| 214 | const INVALID_JSON_STRING = 206;  | 
            ||
| 215 | const INVALID_OBJECT = 207;  | 
            ||
| 216 | const INVALID_METHOD = 208;  | 
            ||
| 217 | const INVALID_SCALAR = 209;  | 
            ||
| 218 | const INVALID_LESS = 210;  | 
            ||
| 219 | const INVALID_LESS_OR_EQUAL = 211;  | 
            ||
| 220 | const INVALID_GREATER = 212;  | 
            ||
| 221 | const INVALID_GREATER_OR_EQUAL = 213;  | 
            ||
| 222 | const INVALID_DATE = 214;  | 
            ||
| 223 | const INVALID_CALLABLE = 215;  | 
            ||
| 224 | const INVALID_KEY_NOT_EXISTS = 216;  | 
            ||
| 225 | const INVALID_SATISFY = 217;  | 
            ||
| 226 | const INVALID_IP = 218;  | 
            ||
| 227 | |||
| 228 | /**  | 
            ||
| 229 | * Exception to throw when an assertion failed.  | 
            ||
| 230 | *  | 
            ||
| 231 | * @var string  | 
            ||
| 232 | */  | 
            ||
| 233 | static protected $exceptionClass = 'Assert\InvalidArgumentException';  | 
            ||
| 234 | |||
| 235 | /**  | 
            ||
| 236 | * Helper method that handles building the assertion failure exceptions.  | 
            ||
| 237 | * They are returned from this method so that the stack trace still shows  | 
            ||
| 238 | * the assertions method.  | 
            ||
| 239 | */  | 
            ||
| 240 | protected static function createException($value, $message, $code, $propertyPath, array $constraints = array())  | 
            ||
| 245 | |||
| 246 | /**  | 
            ||
| 247 | * Assert that two values are equal (using == ).  | 
            ||
| 248 | *  | 
            ||
| 249 | * @param mixed $value  | 
            ||
| 250 | * @param mixed $value2  | 
            ||
| 251 | * @param string|null $message  | 
            ||
| 252 | * @param string|null $propertyPath  | 
            ||
| 253 | * @return void  | 
            ||
| 254 | * @throws \Assert\AssertionFailedException  | 
            ||
| 255 | */  | 
            ||
| 256 | public static function eq($value, $value2, $message = null, $propertyPath = null)  | 
            ||
| 268 | |||
| 269 | /**  | 
            ||
| 270 | * Assert that two values are the same (using ===).  | 
            ||
| 271 | *  | 
            ||
| 272 | * @param mixed $value  | 
            ||
| 273 | * @param mixed $value2  | 
            ||
| 274 | * @param string|null $message  | 
            ||
| 275 | * @param string|null $propertyPath  | 
            ||
| 276 | * @return void  | 
            ||
| 277 | * @throws \Assert\AssertionFailedException  | 
            ||
| 278 | */  | 
            ||
| 279 | public static function same($value, $value2, $message = null, $propertyPath = null)  | 
            ||
| 291 | |||
| 292 | /**  | 
            ||
| 293 | * Assert that two values are not equal (using == ).  | 
            ||
| 294 | *  | 
            ||
| 295 | * @param mixed $value1  | 
            ||
| 296 | * @param mixed $value2  | 
            ||
| 297 | * @param string|null $message  | 
            ||
| 298 | * @param string|null $propertyPath  | 
            ||
| 299 | * @return void  | 
            ||
| 300 | * @throws \Assert\AssertionFailedException  | 
            ||
| 301 | */  | 
            ||
| 302 | public static function notEq($value1, $value2, $message = null, $propertyPath = null)  | 
            ||
| 313 | |||
| 314 | /**  | 
            ||
| 315 | * Assert that two values are not the same (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 notSame($value1, $value2, $message = null, $propertyPath = null)  | 
            ||
| 335 | |||
| 336 | /**  | 
            ||
| 337 | * Assert that value is not in array of choices.  | 
            ||
| 338 | *  | 
            ||
| 339 | * @param mixed $value  | 
            ||
| 340 | * @param array $choices  | 
            ||
| 341 | * @param string|null $message  | 
            ||
| 342 | * @param string|null $propertyPath  | 
            ||
| 343 | * @return void  | 
            ||
| 344 | * @throws \Assert\AssertionFailedException  | 
            ||
| 345 | */  | 
            ||
| 346 | public static function notInArray($value, array $choices, $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 | *  | 
            ||
| 424 | * @param mixed $value  | 
            ||
| 425 | * @param string|null $message  | 
            ||
| 426 | * @param string|null $propertyPath  | 
            ||
| 427 | * @return void  | 
            ||
| 428 | * @throws \Assert\AssertionFailedException  | 
            ||
| 429 | */  | 
            ||
| 430 | public static function integerish($value, $message = null, $propertyPath = null)  | 
            ||
| 441 | |||
| 442 | /**  | 
            ||
| 443 | * Assert that value is php boolean  | 
            ||
| 444 | *  | 
            ||
| 445 | * @param mixed $value  | 
            ||
| 446 | * @param string|null $message  | 
            ||
| 447 | * @param string|null $propertyPath  | 
            ||
| 448 | * @return void  | 
            ||
| 449 | * @throws \Assert\AssertionFailedException  | 
            ||
| 450 | */  | 
            ||
| 451 | public static function boolean($value, $message = null, $propertyPath = null)  | 
            ||
| 462 | |||
| 463 | /**  | 
            ||
| 464 | * Assert that value is a PHP scalar  | 
            ||
| 465 | *  | 
            ||
| 466 | * @param mixed $value  | 
            ||
| 467 | * @param string|null $message  | 
            ||
| 468 | * @param string|null $propertyPath  | 
            ||
| 469 | * @return void  | 
            ||
| 470 | * @throws \Assert\AssertionFailedException  | 
            ||
| 471 | */  | 
            ||
| 472 | public static function scalar($value, $message = null, $propertyPath = null)  | 
            ||
| 483 | |||
| 484 | /**  | 
            ||
| 485 | * Assert that value is not empty  | 
            ||
| 486 | *  | 
            ||
| 487 | * @param mixed $value  | 
            ||
| 488 | * @param string|null $message  | 
            ||
| 489 | * @param string|null $propertyPath  | 
            ||
| 490 | * @return void  | 
            ||
| 491 | * @throws \Assert\AssertionFailedException  | 
            ||
| 492 | */  | 
            ||
| 493 | public static function notEmpty($value, $message = null, $propertyPath = null)  | 
            ||
| 504 | |||
| 505 | /**  | 
            ||
| 506 | * Assert that value is empty  | 
            ||
| 507 | *  | 
            ||
| 508 | * @param mixed $value  | 
            ||
| 509 | * @param string|null $message  | 
            ||
| 510 | * @param string|null $propertyPath  | 
            ||
| 511 | * @return void  | 
            ||
| 512 | * @throws \Assert\AssertionFailedException  | 
            ||
| 513 | */  | 
            ||
| 514 | public static function noContent($value, $message = null, $propertyPath = null)  | 
            ||
| 525 | |||
| 526 | /**  | 
            ||
| 527 | * Assert that value is null  | 
            ||
| 528 | *  | 
            ||
| 529 | * @param mixed $value  | 
            ||
| 530 | * @param string|null $message  | 
            ||
| 531 | * @param string|null $propertyPath  | 
            ||
| 532 | * @return void  | 
            ||
| 533 | * @throws \Assert\AssertionFailedException  | 
            ||
| 534 | */  | 
            ||
| 535 | public static function null($value, $message = null, $propertyPath = null)  | 
            ||
| 546 | |||
| 547 | /**  | 
            ||
| 548 | * Assert that value is not null  | 
            ||
| 549 | *  | 
            ||
| 550 | * @param mixed $value  | 
            ||
| 551 | * @param string|null $message  | 
            ||
| 552 | * @param string|null $propertyPath  | 
            ||
| 553 | * @return void  | 
            ||
| 554 | * @throws \Assert\AssertionFailedException  | 
            ||
| 555 | */  | 
            ||
| 556 | public static function notNull($value, $message = null, $propertyPath = null)  | 
            ||
| 567 | |||
| 568 | /**  | 
            ||
| 569 | * Assert that value is a string  | 
            ||
| 570 | *  | 
            ||
| 571 | * @param mixed $value  | 
            ||
| 572 | * @param string|null $message  | 
            ||
| 573 | * @param string|null $propertyPath  | 
            ||
| 574 | * @return void  | 
            ||
| 575 | * @throws \Assert\AssertionFailedException  | 
            ||
| 576 | */  | 
            ||
| 577 | public static function string($value, $message = null, $propertyPath = null)  | 
            ||
| 589 | |||
| 590 | /**  | 
            ||
| 591 | * Assert that value matches a regex  | 
            ||
| 592 | *  | 
            ||
| 593 | * @param mixed $value  | 
            ||
| 594 | * @param string $pattern  | 
            ||
| 595 | * @param string|null $message  | 
            ||
| 596 | * @param string|null $propertyPath  | 
            ||
| 597 | * @return void  | 
            ||
| 598 | * @throws \Assert\AssertionFailedException  | 
            ||
| 599 | */  | 
            ||
| 600 | public static function regex($value, $pattern, $message = null, $propertyPath = null)  | 
            ||
| 613 | |||
| 614 | /**  | 
            ||
| 615 | * Assert that string has a given length.  | 
            ||
| 616 | *  | 
            ||
| 617 | * @param mixed $value  | 
            ||
| 618 | * @param int $length  | 
            ||
| 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 length($value, $length, $message = null, $propertyPath = null, $encoding = 'utf8')  | 
            ||
| 641 | |||
| 642 | /**  | 
            ||
| 643 | * Assert that a string is at least $minLength chars long.  | 
            ||
| 644 | *  | 
            ||
| 645 | * @param mixed $value  | 
            ||
| 646 | * @param int $minLength  | 
            ||
| 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 minLength($value, $minLength, $message = null, $propertyPath = null, $encoding = 'utf8')  | 
            ||
| 669 | |||
| 670 | /**  | 
            ||
| 671 | * Assert that string value is not longer than $maxLength chars.  | 
            ||
| 672 | *  | 
            ||
| 673 | * @param mixed $value  | 
            ||
| 674 | * @param integer $maxLength  | 
            ||
| 675 | * @param string|null $message  | 
            ||
| 676 | * @param string|null $propertyPath  | 
            ||
| 677 | * @param string $encoding  | 
            ||
| 678 | * @return void  | 
            ||
| 679 | * @throws \Assert\AssertionFailedException  | 
            ||
| 680 | */  | 
            ||
| 681 | public static function maxLength($value, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8')  | 
            ||
| 697 | |||
| 698 | /**  | 
            ||
| 699 | * Assert that string length is between min,max lengths.  | 
            ||
| 700 | *  | 
            ||
| 701 | * @param mixed $value  | 
            ||
| 702 | * @param integer $minLength  | 
            ||
| 703 | * @param integer $maxLength  | 
            ||
| 704 | * @param string|null $message  | 
            ||
| 705 | * @param string|null $propertyPath  | 
            ||
| 706 | * @param string $encoding  | 
            ||
| 707 | * @return void  | 
            ||
| 708 | * @throws \Assert\AssertionFailedException  | 
            ||
| 709 | */  | 
            ||
| 710 | public static function betweenLength($value, $minLength, $maxLength, $message = null, $propertyPath = null, $encoding = 'utf8')  | 
            ||
| 738 | |||
| 739 | /**  | 
            ||
| 740 | * Assert that string starts with a sequence of chars.  | 
            ||
| 741 | *  | 
            ||
| 742 | * @param mixed $string  | 
            ||
| 743 | * @param string $needle  | 
            ||
| 744 | * @param string|null $message  | 
            ||
| 745 | * @param string|null $propertyPath  | 
            ||
| 746 | * @param string $encoding  | 
            ||
| 747 | * @return void  | 
            ||
| 748 | * @throws \Assert\AssertionFailedException  | 
            ||
| 749 | */  | 
            ||
| 750 | public static function startsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8')  | 
            ||
| 765 | |||
| 766 | /**  | 
            ||
| 767 | * Assert that string ends with a sequence of chars.  | 
            ||
| 768 | *  | 
            ||
| 769 | * @param mixed $string  | 
            ||
| 770 | * @param string $needle  | 
            ||
| 771 | * @param string|null $message  | 
            ||
| 772 | * @param string|null $propertyPath  | 
            ||
| 773 | * @param string $encoding  | 
            ||
| 774 | * @return void  | 
            ||
| 775 | * @throws \Assert\AssertionFailedException  | 
            ||
| 776 | */  | 
            ||
| 777 | public static function endsWith($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8')  | 
            ||
| 794 | |||
| 795 | /**  | 
            ||
| 796 | * Assert that string contains a sequence of chars.  | 
            ||
| 797 | *  | 
            ||
| 798 | * @param mixed $string  | 
            ||
| 799 | * @param string $needle  | 
            ||
| 800 | * @param string|null $message  | 
            ||
| 801 | * @param string|null $propertyPath  | 
            ||
| 802 | * @param string $encoding  | 
            ||
| 803 | * @return void  | 
            ||
| 804 | * @throws \Assert\AssertionFailedException  | 
            ||
| 805 | */  | 
            ||
| 806 | public static function contains($string, $needle, $message = null, $propertyPath = null, $encoding = 'utf8')  | 
            ||
| 821 | |||
| 822 | /**  | 
            ||
| 823 | * Assert that value is in array of choices.  | 
            ||
| 824 | *  | 
            ||
| 825 | * @param mixed $value  | 
            ||
| 826 | * @param array $choices  | 
            ||
| 827 | * @param string|null $message  | 
            ||
| 828 | * @param string|null $propertyPath  | 
            ||
| 829 | * @return void  | 
            ||
| 830 | * @throws \Assert\AssertionFailedException  | 
            ||
| 831 | */  | 
            ||
| 832 | public static function choice($value, array $choices, $message = null, $propertyPath = null)  | 
            ||
| 844 | |||
| 845 | /**  | 
            ||
| 846 |      * Alias of {@see choice()} | 
            ||
| 847 | *  | 
            ||
| 848 | * @throws \Assert\AssertionFailedException  | 
            ||
| 849 | */  | 
            ||
| 850 | public static function inArray($value, array $choices, $message = null, $propertyPath = null)  | 
            ||
| 854 | |||
| 855 | /**  | 
            ||
| 856 | * Assert that value is numeric.  | 
            ||
| 857 | *  | 
            ||
| 858 | * @param mixed $value  | 
            ||
| 859 | * @param string|null $message  | 
            ||
| 860 | * @param string|null $propertyPath  | 
            ||
| 861 | * @return void  | 
            ||
| 862 | * @throws \Assert\AssertionFailedException  | 
            ||
| 863 | */  | 
            ||
| 864 | public static function numeric($value, $message = null, $propertyPath = null)  | 
            ||
| 875 | |||
| 876 | /**  | 
            ||
| 877 | * Assert that value is an array.  | 
            ||
| 878 | *  | 
            ||
| 879 | * @param mixed $value  | 
            ||
| 880 | * @param string|null $message  | 
            ||
| 881 | * @param string|null $propertyPath  | 
            ||
| 882 | * @return void  | 
            ||
| 883 | * @throws \Assert\AssertionFailedException  | 
            ||
| 884 | */  | 
            ||
| 885 | public static function isArray($value, $message = null, $propertyPath = null)  | 
            ||
| 896 | |||
| 897 | /**  | 
            ||
| 898 | * Assert that value is an array or a traversable object.  | 
            ||
| 899 | *  | 
            ||
| 900 | * @param mixed $value  | 
            ||
| 901 | * @param string|null $message  | 
            ||
| 902 | * @param string|null $propertyPath  | 
            ||
| 903 | * @return void  | 
            ||
| 904 | * @throws \Assert\AssertionFailedException  | 
            ||
| 905 | */  | 
            ||
| 906 | public static function isTraversable($value, $message = null, $propertyPath = null)  | 
            ||
| 917 | |||
| 918 | /**  | 
            ||
| 919 | * Assert that value is an array or an array-accessible object.  | 
            ||
| 920 | *  | 
            ||
| 921 | * @param mixed $value  | 
            ||
| 922 | * @param string|null $message  | 
            ||
| 923 | * @param string|null $propertyPath  | 
            ||
| 924 | * @return void  | 
            ||
| 925 | * @throws \Assert\AssertionFailedException  | 
            ||
| 926 | */  | 
            ||
| 927 | public static function isArrayAccessible($value, $message = null, $propertyPath = null)  | 
            ||
| 938 | |||
| 939 | /**  | 
            ||
| 940 | * Assert that key exists in an array  | 
            ||
| 941 | *  | 
            ||
| 942 | * @param mixed $value  | 
            ||
| 943 | * @param string|integer $key  | 
            ||
| 944 | * @param string|null $message  | 
            ||
| 945 | * @param string|null $propertyPath  | 
            ||
| 946 | * @return void  | 
            ||
| 947 | * @throws \Assert\AssertionFailedException  | 
            ||
| 948 | */  | 
            ||
| 949 | public static function keyExists($value, $key, $message = null, $propertyPath = null)  | 
            ||
| 962 | |||
| 963 | /**  | 
            ||
| 964 | * Assert that key does not exist in an array  | 
            ||
| 965 | *  | 
            ||
| 966 | * @param mixed $value  | 
            ||
| 967 | * @param string|integer $key  | 
            ||
| 968 | * @param string|null $message  | 
            ||
| 969 | * @param string|null $propertyPath  | 
            ||
| 970 | * @return void  | 
            ||
| 971 | * @throws \Assert\AssertionFailedException  | 
            ||
| 972 | */  | 
            ||
| 973 | public static function keyNotExists($value, $key, $message = null, $propertyPath = null)  | 
            ||
| 986 | |||
| 987 | /**  | 
            ||
| 988 | * Assert that key exists in an array/array-accessible object using isset()  | 
            ||
| 989 | *  | 
            ||
| 990 | * @param mixed $value  | 
            ||
| 991 | * @param string|integer $key  | 
            ||
| 992 | * @param string|null $message  | 
            ||
| 993 | * @param string|null $propertyPath  | 
            ||
| 994 | * @return void  | 
            ||
| 995 | * @throws \Assert\AssertionFailedException  | 
            ||
| 996 | */  | 
            ||
| 997 | public static function keyIsset($value, $key, $message = null, $propertyPath = null)  | 
            ||
| 1010 | |||
| 1011 | /**  | 
            ||
| 1012 | * Assert that key exists in an array/array-accessible object and it's value is not empty.  | 
            ||
| 1013 | *  | 
            ||
| 1014 | * @param mixed $value  | 
            ||
| 1015 | * @param string|integer $key  | 
            ||
| 1016 | * @param string|null $message  | 
            ||
| 1017 | * @param string|null $propertyPath  | 
            ||
| 1018 | * @return void  | 
            ||
| 1019 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1020 | */  | 
            ||
| 1021 | public static function notEmptyKey($value, $key, $message = null, $propertyPath = null)  | 
            ||
| 1026 | |||
| 1027 | /**  | 
            ||
| 1028 | * Assert that value is not blank  | 
            ||
| 1029 | *  | 
            ||
| 1030 | * @param mixed $value  | 
            ||
| 1031 | * @param string|null $message  | 
            ||
| 1032 | * @param string|null $propertyPath  | 
            ||
| 1033 | * @return void  | 
            ||
| 1034 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1035 | */  | 
            ||
| 1036 | public static function notBlank($value, $message = null, $propertyPath = null)  | 
            ||
| 1047 | |||
| 1048 | /**  | 
            ||
| 1049 | * Assert that value is instance 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 isInstanceOf($value, $className, $message = null, $propertyPath = null)  | 
            ||
| 1070 | |||
| 1071 | /**  | 
            ||
| 1072 | * Assert that value is not instance of given class-name.  | 
            ||
| 1073 | *  | 
            ||
| 1074 | * @param mixed $value  | 
            ||
| 1075 | * @param string $className  | 
            ||
| 1076 | * @param string|null $message  | 
            ||
| 1077 | * @param string|null $propertyPath  | 
            ||
| 1078 | * @return void  | 
            ||
| 1079 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1080 | */  | 
            ||
| 1081 | public static function notIsInstanceOf($value, $className, $message = null, $propertyPath = null)  | 
            ||
| 1093 | |||
| 1094 | /**  | 
            ||
| 1095 | * Assert that value is subclass of given class-name.  | 
            ||
| 1096 | *  | 
            ||
| 1097 | * @param mixed $value  | 
            ||
| 1098 | * @param string $className  | 
            ||
| 1099 | * @param string|null $message  | 
            ||
| 1100 | * @param string|null $propertyPath  | 
            ||
| 1101 | * @return void  | 
            ||
| 1102 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1103 | */  | 
            ||
| 1104 | public static function subclassOf($value, $className, $message = null, $propertyPath = null)  | 
            ||
| 1116 | |||
| 1117 | /**  | 
            ||
| 1118 | * Assert that value is in range of numbers.  | 
            ||
| 1119 | *  | 
            ||
| 1120 | * @param mixed $value  | 
            ||
| 1121 | * @param integer $minValue  | 
            ||
| 1122 | * @param integer $maxValue  | 
            ||
| 1123 | * @param string|null $message  | 
            ||
| 1124 | * @param string|null $propertyPath  | 
            ||
| 1125 | * @return void  | 
            ||
| 1126 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1127 | */  | 
            ||
| 1128 | public static function range($value, $minValue, $maxValue, $message = null, $propertyPath = null)  | 
            ||
| 1143 | |||
| 1144 | /**  | 
            ||
| 1145 | * Assert that a value is at least as big as a given limit  | 
            ||
| 1146 | *  | 
            ||
| 1147 | * @param mixed $value  | 
            ||
| 1148 | * @param mixed $minValue  | 
            ||
| 1149 | * @param string|null $message  | 
            ||
| 1150 | * @param string|null $propertyPath  | 
            ||
| 1151 | * @return void  | 
            ||
| 1152 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1153 | */  | 
            ||
| 1154 | public static function min($value, $minValue, $message = null, $propertyPath = null)  | 
            ||
| 1168 | |||
| 1169 | /**  | 
            ||
| 1170 | * Assert that a number is smaller as a given limit  | 
            ||
| 1171 | *  | 
            ||
| 1172 | * @param mixed $value  | 
            ||
| 1173 | * @param mixed $maxValue  | 
            ||
| 1174 | * @param string|null $message  | 
            ||
| 1175 | * @param string|null $propertyPath  | 
            ||
| 1176 | * @return void  | 
            ||
| 1177 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1178 | */  | 
            ||
| 1179 | public static function max($value, $maxValue, $message = null, $propertyPath = null)  | 
            ||
| 1193 | |||
| 1194 | /**  | 
            ||
| 1195 | * Assert that a file exists  | 
            ||
| 1196 | *  | 
            ||
| 1197 | * @param string $value  | 
            ||
| 1198 | * @param string|null $message  | 
            ||
| 1199 | * @param string|null $propertyPath  | 
            ||
| 1200 | * @return void  | 
            ||
| 1201 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1202 | */  | 
            ||
| 1203 | public static function file($value, $message = null, $propertyPath = null)  | 
            ||
| 1217 | |||
| 1218 | /**  | 
            ||
| 1219 | * Assert that a directory exists  | 
            ||
| 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 directory($value, $message = null, $propertyPath = null)  | 
            ||
| 1240 | |||
| 1241 | /**  | 
            ||
| 1242 | * Assert that the value is something readable  | 
            ||
| 1243 | *  | 
            ||
| 1244 | * @param string $value  | 
            ||
| 1245 | * @param string|null $message  | 
            ||
| 1246 | * @param string|null $propertyPath  | 
            ||
| 1247 | * @return void  | 
            ||
| 1248 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1249 | */  | 
            ||
| 1250 | public static function readable($value, $message = null, $propertyPath = null)  | 
            ||
| 1263 | |||
| 1264 | /**  | 
            ||
| 1265 | * Assert that the value is something writeable  | 
            ||
| 1266 | *  | 
            ||
| 1267 | * @param string $value  | 
            ||
| 1268 | * @param string|null $message  | 
            ||
| 1269 | * @param string|null $propertyPath  | 
            ||
| 1270 | * @return void  | 
            ||
| 1271 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1272 | */  | 
            ||
| 1273 | public static function writeable($value, $message = null, $propertyPath = null)  | 
            ||
| 1286 | |||
| 1287 | /**  | 
            ||
| 1288 | * Assert that value is an email adress (using input_filter/FILTER_VALIDATE_EMAIL).  | 
            ||
| 1289 | *  | 
            ||
| 1290 | * @param mixed $value  | 
            ||
| 1291 | * @param string|null $message  | 
            ||
| 1292 | * @param string|null $propertyPath  | 
            ||
| 1293 | * @return void  | 
            ||
| 1294 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1295 | */  | 
            ||
| 1296 | public static function email($value, $message = null, $propertyPath = null)  | 
            ||
| 1321 | |||
| 1322 | /**  | 
            ||
| 1323 | * Assert that value is an URL.  | 
            ||
| 1324 | *  | 
            ||
| 1325 | * This code snipped was taken from the Symfony project and modified to the special demands of this method.  | 
            ||
| 1326 | *  | 
            ||
| 1327 | * @param mixed $value  | 
            ||
| 1328 | * @param string|null $message  | 
            ||
| 1329 | * @param string|null $propertyPath  | 
            ||
| 1330 | * @return void  | 
            ||
| 1331 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1332 | *  | 
            ||
| 1333 | *  | 
            ||
| 1334 | * @link https://github.com/symfony/Validator/blob/master/Constraints/UrlValidator.php  | 
            ||
| 1335 | * @link https://github.com/symfony/Validator/blob/master/Constraints/Url.php  | 
            ||
| 1336 | */  | 
            ||
| 1337 | public static function url($value, $message = null, $propertyPath = null)  | 
            ||
| 1370 | |||
| 1371 | /**  | 
            ||
| 1372 | * Assert that value is alphanumeric.  | 
            ||
| 1373 | *  | 
            ||
| 1374 | * @param mixed $value  | 
            ||
| 1375 | * @param string|null $message  | 
            ||
| 1376 | * @param string|null $propertyPath  | 
            ||
| 1377 | * @return void  | 
            ||
| 1378 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1379 | */  | 
            ||
| 1380 | public static function alnum($value, $message = null, $propertyPath = null)  | 
            ||
| 1393 | |||
| 1394 | /**  | 
            ||
| 1395 | * Assert that the value is boolean True.  | 
            ||
| 1396 | *  | 
            ||
| 1397 | * @param mixed $value  | 
            ||
| 1398 | * @param string|null $message  | 
            ||
| 1399 | * @param string|null $propertyPath  | 
            ||
| 1400 | * @return void  | 
            ||
| 1401 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1402 | */  | 
            ||
| 1403 | public static function true($value, $message = null, $propertyPath = null)  | 
            ||
| 1414 | |||
| 1415 | /**  | 
            ||
| 1416 | * Assert that the value is boolean False.  | 
            ||
| 1417 | *  | 
            ||
| 1418 | * @param mixed $value  | 
            ||
| 1419 | * @param string|null $message  | 
            ||
| 1420 | * @param string|null $propertyPath  | 
            ||
| 1421 | * @return void  | 
            ||
| 1422 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1423 | */  | 
            ||
| 1424 | public static function false($value, $message = null, $propertyPath = null)  | 
            ||
| 1435 | |||
| 1436 | /**  | 
            ||
| 1437 | * Assert that the class exists.  | 
            ||
| 1438 | *  | 
            ||
| 1439 | * @param mixed $value  | 
            ||
| 1440 | * @param string|null $message  | 
            ||
| 1441 | * @param string|null $propertyPath  | 
            ||
| 1442 | * @return void  | 
            ||
| 1443 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1444 | */  | 
            ||
| 1445 | public static function classExists($value, $message = null, $propertyPath = null)  | 
            ||
| 1456 | |||
| 1457 | /**  | 
            ||
| 1458 | * Assert that the interface exists.  | 
            ||
| 1459 | *  | 
            ||
| 1460 | * @param mixed $value  | 
            ||
| 1461 | * @param string|null $message  | 
            ||
| 1462 | * @param string|null $propertyPath  | 
            ||
| 1463 | * @return void  | 
            ||
| 1464 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1465 | */  | 
            ||
| 1466 | public static function interfaceExists($value, $message = null, $propertyPath = null)  | 
            ||
| 1477 | |||
| 1478 | /**  | 
            ||
| 1479 | * Assert that the class implements the interface  | 
            ||
| 1480 | *  | 
            ||
| 1481 | * @param mixed $class  | 
            ||
| 1482 | * @param string $interfaceName  | 
            ||
| 1483 | * @param string|null $message  | 
            ||
| 1484 | * @param string|null $propertyPath  | 
            ||
| 1485 | * @return void  | 
            ||
| 1486 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1487 | */  | 
            ||
| 1488 | public static function implementsInterface($class, $interfaceName, $message = null, $propertyPath = null)  | 
            ||
| 1501 | |||
| 1502 | /**  | 
            ||
| 1503 | * Assert that the given string is a valid json string.  | 
            ||
| 1504 | *  | 
            ||
| 1505 | * NOTICE:  | 
            ||
| 1506 | * Since this does a json_decode to determine its validity  | 
            ||
| 1507 | * you probably should consider, when using the variable  | 
            ||
| 1508 | * content afterwards, just to decode and check for yourself instead  | 
            ||
| 1509 | * of using this assertion.  | 
            ||
| 1510 | *  | 
            ||
| 1511 | * @param mixed $value  | 
            ||
| 1512 | * @param string|null $message  | 
            ||
| 1513 | * @param string|null $propertyPath  | 
            ||
| 1514 | * @return void  | 
            ||
| 1515 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1516 | */  | 
            ||
| 1517 | public static function isJsonString($value, $message = null, $propertyPath = null)  | 
            ||
| 1528 | |||
| 1529 | /**  | 
            ||
| 1530 | * Assert that the given string is a valid UUID  | 
            ||
| 1531 | *  | 
            ||
| 1532 |      * Uses code from {@link https://github.com/ramsey/uuid} that is MIT licensed. | 
            ||
| 1533 | *  | 
            ||
| 1534 | * @param string $value  | 
            ||
| 1535 | * @param string|null $message  | 
            ||
| 1536 | * @param string|null $propertyPath  | 
            ||
| 1537 | * @return void  | 
            ||
| 1538 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1539 | */  | 
            ||
| 1540 | public static function uuid($value, $message = null, $propertyPath = null)  | 
            ||
| 1557 | |||
| 1558 | /**  | 
            ||
| 1559 | * Assert that the count of countable is equal to count.  | 
            ||
| 1560 | *  | 
            ||
| 1561 | * @param array|\Countable $countable  | 
            ||
| 1562 | * @param int $count  | 
            ||
| 1563 | * @param string $message  | 
            ||
| 1564 | * @param string $propertyPath  | 
            ||
| 1565 | * @return void  | 
            ||
| 1566 | * @throws \Assert\AssertionFailedException  | 
            ||
| 1567 | */  | 
            ||
| 1568 | public static function count($countable, $count, $message = null, $propertyPath = null)  | 
            ||
| 1579 | |||
| 1580 | /**  | 
            ||
| 1581 | * static call handler to implement:  | 
            ||
| 1582 | * - "null or assertion" delegation  | 
            ||
| 1583 | * - "all" delegation  | 
            ||
| 1584 | */  | 
            ||
| 1585 | public static function __callStatic($method, $args)  | 
            ||
| 1621 | |||
| 1622 | /**  | 
            ||
| 1623 | * Determines if the values array has every choice as key and that this choice has content.  | 
            ||
| 1624 | *  | 
            ||
| 1625 | * @param array $values  | 
            ||
| 1626 | * @param array $choices  | 
            ||
| 1627 | * @param null $message  | 
            ||
| 1628 | * @param null $propertyPath  | 
            ||
| 1629 | */  | 
            ||
| 1630 | public static function choicesNotEmpty(array $values, array $choices, $message = null, $propertyPath = null)  | 
            ||
| 1639 | |||
| 1640 | /**  | 
            ||
| 1641 | * Determines that the named method is defined in the provided object.  | 
            ||
| 1642 | *  | 
            ||
| 1643 | * @param string $value  | 
            ||
| 1644 | * @param mixed $object  | 
            ||
| 1645 | * @param null $message  | 
            ||
| 1646 | * @param null $propertyPath  | 
            ||
| 1647 | *  | 
            ||
| 1648 | * @throws  | 
            ||
| 1649 | */  | 
            ||
| 1650 | public static function methodExists($value, $object, $message = null, $propertyPath = null)  | 
            ||
| 1663 | |||
| 1664 | /**  | 
            ||
| 1665 | * Determines that the provided value is an object.  | 
            ||
| 1666 | *  | 
            ||
| 1667 | * @param mixed $value  | 
            ||
| 1668 | * @param null $message  | 
            ||
| 1669 | * @param null $propertyPath  | 
            ||
| 1670 | */  | 
            ||
| 1671 | public static function isObject($value, $message = null, $propertyPath = null)  | 
            ||
| 1683 | |||
| 1684 | /**  | 
            ||
| 1685 | * Determines if the value is less than given limit.  | 
            ||
| 1686 | *  | 
            ||
| 1687 | * @param mixed $value  | 
            ||
| 1688 | * @param mixed $limit  | 
            ||
| 1689 | * @param null $message  | 
            ||
| 1690 | * @param null $propertyPath  | 
            ||
| 1691 | */  | 
            ||
| 1692 | public static function lessThan($value, $limit, $message = null, $propertyPath = null)  | 
            ||
| 1704 | |||
| 1705 | /**  | 
            ||
| 1706 | * Determines if the value is less or than given limit.  | 
            ||
| 1707 | *  | 
            ||
| 1708 | * @param mixed $value  | 
            ||
| 1709 | * @param mixed $limit  | 
            ||
| 1710 | * @param null $message  | 
            ||
| 1711 | * @param null $propertyPath  | 
            ||
| 1712 | */  | 
            ||
| 1713 | public static function lessOrEqualThan($value, $limit, $message = null, $propertyPath = null)  | 
            ||
| 1725 | |||
| 1726 | /**  | 
            ||
| 1727 | * Determines if the value is greater than given limit.  | 
            ||
| 1728 | *  | 
            ||
| 1729 | * @param mixed $value  | 
            ||
| 1730 | * @param mixed $limit  | 
            ||
| 1731 | * @param null $message  | 
            ||
| 1732 | * @param null $propertyPath  | 
            ||
| 1733 | */  | 
            ||
| 1734 | public static function greaterThan($value, $limit, $message = null, $propertyPath = null)  | 
            ||
| 1746 | |||
| 1747 | /**  | 
            ||
| 1748 | * Determines if the value is greater or equal than given limit.  | 
            ||
| 1749 | *  | 
            ||
| 1750 | * @param mixed $value  | 
            ||
| 1751 | * @param mixed $limit  | 
            ||
| 1752 | * @param null $message  | 
            ||
| 1753 | * @param null $propertyPath  | 
            ||
| 1754 | */  | 
            ||
| 1755 | public static function greaterOrEqualThan($value, $limit, $message = null, $propertyPath = null)  | 
            ||
| 1767 | |||
| 1768 | /**  | 
            ||
| 1769 | * Assert that date is valid and corresponds to the given format.  | 
            ||
| 1770 | *  | 
            ||
| 1771 | * @param string $value  | 
            ||
| 1772 | * @param string $format supports all of the options date(), except for the following:  | 
            ||
| 1773 | * N, w, W, t, L, o, B, a, A, g, h, I, O, P, Z, c, r.  | 
            ||
| 1774 | * @param string|null $message  | 
            ||
| 1775 | * @param string|null $propertyPath  | 
            ||
| 1776 | *  | 
            ||
| 1777 | * @link http://php.net/manual/function.date.php#refsect1-function.date-parameters  | 
            ||
| 1778 | */  | 
            ||
| 1779 | public static function date($value, $format, $message = null, $propertyPath = null)  | 
            ||
| 1796 | |||
| 1797 | /**  | 
            ||
| 1798 | * Determines that the provided value is callable.  | 
            ||
| 1799 | *  | 
            ||
| 1800 | * @param mixed $value  | 
            ||
| 1801 | * @param null $message  | 
            ||
| 1802 | * @param null $propertyPath  | 
            ||
| 1803 | */  | 
            ||
| 1804 | public static function isCallable($value, $message = null, $propertyPath = null)  | 
            ||
| 1815 | |||
| 1816 | /**  | 
            ||
| 1817 | * Assert that the provided value is valid according to a callback.  | 
            ||
| 1818 | *  | 
            ||
| 1819 | * If the callback returns `false` the assertion will fail.  | 
            ||
| 1820 | *  | 
            ||
| 1821 | * @param mixed $value  | 
            ||
| 1822 | * @param callable $callback  | 
            ||
| 1823 | * @param string|null $message  | 
            ||
| 1824 | * @param string|null $propertyPath  | 
            ||
| 1825 | */  | 
            ||
| 1826 | public static function satisfy($value, $callback, $message = null, $propertyPath = null)  | 
            ||
| 1839 | |||
| 1840 | /**  | 
            ||
| 1841 | * Assert that value is an IPv4 or IPv6 address  | 
            ||
| 1842 | * (using input_filter/FILTER_VALIDATE_IP).  | 
            ||
| 1843 | *  | 
            ||
| 1844 | * @param string $value  | 
            ||
| 1845 | * @param null|int $flag  | 
            ||
| 1846 | * @param string|null $message  | 
            ||
| 1847 | * @param string|null $propertyPath  | 
            ||
| 1848 | *  | 
            ||
| 1849 | * @link http://php.net/manual/filter.filters.flags.php  | 
            ||
| 1850 | */  | 
            ||
| 1851 | public static function ip($value, $flag = null, $message = null, $propertyPath = null)  | 
            ||
| 1862 | |||
| 1863 | /**  | 
            ||
| 1864 | * Assert that value is an IPv4 address  | 
            ||
| 1865 | * (using input_filter/FILTER_VALIDATE_IP).  | 
            ||
| 1866 | *  | 
            ||
| 1867 | * @param string $value  | 
            ||
| 1868 | * @param null|int $flag  | 
            ||
| 1869 | * @param string|null $message  | 
            ||
| 1870 | * @param string|null $propertyPath  | 
            ||
| 1871 | *  | 
            ||
| 1872 | * @link http://php.net/manual/filter.filters.flags.php  | 
            ||
| 1873 | */  | 
            ||
| 1874 | public static function ipv4($value, $flag = null, $message = null, $propertyPath = null)  | 
            ||
| 1878 | |||
| 1879 | /**  | 
            ||
| 1880 | * Assert that value is an IPv6 address  | 
            ||
| 1881 | * (using input_filter/FILTER_VALIDATE_IP).  | 
            ||
| 1882 | *  | 
            ||
| 1883 | * @param string $value  | 
            ||
| 1884 | * @param null|int $flag  | 
            ||
| 1885 | * @param string|null $message  | 
            ||
| 1886 | * @param string|null $propertyPath  | 
            ||
| 1887 | *  | 
            ||
| 1888 | * @link http://php.net/manual/filter.filters.flags.php  | 
            ||
| 1889 | */  | 
            ||
| 1890 | public static function ipv6($value, $flag = null, $message = null, $propertyPath = null)  | 
            ||
| 1894 | |||
| 1895 | /**  | 
            ||
| 1896 | * Make a string version of a value.  | 
            ||
| 1897 | *  | 
            ||
| 1898 | * @param mixed $value  | 
            ||
| 1899 | * @return string  | 
            ||
| 1900 | */  | 
            ||
| 1901 | protected static function stringify($value)  | 
            ||
| 1935 | }  | 
            ||
| 1936 |