Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Assert 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Assert, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 193 | class Assert |
||
|
|
|||
| 194 | { |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @psalm-assert string $value |
||
| 198 | * |
||
| 199 | * @param mixed $value |
||
| 200 | * @param string $message |
||
| 201 | * @param null $exception |
||
| 202 | * @throws Exception |
||
| 203 | */ |
||
| 204 | 151 | public static function string($value, $message = '', $exception = null) |
|
| 213 | |||
| 214 | /** |
||
| 215 | * @psalm-assert string $value |
||
| 216 | * |
||
| 217 | * @param mixed $value |
||
| 218 | * @param string $message |
||
| 219 | * @param null $exception |
||
| 220 | * @throws Exception |
||
| 221 | */ |
||
| 222 | 20 | public static function stringNotEmpty($value, $message = '', $exception = null) |
|
| 227 | |||
| 228 | /** |
||
| 229 | * @psalm-assert int $value |
||
| 230 | * |
||
| 231 | * @param mixed $value |
||
| 232 | * @param string $message |
||
| 233 | * @param null $exception |
||
| 234 | * @throws Exception |
||
| 235 | */ |
||
| 236 | 21 | public static function integer($value, $message = '', $exception = null) |
|
| 245 | |||
| 246 | /** |
||
| 247 | * @psalm-assert numeric $value |
||
| 248 | * |
||
| 249 | * @param mixed $value |
||
| 250 | * @param string $message |
||
| 251 | */ |
||
| 252 | 20 | public static function integerish($value, $message = '', $exception = null) |
|
| 261 | |||
| 262 | /** |
||
| 263 | * @psalm-assert float $value |
||
| 264 | * |
||
| 265 | * @param mixed $value |
||
| 266 | * @param string $message |
||
| 267 | * @param null $exception |
||
| 268 | * @throws Exception |
||
| 269 | */ |
||
| 270 | 20 | public static function float($value, $message = '', $exception = null) |
|
| 279 | |||
| 280 | /** |
||
| 281 | * @psalm-assert numeric $value |
||
| 282 | * |
||
| 283 | * @param mixed $value |
||
| 284 | * @param string $message |
||
| 285 | * @param null $exception |
||
| 286 | * @throws Exception |
||
| 287 | */ |
||
| 288 | 25 | public static function numeric($value, $message = '', $exception = null) |
|
| 297 | |||
| 298 | /** |
||
| 299 | * @psalm-assert int $value |
||
| 300 | * |
||
| 301 | * @param mixed $value |
||
| 302 | * @param string $message |
||
| 303 | * @param null $exception |
||
| 304 | * @throws Exception |
||
| 305 | */ |
||
| 306 | 30 | public static function natural($value, $message = '', $exception = null) |
|
| 315 | |||
| 316 | /** |
||
| 317 | * @psalm-assert bool $value |
||
| 318 | * |
||
| 319 | * @param mixed $value |
||
| 320 | * @param string $message |
||
| 321 | * @param null $exception |
||
| 322 | * @throws Exception |
||
| 323 | */ |
||
| 324 | 20 | public static function boolean($value, $message = '', $exception = null) |
|
| 333 | |||
| 334 | /** |
||
| 335 | * @psalm-assert scalar $value |
||
| 336 | * |
||
| 337 | * @param mixed $value |
||
| 338 | * @param string $message |
||
| 339 | * @param null $exception |
||
| 340 | * @throws Exception |
||
| 341 | */ |
||
| 342 | 29 | public static function scalar($value, $message = '', $exception = null) |
|
| 351 | |||
| 352 | /** |
||
| 353 | * @psalm-assert object $value |
||
| 354 | * |
||
| 355 | * @param mixed $value |
||
| 356 | * @param string $message |
||
| 357 | * @param null $exception |
||
| 358 | * @throws Exception |
||
| 359 | */ |
||
| 360 | 29 | public static function object($value, $message = '', $exception = null) |
|
| 369 | |||
| 370 | /** |
||
| 371 | * @psalm-assert resource $value |
||
| 372 | * |
||
| 373 | * @param mixed $value |
||
| 374 | * @param string|null $type type of resource this should be. @see https://www.php.net/manual/en/function.get-resource-type.php |
||
| 375 | * @param string $message |
||
| 376 | * @param null $exception |
||
| 377 | * @throws Exception |
||
| 378 | */ |
||
| 379 | 20 | public static function resource($value, $type = null, $message = '', $exception = null) |
|
| 396 | |||
| 397 | /** |
||
| 398 | * @psalm-assert callable $value |
||
| 399 | * |
||
| 400 | * @param mixed $value |
||
| 401 | * @param string $message |
||
| 402 | * @param null $exception |
||
| 403 | * @throws Exception |
||
| 404 | */ |
||
| 405 | 25 | public static function isCallable($value, $message = '', $exception = null) |
|
| 414 | |||
| 415 | /** |
||
| 416 | * @psalm-assert array $value |
||
| 417 | * |
||
| 418 | * @param mixed $value |
||
| 419 | * @param string $message |
||
| 420 | * @param null $exception |
||
| 421 | * @throws Exception |
||
| 422 | */ |
||
| 423 | 25 | public static function isArray($value, $message = '', $exception = null) |
|
| 432 | |||
| 433 | /** |
||
| 434 | * @psalm-assert iterable $value |
||
| 435 | * |
||
| 436 | * @param mixed $value |
||
| 437 | * @param string $message |
||
| 438 | * @param null $exception |
||
| 439 | * @throws Exception |
||
| 440 | * @deprecated use "isIterable" or "isInstanceOf" instead |
||
| 441 | * |
||
| 442 | */ |
||
| 443 | 25 | public static function isTraversable($value, $message = '', $exception = null) |
|
| 460 | |||
| 461 | /** |
||
| 462 | * @param mixed $value |
||
| 463 | * @param string $message |
||
| 464 | * @param null $exception |
||
| 465 | * @throws Exception |
||
| 466 | */ |
||
| 467 | 25 | View Code Duplication | public static function isArrayAccessible($value, $message = '', $exception = null) |
| 476 | |||
| 477 | /** |
||
| 478 | * @psalm-assert countable $value |
||
| 479 | * |
||
| 480 | * @param mixed $value |
||
| 481 | * @param string $message |
||
| 482 | * @param null $exception |
||
| 483 | * @throws Exception |
||
| 484 | */ |
||
| 485 | 30 | View Code Duplication | public static function isCountable($value, $message = '', $exception = null) |
| 494 | |||
| 495 | /** |
||
| 496 | * @psalm-assert iterable $value |
||
| 497 | * |
||
| 498 | * @param mixed $value |
||
| 499 | * @param string $message |
||
| 500 | * @param null $exception |
||
| 501 | * @throws Exception |
||
| 502 | */ |
||
| 503 | 883 | View Code Duplication | public static function isIterable($value, $message = '', $exception = null) |
| 512 | |||
| 513 | /** |
||
| 514 | * @psalm-template ExpectedType of object |
||
| 515 | * @psalm-param class-string<ExpectedType> $class |
||
| 516 | * @psalm-assert ExpectedType $value |
||
| 517 | * |
||
| 518 | * @param mixed $value |
||
| 519 | * @param string|object $class |
||
| 520 | * @param string $message |
||
| 521 | * @param null $exception |
||
| 522 | * @throws Exception |
||
| 523 | */ |
||
| 524 | 20 | public static function isInstanceOf($value, $class, $message = '', $exception = null) |
|
| 534 | |||
| 535 | /** |
||
| 536 | * @psalm-template ExpectedType of object |
||
| 537 | * @psalm-param class-string<ExpectedType> $class |
||
| 538 | * @psalm-assert !ExpectedType $value |
||
| 539 | * |
||
| 540 | * @param mixed $value |
||
| 541 | * @param string|object $class |
||
| 542 | * @param string $message |
||
| 543 | * @param null $exception |
||
| 544 | * @throws Exception |
||
| 545 | */ |
||
| 546 | 20 | public static function notInstanceOf($value, $class, $message = '', $exception = null) |
|
| 556 | |||
| 557 | /** |
||
| 558 | * @param mixed $value |
||
| 559 | * @param array<object|string> $classes |
||
| 560 | * @param string $message |
||
| 561 | * @param null $exception |
||
| 562 | * @throws Exception |
||
| 563 | */ |
||
| 564 | 25 | public static function isInstanceOfAny($value, array $classes, $message = '', $exception = null) |
|
| 578 | |||
| 579 | /** |
||
| 580 | * @psalm-assert empty $value |
||
| 581 | * |
||
| 582 | * @param mixed $value |
||
| 583 | * @param string $message |
||
| 584 | * @param null $exception |
||
| 585 | * @throws Exception |
||
| 586 | */ |
||
| 587 | 29 | public static function isEmpty($value, $message = '', $exception = null) |
|
| 596 | |||
| 597 | /** |
||
| 598 | * @psalm-assert !empty $value |
||
| 599 | * |
||
| 600 | * @param mixed $value |
||
| 601 | * @param string $message |
||
| 602 | * @param null $exception |
||
| 603 | * @throws Exception |
||
| 604 | */ |
||
| 605 | 29 | public static function notEmpty($value, $message = '', $exception = null) |
|
| 614 | |||
| 615 | /** |
||
| 616 | * @psalm-assert null $value |
||
| 617 | * |
||
| 618 | * @param mixed $value |
||
| 619 | * @param string $message |
||
| 620 | * @param null $exception |
||
| 621 | * @throws Exception |
||
| 622 | */ |
||
| 623 | 14 | public static function null($value, $message = '', $exception = null) |
|
| 632 | |||
| 633 | /** |
||
| 634 | * @psalm-assert !null $value |
||
| 635 | * |
||
| 636 | * @param mixed $value |
||
| 637 | * @param string $message |
||
| 638 | * @param null $exception |
||
| 639 | * @throws Exception |
||
| 640 | */ |
||
| 641 | 14 | public static function notNull($value, $message = '', $exception = null) |
|
| 650 | |||
| 651 | /** |
||
| 652 | * @psalm-assert true $value |
||
| 653 | * |
||
| 654 | * @param mixed $value |
||
| 655 | * @param string $message |
||
| 656 | * @param null $exception |
||
| 657 | * @throws Exception |
||
| 658 | */ |
||
| 659 | 19 | public static function true($value, $message = '', $exception = null) |
|
| 668 | |||
| 669 | /** |
||
| 670 | * @psalm-assert false $value |
||
| 671 | * |
||
| 672 | * @param mixed $value |
||
| 673 | * @param string $message |
||
| 674 | * @param null $exception |
||
| 675 | * @throws Exception |
||
| 676 | */ |
||
| 677 | 24 | public static function false($value, $message = '', $exception = null) |
|
| 686 | |||
| 687 | /** |
||
| 688 | * @param mixed $value |
||
| 689 | * @param string $message |
||
| 690 | * @param null $exception |
||
| 691 | * @throws Exception |
||
| 692 | */ |
||
| 693 | 59 | public static function ip($value, $message = '', $exception = null) |
|
| 702 | |||
| 703 | /** |
||
| 704 | * @param mixed $value |
||
| 705 | * @param string $message |
||
| 706 | * @param null $exception |
||
| 707 | * @throws Exception |
||
| 708 | */ |
||
| 709 | 59 | public static function ipv4($value, $message = '', $exception = null) |
|
| 718 | |||
| 719 | /** |
||
| 720 | * @param mixed $value |
||
| 721 | * @param string $message |
||
| 722 | * @param null $exception |
||
| 723 | * @throws Exception |
||
| 724 | */ |
||
| 725 | 59 | public static function ipv6($value, $message = '', $exception = null) |
|
| 734 | |||
| 735 | /** |
||
| 736 | * @param mixed $value |
||
| 737 | * @param string $message |
||
| 738 | * @param null $exception |
||
| 739 | * @throws Exception |
||
| 740 | */ |
||
| 741 | 20 | public static function email($value, $message = '', $exception = null) |
|
| 750 | |||
| 751 | /** |
||
| 752 | * Does non strict comparisons on the items, so ['3', 3] will not pass the assertion. |
||
| 753 | * |
||
| 754 | * @param array $values |
||
| 755 | * @param string $message |
||
| 756 | * @param null $exception |
||
| 757 | * @throws Exception |
||
| 758 | */ |
||
| 759 | 15 | public static function uniqueValues(array $values, $message = '', $exception = null) |
|
| 774 | |||
| 775 | /** |
||
| 776 | * @param mixed $value |
||
| 777 | * @param mixed $expect |
||
| 778 | * @param string $message |
||
| 779 | * @param null $exception |
||
| 780 | * @throws Exception |
||
| 781 | */ |
||
| 782 | 39 | View Code Duplication | public static function eq($value, $expect, $message = '', $exception = null) |
| 792 | |||
| 793 | /** |
||
| 794 | * @param mixed $value |
||
| 795 | * @param mixed $expect |
||
| 796 | * @param string $message |
||
| 797 | * @param null $exception |
||
| 798 | * @throws Exception |
||
| 799 | */ |
||
| 800 | 35 | public static function notEq($value, $expect, $message = '', $exception = null) |
|
| 809 | |||
| 810 | /** |
||
| 811 | * @psalm-template ExpectedType |
||
| 812 | * @psalm-param ExpectedType $expect |
||
| 813 | * @psalm-assert =ExpectedType $value |
||
| 814 | * |
||
| 815 | * @param mixed $value |
||
| 816 | * @param mixed $expect |
||
| 817 | * @param string $message |
||
| 818 | * @param null $exception |
||
| 819 | * @throws Exception |
||
| 820 | */ |
||
| 821 | 20 | View Code Duplication | public static function same($value, $expect, $message = '', $exception = null) |
| 831 | |||
| 832 | /** |
||
| 833 | * @param mixed $value |
||
| 834 | * @param mixed $expect |
||
| 835 | * @param string $message |
||
| 836 | * @param null $exception |
||
| 837 | * @throws Exception |
||
| 838 | */ |
||
| 839 | 20 | public static function notSame($value, $expect, $message = '', $exception = null) |
|
| 848 | |||
| 849 | /** |
||
| 850 | * @param mixed $value |
||
| 851 | * @param mixed $limit |
||
| 852 | * @param string $message |
||
| 853 | * @param null $exception |
||
| 854 | * @throws Exception |
||
| 855 | */ |
||
| 856 | 10 | View Code Duplication | public static function greaterThan($value, $limit, $message = '', $exception = null) |
| 866 | |||
| 867 | /** |
||
| 868 | * @param mixed $value |
||
| 869 | * @param mixed $limit |
||
| 870 | * @param string $message |
||
| 871 | * @param null $exception |
||
| 872 | * @throws Exception |
||
| 873 | */ |
||
| 874 | 15 | View Code Duplication | public static function greaterThanEq($value, $limit, $message = '', $exception = null) |
| 884 | |||
| 885 | /** |
||
| 886 | * @param mixed $value |
||
| 887 | * @param mixed $limit |
||
| 888 | * @param string $message |
||
| 889 | * @param null $exception |
||
| 890 | * @throws Exception |
||
| 891 | */ |
||
| 892 | 10 | View Code Duplication | public static function lessThan($value, $limit, $message = '', $exception = null) |
| 902 | |||
| 903 | /** |
||
| 904 | * @param mixed $value |
||
| 905 | * @param mixed $limit |
||
| 906 | * @param string $message |
||
| 907 | * @param null $exception |
||
| 908 | * @throws Exception |
||
| 909 | */ |
||
| 910 | 15 | View Code Duplication | public static function lessThanEq($value, $limit, $message = '', $exception = null) |
| 920 | |||
| 921 | /** |
||
| 922 | * Inclusive range, so Assert::(3, 3, 5) passes. |
||
| 923 | * |
||
| 924 | * @param mixed $value |
||
| 925 | * @param $min |
||
| 926 | * @param $max |
||
| 927 | * @param string $message |
||
| 928 | * @param null $exception |
||
| 929 | * @throws Exception |
||
| 930 | */ |
||
| 931 | 20 | public static function range($value, $min, $max, $message = '', $exception = null) |
|
| 942 | |||
| 943 | /** |
||
| 944 | * Does strict comparison, so Assert::oneOf(3, ['3']) does not pass the assertion. |
||
| 945 | * |
||
| 946 | * @psalm-template ExpectedType |
||
| 947 | * @psalm-param array<ExpectedType> $values |
||
| 948 | * @psalm-assert ExpectedType $value |
||
| 949 | * |
||
| 950 | * @param mixed $value |
||
| 951 | * @param array $values |
||
| 952 | * @param string $message |
||
| 953 | * @param null $exception |
||
| 954 | * @throws Exception |
||
| 955 | */ |
||
| 956 | 10 | public static function oneOf($value, array $values, $message = '', $exception = null) |
|
| 966 | |||
| 967 | /** |
||
| 968 | * @param mixed $value |
||
| 969 | * @param string $subString |
||
| 970 | * @param string $message |
||
| 971 | * @param null $exception |
||
| 972 | * @throws Exception |
||
| 973 | */ |
||
| 974 | 100 | View Code Duplication | public static function contains($value, $subString, $message = '', $exception = null) |
| 984 | |||
| 985 | /** |
||
| 986 | * @param mixed $value |
||
| 987 | * @param string $subString |
||
| 988 | * @param string $message |
||
| 989 | * @param null $exception |
||
| 990 | * @throws Exception |
||
| 991 | */ |
||
| 992 | 100 | View Code Duplication | public static function notContains($value, $subString, $message = '', $exception = null) |
| 1002 | |||
| 1003 | /** |
||
| 1004 | * @param mixed $value |
||
| 1005 | * @param string $message |
||
| 1006 | * @param null $exception |
||
| 1007 | * @throws Exception |
||
| 1008 | */ |
||
| 1009 | 50 | public static function notWhitespaceOnly($value, $message = '', $exception = null) |
|
| 1018 | |||
| 1019 | /** |
||
| 1020 | * @param mixed $value |
||
| 1021 | * @param string $prefix |
||
| 1022 | * @param string $message |
||
| 1023 | * @param null $exception |
||
| 1024 | * @throws Exception |
||
| 1025 | */ |
||
| 1026 | 60 | View Code Duplication | public static function startsWith($value, $prefix, $message = '', $exception = null) |
| 1036 | |||
| 1037 | /** |
||
| 1038 | * @param mixed $value |
||
| 1039 | * @param string $message |
||
| 1040 | * @param null $exception |
||
| 1041 | * @throws Exception |
||
| 1042 | */ |
||
| 1043 | 30 | public static function startsWithLetter($value, $message = '', $exception = null) |
|
| 1061 | |||
| 1062 | /** |
||
| 1063 | * @param mixed $value |
||
| 1064 | * @param string $suffix |
||
| 1065 | * @param string $message |
||
| 1066 | * @param null $exception |
||
| 1067 | * @throws Exception |
||
| 1068 | */ |
||
| 1069 | 60 | public static function endsWith($value, $suffix, $message = '', $exception = null) |
|
| 1079 | |||
| 1080 | /** |
||
| 1081 | * @param mixed $value |
||
| 1082 | * @param mixed $pattern |
||
| 1083 | * @param string $message |
||
| 1084 | * @param null $exception |
||
| 1085 | * @throws Exception |
||
| 1086 | */ |
||
| 1087 | 15 | public static function regex($value, $pattern, $message = '', $exception = null) |
|
| 1096 | |||
| 1097 | /** |
||
| 1098 | * @param mixed $value |
||
| 1099 | * @param mixed $pattern |
||
| 1100 | * @param string $message |
||
| 1101 | * @param null $exception |
||
| 1102 | * @throws Exception |
||
| 1103 | */ |
||
| 1104 | 15 | public static function notRegex($value, $pattern, $message = '', $exception = null) |
|
| 1115 | |||
| 1116 | /** |
||
| 1117 | * @psalm-assert !numeric $value |
||
| 1118 | * |
||
| 1119 | * @param mixed $value |
||
| 1120 | * @param string $message |
||
| 1121 | * @param null $exception |
||
| 1122 | * @throws Exception |
||
| 1123 | */ |
||
| 1124 | 35 | public static function unicodeLetters($value, $message = '', $exception = null) |
|
| 1135 | |||
| 1136 | /** |
||
| 1137 | * @param mixed $value |
||
| 1138 | * @param string $message |
||
| 1139 | * @param null $exception |
||
| 1140 | * @throws Exception |
||
| 1141 | */ |
||
| 1142 | 15 | View Code Duplication | public static function alpha($value, $message = '', $exception = null) |
| 1156 | |||
| 1157 | /** |
||
| 1158 | * @param mixed $value |
||
| 1159 | * @param string $message |
||
| 1160 | * @param null $exception |
||
| 1161 | * @throws Exception |
||
| 1162 | */ |
||
| 1163 | 15 | View Code Duplication | public static function digits($value, $message = '', $exception = null) |
| 1177 | |||
| 1178 | /** |
||
| 1179 | * @param mixed $value |
||
| 1180 | * @param string $message |
||
| 1181 | * @param null $exception |
||
| 1182 | * @throws Exception |
||
| 1183 | */ |
||
| 1184 | 15 | View Code Duplication | public static function alnum($value, $message = '', $exception = null) |
| 1198 | |||
| 1199 | /** |
||
| 1200 | * @param mixed $value |
||
| 1201 | * @param string $message |
||
| 1202 | * @param null $exception |
||
| 1203 | * @throws Exception |
||
| 1204 | */ |
||
| 1205 | 20 | View Code Duplication | public static function lower($value, $message = '', $exception = null) |
| 1219 | |||
| 1220 | /** |
||
| 1221 | * @param mixed $value |
||
| 1222 | * @param string $message |
||
| 1223 | * @param null $exception |
||
| 1224 | * @throws Exception |
||
| 1225 | */ |
||
| 1226 | 20 | View Code Duplication | public static function upper($value, $message = '', $exception = null) |
| 1240 | |||
| 1241 | /** |
||
| 1242 | * @param mixed $value |
||
| 1243 | * @param mixed $length |
||
| 1244 | * @param string $message |
||
| 1245 | * @param null $exception |
||
| 1246 | * @throws Exception |
||
| 1247 | */ |
||
| 1248 | 45 | View Code Duplication | public static function length($value, $length, $message = '', $exception = null) |
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Inclusive min. |
||
| 1261 | * |
||
| 1262 | * @param mixed $value |
||
| 1263 | * @param mixed $min |
||
| 1264 | * @param string $message |
||
| 1265 | * @param null $exception |
||
| 1266 | * @throws Exception |
||
| 1267 | */ |
||
| 1268 | 45 | View Code Duplication | public static function minLength($value, $min, $message = '', $exception = null) |
| 1278 | |||
| 1279 | /** |
||
| 1280 | * Inclusive max. |
||
| 1281 | * |
||
| 1282 | * @param mixed $value |
||
| 1283 | * @param mixed $max |
||
| 1284 | * @param string $message |
||
| 1285 | * @param null $exception |
||
| 1286 | * @throws Exception |
||
| 1287 | */ |
||
| 1288 | 45 | View Code Duplication | public static function maxLength($value, $max, $message = '', $exception = null) |
| 1298 | |||
| 1299 | /** |
||
| 1300 | * Inclusive , so Assert::lengthBetween('asd', 3, 5); passes the assertion. |
||
| 1301 | * |
||
| 1302 | * @param mixed $value |
||
| 1303 | * @param mixed $min |
||
| 1304 | * @param mixed $max |
||
| 1305 | * @param string $message |
||
| 1306 | * @param null $exception |
||
| 1307 | * @throws Exception |
||
| 1308 | */ |
||
| 1309 | 75 | View Code Duplication | public static function lengthBetween($value, $min, $max, $message = '', $exception = null) |
| 1322 | |||
| 1323 | /** |
||
| 1324 | * Will also pass if $value is a directory, use Assert::file() instead if you need to be sure it is a file. |
||
| 1325 | * |
||
| 1326 | * @param mixed $value |
||
| 1327 | * @param string $message |
||
| 1328 | * @param null $exception |
||
| 1329 | * @throws Exception |
||
| 1330 | */ |
||
| 1331 | 45 | View Code Duplication | public static function fileExists($value, $message = '', $exception = null) |
| 1342 | |||
| 1343 | /** |
||
| 1344 | * @param mixed $value |
||
| 1345 | * @param string $message |
||
| 1346 | * @param null $exception |
||
| 1347 | * @throws Exception |
||
| 1348 | */ |
||
| 1349 | 15 | View Code Duplication | public static function file($value, $message = '', $exception = null) |
| 1360 | |||
| 1361 | /** |
||
| 1362 | * @param mixed $value |
||
| 1363 | * @param string $message |
||
| 1364 | * @param null $exception |
||
| 1365 | * @throws Exception |
||
| 1366 | */ |
||
| 1367 | 15 | View Code Duplication | public static function directory($value, $message = '', $exception = null) |
| 1378 | |||
| 1379 | /** |
||
| 1380 | * @param mixed $value |
||
| 1381 | * @param string $message |
||
| 1382 | * @param null $exception |
||
| 1383 | * @throws Exception |
||
| 1384 | */ |
||
| 1385 | public static function readable($value, $message = '', $exception = null) |
||
| 1394 | |||
| 1395 | /** |
||
| 1396 | * @param mixed $value |
||
| 1397 | * @param string $message |
||
| 1398 | * @param null $exception |
||
| 1399 | * @throws Exception |
||
| 1400 | */ |
||
| 1401 | public static function writable($value, $message = '', $exception = null) |
||
| 1410 | |||
| 1411 | /** |
||
| 1412 | * @psalm-assert class-string $value |
||
| 1413 | * |
||
| 1414 | * @param mixed $value |
||
| 1415 | * @param string $message |
||
| 1416 | * @param null $exception |
||
| 1417 | * @throws Exception |
||
| 1418 | */ |
||
| 1419 | 10 | public static function classExists($value, $message = '', $exception = null) |
|
| 1428 | |||
| 1429 | /** |
||
| 1430 | * @param mixed $value |
||
| 1431 | * @param string|object $class |
||
| 1432 | * @param string $message |
||
| 1433 | * @param null $exception |
||
| 1434 | * @throws Exception |
||
| 1435 | */ |
||
| 1436 | 10 | View Code Duplication | public static function subclassOf($value, $class, $message = '', $exception = null) |
| 1446 | |||
| 1447 | /** |
||
| 1448 | * @psalm-assert class-string $value |
||
| 1449 | * |
||
| 1450 | * @param mixed $value |
||
| 1451 | * @param string $message |
||
| 1452 | * @param null $exception |
||
| 1453 | * @throws Exception |
||
| 1454 | */ |
||
| 1455 | 10 | public static function interfaceExists($value, $message = '', $exception = null) |
|
| 1464 | |||
| 1465 | /** |
||
| 1466 | * @param mixed $value |
||
| 1467 | * @param mixed $interface |
||
| 1468 | * @param string $message |
||
| 1469 | * @param null $exception |
||
| 1470 | * @throws Exception |
||
| 1471 | */ |
||
| 1472 | 10 | public static function implementsInterface($value, $interface, $message = '', $exception = null) |
|
| 1482 | |||
| 1483 | /** |
||
| 1484 | * @param string|object $classOrObject |
||
| 1485 | * @param mixed $property |
||
| 1486 | * @param string $message |
||
| 1487 | * @param null $exception |
||
| 1488 | * @throws Exception |
||
| 1489 | */ |
||
| 1490 | 15 | View Code Duplication | public static function propertyExists($classOrObject, $property, $message = '', $exception = null) |
| 1499 | |||
| 1500 | /** |
||
| 1501 | * @param string|object $classOrObject |
||
| 1502 | * @param mixed $property |
||
| 1503 | * @param string $message |
||
| 1504 | * @param null $exception |
||
| 1505 | * @throws Exception |
||
| 1506 | */ |
||
| 1507 | 15 | View Code Duplication | public static function propertyNotExists($classOrObject, $property, $message = '', $exception = null) |
| 1516 | |||
| 1517 | /** |
||
| 1518 | * @param string|object $classOrObject |
||
| 1519 | * @param mixed $method |
||
| 1520 | * @param string $message |
||
| 1521 | * @param null $exception |
||
| 1522 | * @throws Exception |
||
| 1523 | */ |
||
| 1524 | 34 | View Code Duplication | public static function methodExists($classOrObject, $method, $message = '', $exception = null) |
| 1533 | |||
| 1534 | /** |
||
| 1535 | * @param string|object $classOrObject |
||
| 1536 | * @param mixed $method |
||
| 1537 | * @param string $message |
||
| 1538 | * @param null $exception |
||
| 1539 | * @throws Exception |
||
| 1540 | */ |
||
| 1541 | 34 | View Code Duplication | public static function methodNotExists($classOrObject, $method, $message = '', $exception = null) |
| 1550 | |||
| 1551 | /** |
||
| 1552 | * @param array $array |
||
| 1553 | * @param string|int $key |
||
| 1554 | * @param string $message |
||
| 1555 | * @param null $exception |
||
| 1556 | * @throws Exception |
||
| 1557 | */ |
||
| 1558 | 15 | View Code Duplication | public static function keyExists($array, $key, $message = '', $exception = null) |
| 1567 | |||
| 1568 | /** |
||
| 1569 | * @param array $array |
||
| 1570 | * @param string|int $key |
||
| 1571 | * @param string $message |
||
| 1572 | * @param null $exception |
||
| 1573 | * @throws Exception |
||
| 1574 | */ |
||
| 1575 | 15 | View Code Duplication | public static function keyNotExists($array, $key, $message = '', $exception = null) |
| 1584 | |||
| 1585 | /** |
||
| 1586 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1587 | * |
||
| 1588 | * @param mixed $array |
||
| 1589 | * @param mixed $number |
||
| 1590 | * @param string $message |
||
| 1591 | * @param null $exception |
||
| 1592 | * @throws Exception |
||
| 1593 | */ |
||
| 1594 | 10 | public static function count($array, $number, $message = '', $exception = null) |
|
| 1603 | |||
| 1604 | /** |
||
| 1605 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1606 | * |
||
| 1607 | * @param mixed $array |
||
| 1608 | * @param mixed $min |
||
| 1609 | * @param string $message |
||
| 1610 | * @param null $exception |
||
| 1611 | * @throws Exception |
||
| 1612 | */ |
||
| 1613 | 15 | public static function minCount($array, $min, $message = '', $exception = null) |
|
| 1623 | |||
| 1624 | /** |
||
| 1625 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1626 | * |
||
| 1627 | * @param mixed $array |
||
| 1628 | * @param mixed $max |
||
| 1629 | * @param string $message |
||
| 1630 | * @param null $exception |
||
| 1631 | * @throws Exception |
||
| 1632 | */ |
||
| 1633 | 15 | public static function maxCount($array, $max, $message = '', $exception = null) |
|
| 1643 | |||
| 1644 | /** |
||
| 1645 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1646 | * |
||
| 1647 | * @param mixed $array |
||
| 1648 | * @param mixed $min |
||
| 1649 | * @param mixed $max |
||
| 1650 | * @param string $message |
||
| 1651 | * @param null $exception |
||
| 1652 | * @throws Exception |
||
| 1653 | */ |
||
| 1654 | 25 | View Code Duplication | public static function countBetween($array, $min, $max, $message = '', $exception = null) |
| 1667 | |||
| 1668 | /** |
||
| 1669 | * @param mixed $array |
||
| 1670 | * @param string $message |
||
| 1671 | * @param null $exception |
||
| 1672 | * @throws Exception |
||
| 1673 | */ |
||
| 1674 | 30 | public static function isList($array, $message = '', $exception = null) |
|
| 1683 | |||
| 1684 | /** |
||
| 1685 | * @param mixed $array |
||
| 1686 | * @param string $message |
||
| 1687 | * @param null $exception |
||
| 1688 | * @throws Exception |
||
| 1689 | */ |
||
| 1690 | 20 | public static function isMap($array, $message = '', $exception = null) |
|
| 1705 | |||
| 1706 | /** |
||
| 1707 | * @param mixed $value |
||
| 1708 | * @param string $message |
||
| 1709 | * @param null $exception |
||
| 1710 | * @throws Exception |
||
| 1711 | */ |
||
| 1712 | 70 | public static function uuid($value, $message = '', $exception = null) |
|
| 1729 | |||
| 1730 | /** |
||
| 1731 | * @param Closure $expression |
||
| 1732 | * @param string|object $class |
||
| 1733 | * @param string $message |
||
| 1734 | * @param null $exception |
||
| 1735 | * @throws Exception |
||
| 1736 | */ |
||
| 1737 | 30 | public static function throws(Closure $expression, $class = 'Exception', $message = '', $exception = null) |
|
| 1763 | |||
| 1764 | 1383 | public static function __callStatic($name, $arguments) |
|
| 1792 | |||
| 1793 | /** |
||
| 1794 | * @param mixed $value |
||
| 1795 | * |
||
| 1796 | * @return string |
||
| 1797 | */ |
||
| 1798 | 867 | protected static function valueToString($value) |
|
| 1834 | |||
| 1835 | /** |
||
| 1836 | * @param mixed $value |
||
| 1837 | * |
||
| 1838 | * @return string |
||
| 1839 | */ |
||
| 1840 | 210 | protected static function typeToString($value) |
|
| 1844 | |||
| 1845 | 210 | protected static function strlen($value) |
|
| 1857 | |||
| 1858 | 1146 | private static function throwException($message, $exception = null) |
|
| 1868 | |||
| 1869 | /** |
||
| 1870 | * @param string $message |
||
| 1871 | */ |
||
| 1872 | 918 | protected static function reportInvalidArgument($message) |
|
| 1876 | |||
| 1877 | private function __construct() |
||
| 1880 | } |
||
| 1881 |