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 |
||
| 199 | class Assert |
||
|
|
|||
| 200 | { |
||
| 201 | /** |
||
| 202 | * @psalm-assert string $value |
||
| 203 | * |
||
| 204 | * @param mixed $value |
||
| 205 | * @param string $message |
||
| 206 | */ |
||
| 207 | 186 | public static function string($value, $message = '') |
|
| 208 | { |
||
| 209 | 186 | if (!\is_string($value)) { |
|
| 210 | 26 | static::reportInvalidArgument(\sprintf( |
|
| 211 | 26 | $message ?: 'Expected a string. Got: %s', |
|
| 212 | 26 | static::typeToString($value) |
|
| 213 | )); |
||
| 214 | } |
||
| 215 | 160 | } |
|
| 216 | |||
| 217 | /** |
||
| 218 | * @psalm-assert string $value |
||
| 219 | * |
||
| 220 | * @param mixed $value |
||
| 221 | * @param string $message |
||
| 222 | */ |
||
| 223 | 16 | public static function stringNotEmpty($value, $message = '') |
|
| 224 | { |
||
| 225 | 16 | static::string($value, $message); |
|
| 226 | 12 | static::notEq($value, '', $message); |
|
| 227 | 8 | } |
|
| 228 | |||
| 229 | /** |
||
| 230 | * @psalm-assert int $value |
||
| 231 | * |
||
| 232 | * @param mixed $value |
||
| 233 | * @param string $message |
||
| 234 | */ |
||
| 235 | 17 | public static function integer($value, $message = '') |
|
| 236 | { |
||
| 237 | 17 | if (!\is_int($value)) { |
|
| 238 | 13 | static::reportInvalidArgument(\sprintf( |
|
| 239 | 13 | $message ?: 'Expected an integer. Got: %s', |
|
| 240 | 13 | static::typeToString($value) |
|
| 241 | )); |
||
| 242 | } |
||
| 243 | 4 | } |
|
| 244 | |||
| 245 | /** |
||
| 246 | * @psalm-assert numeric $value |
||
| 247 | * |
||
| 248 | * @param mixed $value |
||
| 249 | * @param string $message |
||
| 250 | */ |
||
| 251 | 16 | public static function integerish($value, $message = '') |
|
| 252 | { |
||
| 253 | 16 | if (!\is_numeric($value) || $value != (int) $value) { |
|
| 254 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 255 | 4 | $message ?: 'Expected an integerish value. Got: %s', |
|
| 256 | 4 | static::typeToString($value) |
|
| 257 | )); |
||
| 258 | } |
||
| 259 | 12 | } |
|
| 260 | |||
| 261 | /** |
||
| 262 | * @psalm-assert float $value |
||
| 263 | * |
||
| 264 | * @param mixed $value |
||
| 265 | * @param string $message |
||
| 266 | */ |
||
| 267 | 16 | public static function float($value, $message = '') |
|
| 268 | { |
||
| 269 | 16 | if (!\is_float($value)) { |
|
| 270 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 271 | 8 | $message ?: 'Expected a float. Got: %s', |
|
| 272 | 8 | static::typeToString($value) |
|
| 273 | )); |
||
| 274 | } |
||
| 275 | 8 | } |
|
| 276 | |||
| 277 | /** |
||
| 278 | * @psalm-assert numeric $value |
||
| 279 | * |
||
| 280 | * @param mixed $value |
||
| 281 | * @param string $message |
||
| 282 | */ |
||
| 283 | 20 | public static function numeric($value, $message = '') |
|
| 284 | { |
||
| 285 | 20 | if (!\is_numeric($value)) { |
|
| 286 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 287 | 4 | $message ?: 'Expected a numeric. Got: %s', |
|
| 288 | 4 | static::typeToString($value) |
|
| 289 | )); |
||
| 290 | } |
||
| 291 | 16 | } |
|
| 292 | |||
| 293 | /** |
||
| 294 | * @psalm-assert int $value |
||
| 295 | * |
||
| 296 | * @param mixed $value |
||
| 297 | * @param string $message |
||
| 298 | */ |
||
| 299 | 24 | public static function natural($value, $message = '') |
|
| 300 | { |
||
| 301 | 24 | if (!\is_int($value) || $value < 0) { |
|
| 302 | 16 | static::reportInvalidArgument(\sprintf( |
|
| 303 | 16 | $message ?: 'Expected a non-negative integer. Got %s', |
|
| 304 | 16 | static::valueToString($value) |
|
| 305 | )); |
||
| 306 | } |
||
| 307 | 8 | } |
|
| 308 | |||
| 309 | /** |
||
| 310 | * @psalm-assert bool $value |
||
| 311 | * |
||
| 312 | * @param mixed $value |
||
| 313 | * @param string $message |
||
| 314 | */ |
||
| 315 | 16 | public static function boolean($value, $message = '') |
|
| 324 | |||
| 325 | /** |
||
| 326 | * @psalm-assert scalar $value |
||
| 327 | * |
||
| 328 | * @param mixed $value |
||
| 329 | * @param string $message |
||
| 330 | */ |
||
| 331 | 23 | public static function scalar($value, $message = '') |
|
| 332 | { |
||
| 333 | 23 | if (!\is_scalar($value)) { |
|
| 334 | 11 | static::reportInvalidArgument(\sprintf( |
|
| 335 | 11 | $message ?: 'Expected a scalar. Got: %s', |
|
| 336 | 11 | static::typeToString($value) |
|
| 337 | )); |
||
| 338 | } |
||
| 339 | 12 | } |
|
| 340 | |||
| 341 | /** |
||
| 342 | * @psalm-assert object $value |
||
| 343 | * |
||
| 344 | * @param mixed $value |
||
| 345 | * @param string $message |
||
| 346 | */ |
||
| 347 | 23 | public static function object($value, $message = '') |
|
| 348 | { |
||
| 349 | 23 | if (!\is_object($value)) { |
|
| 350 | 15 | static::reportInvalidArgument(\sprintf( |
|
| 351 | 15 | $message ?: 'Expected an object. Got: %s', |
|
| 352 | 15 | static::typeToString($value) |
|
| 353 | )); |
||
| 354 | } |
||
| 355 | 8 | } |
|
| 356 | |||
| 357 | /** |
||
| 358 | * @psalm-assert resource $value |
||
| 359 | * |
||
| 360 | * @param mixed $value |
||
| 361 | * @param string|null $type type of resource this should be. @see https://www.php.net/manual/en/function.get-resource-type.php |
||
| 362 | * @param string $message |
||
| 363 | */ |
||
| 364 | 16 | public static function resource($value, $type = null, $message = '') |
|
| 365 | { |
||
| 366 | 16 | if (!\is_resource($value)) { |
|
| 367 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 368 | 4 | $message ?: 'Expected a resource. Got: %s', |
|
| 369 | 4 | static::typeToString($value) |
|
| 370 | )); |
||
| 371 | } |
||
| 372 | |||
| 373 | 12 | if ($type && $type !== \get_resource_type($value)) { |
|
| 374 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 375 | 4 | $message ?: 'Expected a resource of type %2$s. Got: %s', |
|
| 376 | 4 | static::typeToString($value), |
|
| 377 | 4 | $type |
|
| 378 | )); |
||
| 379 | } |
||
| 380 | 8 | } |
|
| 381 | |||
| 382 | /** |
||
| 383 | * @psalm-assert callable $value |
||
| 384 | * |
||
| 385 | * @param mixed $value |
||
| 386 | * @param string $message |
||
| 387 | */ |
||
| 388 | 20 | public static function isCallable($value, $message = '') |
|
| 389 | { |
||
| 390 | 20 | if (!\is_callable($value)) { |
|
| 391 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 392 | 8 | $message ?: 'Expected a callable. Got: %s', |
|
| 393 | 8 | static::typeToString($value) |
|
| 394 | )); |
||
| 395 | } |
||
| 396 | 12 | } |
|
| 397 | |||
| 398 | /** |
||
| 399 | * @psalm-assert array $value |
||
| 400 | * |
||
| 401 | * @param mixed $value |
||
| 402 | * @param string $message |
||
| 403 | */ |
||
| 404 | 20 | public static function isArray($value, $message = '') |
|
| 405 | { |
||
| 406 | 20 | if (!\is_array($value)) { |
|
| 407 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 408 | 12 | $message ?: 'Expected an array. Got: %s', |
|
| 409 | 12 | static::typeToString($value) |
|
| 410 | )); |
||
| 411 | } |
||
| 412 | 8 | } |
|
| 413 | |||
| 414 | /** |
||
| 415 | * @psalm-assert iterable $value |
||
| 416 | * |
||
| 417 | * @deprecated use "isIterable" or "isInstanceOf" instead |
||
| 418 | * |
||
| 419 | * @param mixed $value |
||
| 420 | * @param string $message |
||
| 421 | */ |
||
| 422 | 20 | public static function isTraversable($value, $message = '') |
|
| 423 | { |
||
| 424 | 20 | @\trigger_error( |
|
| 425 | 20 | \sprintf( |
|
| 426 | 20 | 'The "%s" assertion is deprecated. You should stop using it, as it will soon be removed in 2.0 version. Use "isIterable" or "isInstanceOf" instead.', |
|
| 427 | 20 | __METHOD__ |
|
| 428 | ), |
||
| 429 | 20 | \E_USER_DEPRECATED |
|
| 430 | ); |
||
| 431 | |||
| 432 | 20 | if (!\is_array($value) && !($value instanceof Traversable)) { |
|
| 433 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 434 | 8 | $message ?: 'Expected a traversable. Got: %s', |
|
| 435 | 8 | static::typeToString($value) |
|
| 436 | )); |
||
| 437 | } |
||
| 438 | 12 | } |
|
| 439 | |||
| 440 | /** |
||
| 441 | * @param mixed $value |
||
| 442 | * @param string $message |
||
| 443 | */ |
||
| 444 | 20 | View Code Duplication | public static function isArrayAccessible($value, $message = '') |
| 453 | |||
| 454 | /** |
||
| 455 | * @psalm-assert countable $value |
||
| 456 | * |
||
| 457 | * @param mixed $value |
||
| 458 | * @param string $message |
||
| 459 | */ |
||
| 460 | 24 | View Code Duplication | public static function isCountable($value, $message = '') |
| 461 | { |
||
| 462 | 24 | if (!\is_array($value) && !($value instanceof Countable)) { |
|
| 463 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 464 | 12 | $message ?: 'Expected a countable. Got: %s', |
|
| 465 | 12 | static::typeToString($value) |
|
| 466 | )); |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @psalm-assert iterable $value |
||
| 472 | * |
||
| 473 | * @param mixed $value |
||
| 474 | * @param string $message |
||
| 475 | */ |
||
| 476 | 910 | View Code Duplication | public static function isIterable($value, $message = '') |
| 485 | |||
| 486 | /** |
||
| 487 | * @psalm-template ExpectedType of object |
||
| 488 | * @psalm-param class-string<ExpectedType> $class |
||
| 489 | * @psalm-assert ExpectedType $value |
||
| 490 | * |
||
| 491 | * @param mixed $value |
||
| 492 | * @param string|object $class |
||
| 493 | * @param string $message |
||
| 494 | */ |
||
| 495 | 16 | public static function isInstanceOf($value, $class, $message = '') |
|
| 505 | |||
| 506 | /** |
||
| 507 | * @psalm-template ExpectedType of object |
||
| 508 | * @psalm-param class-string<ExpectedType> $class |
||
| 509 | * @psalm-assert !ExpectedType $value |
||
| 510 | * |
||
| 511 | * @param mixed $value |
||
| 512 | * @param string|object $class |
||
| 513 | * @param string $message |
||
| 514 | */ |
||
| 515 | 16 | public static function notInstanceOf($value, $class, $message = '') |
|
| 525 | |||
| 526 | /** |
||
| 527 | * @param mixed $value |
||
| 528 | * @param array<object|string> $classes |
||
| 529 | * @param string $message |
||
| 530 | */ |
||
| 531 | 20 | public static function isInstanceOfAny($value, array $classes, $message = '') |
|
| 545 | |||
| 546 | 20 | View Code Duplication | public static function isAOf($value, $class, $message = '') |
| 558 | |||
| 559 | 20 | View Code Duplication | public static function notAOf($value, $class, $message = '') |
| 571 | |||
| 572 | 24 | public static function isAOfAny($value, array $classes, $message = '') |
|
| 588 | |||
| 589 | /** |
||
| 590 | * @psalm-assert empty $value |
||
| 591 | * |
||
| 592 | * @param mixed $value |
||
| 593 | * @param string $message |
||
| 594 | */ |
||
| 595 | 23 | public static function isEmpty($value, $message = '') |
|
| 604 | |||
| 605 | /** |
||
| 606 | * @psalm-assert !empty $value |
||
| 607 | * |
||
| 608 | * @param mixed $value |
||
| 609 | * @param string $message |
||
| 610 | */ |
||
| 611 | 23 | public static function notEmpty($value, $message = '') |
|
| 620 | |||
| 621 | /** |
||
| 622 | * @psalm-assert null $value |
||
| 623 | * |
||
| 624 | * @param mixed $value |
||
| 625 | * @param string $message |
||
| 626 | */ |
||
| 627 | 11 | public static function null($value, $message = '') |
|
| 636 | |||
| 637 | /** |
||
| 638 | * @psalm-assert !null $value |
||
| 639 | * |
||
| 640 | * @param mixed $value |
||
| 641 | * @param string $message |
||
| 642 | */ |
||
| 643 | 11 | public static function notNull($value, $message = '') |
|
| 651 | |||
| 652 | /** |
||
| 653 | * @psalm-assert true $value |
||
| 654 | * |
||
| 655 | * @param mixed $value |
||
| 656 | * @param string $message |
||
| 657 | */ |
||
| 658 | 15 | public static function true($value, $message = '') |
|
| 667 | |||
| 668 | /** |
||
| 669 | * @psalm-assert false $value |
||
| 670 | * |
||
| 671 | * @param mixed $value |
||
| 672 | * @param string $message |
||
| 673 | */ |
||
| 674 | 19 | public static function false($value, $message = '') |
|
| 683 | |||
| 684 | /** |
||
| 685 | * @param mixed $value |
||
| 686 | * @param string $message |
||
| 687 | */ |
||
| 688 | 47 | View Code Duplication | public static function ip($value, $message = '') |
| 697 | |||
| 698 | /** |
||
| 699 | * @param mixed $value |
||
| 700 | * @param string $message |
||
| 701 | */ |
||
| 702 | 47 | View Code Duplication | public static function ipv4($value, $message = '') |
| 711 | |||
| 712 | /** |
||
| 713 | * @param mixed $value |
||
| 714 | * @param string $message |
||
| 715 | */ |
||
| 716 | 47 | View Code Duplication | public static function ipv6($value, $message = '') |
| 725 | |||
| 726 | /** |
||
| 727 | * @param mixed $value |
||
| 728 | * @param string $message |
||
| 729 | */ |
||
| 730 | 16 | View Code Duplication | public static function email($value, $message = '') |
| 739 | |||
| 740 | /** |
||
| 741 | * Does non strict comparisons on the items, so ['3', 3] will not pass the assertion. |
||
| 742 | * |
||
| 743 | * @param array $values |
||
| 744 | * @param string $message |
||
| 745 | */ |
||
| 746 | 12 | public static function uniqueValues(array $values, $message = '') |
|
| 761 | |||
| 762 | /** |
||
| 763 | * @param mixed $value |
||
| 764 | * @param mixed $expect |
||
| 765 | * @param string $message |
||
| 766 | */ |
||
| 767 | 33 | public static function eq($value, $expect, $message = '') |
|
| 777 | |||
| 778 | /** |
||
| 779 | * @param mixed $value |
||
| 780 | * @param mixed $expect |
||
| 781 | * @param string $message |
||
| 782 | */ |
||
| 783 | 28 | public static function notEq($value, $expect, $message = '') |
|
| 792 | |||
| 793 | /** |
||
| 794 | * @psalm-template ExpectedType |
||
| 795 | * @psalm-param ExpectedType $expect |
||
| 796 | * @psalm-assert =ExpectedType $value |
||
| 797 | * |
||
| 798 | * @param mixed $value |
||
| 799 | * @param mixed $expect |
||
| 800 | * @param string $message |
||
| 801 | */ |
||
| 802 | 16 | public static function same($value, $expect, $message = '') |
|
| 812 | |||
| 813 | /** |
||
| 814 | * @param mixed $value |
||
| 815 | * @param mixed $expect |
||
| 816 | * @param string $message |
||
| 817 | */ |
||
| 818 | 16 | public static function notSame($value, $expect, $message = '') |
|
| 827 | |||
| 828 | /** |
||
| 829 | * @param mixed $value |
||
| 830 | * @param mixed $limit |
||
| 831 | * @param string $message |
||
| 832 | */ |
||
| 833 | 8 | public static function greaterThan($value, $limit, $message = '') |
|
| 843 | |||
| 844 | /** |
||
| 845 | * @param mixed $value |
||
| 846 | * @param mixed $limit |
||
| 847 | * @param string $message |
||
| 848 | */ |
||
| 849 | 12 | public static function greaterThanEq($value, $limit, $message = '') |
|
| 859 | |||
| 860 | /** |
||
| 861 | * @param mixed $value |
||
| 862 | * @param mixed $limit |
||
| 863 | * @param string $message |
||
| 864 | */ |
||
| 865 | 8 | public static function lessThan($value, $limit, $message = '') |
|
| 875 | |||
| 876 | /** |
||
| 877 | * @param mixed $value |
||
| 878 | * @param mixed $limit |
||
| 879 | * @param string $message |
||
| 880 | */ |
||
| 881 | 12 | public static function lessThanEq($value, $limit, $message = '') |
|
| 891 | |||
| 892 | /** |
||
| 893 | * Inclusive range, so Assert::(3, 3, 5) passes. |
||
| 894 | * |
||
| 895 | * @param mixed $value |
||
| 896 | * @param mixed min |
||
| 897 | * @param mixed max |
||
| 898 | * @param string $message |
||
| 899 | */ |
||
| 900 | 16 | View Code Duplication | public static function range($value, $min, $max, $message = '') |
| 911 | |||
| 912 | /** |
||
| 913 | * Does strict comparison, so Assert::oneOf(3, ['3']) does not pass the assertion. |
||
| 914 | * |
||
| 915 | * @psalm-template ExpectedType |
||
| 916 | * @psalm-param array<ExpectedType> $values |
||
| 917 | * @psalm-assert ExpectedType $value |
||
| 918 | * |
||
| 919 | * @param mixed $value |
||
| 920 | * @param array $values |
||
| 921 | * @param string $message |
||
| 922 | */ |
||
| 923 | 8 | public static function oneOf($value, array $values, $message = '') |
|
| 933 | |||
| 934 | /** |
||
| 935 | * @param mixed $value |
||
| 936 | * @param string $subString |
||
| 937 | * @param string $message |
||
| 938 | */ |
||
| 939 | 80 | View Code Duplication | public static function contains($value, $subString, $message = '') |
| 949 | |||
| 950 | /** |
||
| 951 | * @param mixed $value |
||
| 952 | * @param string $subString |
||
| 953 | * @param string $message |
||
| 954 | */ |
||
| 955 | 80 | View Code Duplication | public static function notContains($value, $subString, $message = '') |
| 965 | |||
| 966 | /** |
||
| 967 | * @param mixed $value |
||
| 968 | * @param string $message |
||
| 969 | */ |
||
| 970 | 40 | public static function notWhitespaceOnly($value, $message = '') |
|
| 979 | |||
| 980 | /** |
||
| 981 | * @param mixed $value |
||
| 982 | * @param string $prefix |
||
| 983 | * @param string $message |
||
| 984 | */ |
||
| 985 | 48 | View Code Duplication | public static function startsWith($value, $prefix, $message = '') |
| 995 | |||
| 996 | /** |
||
| 997 | * @param mixed $value |
||
| 998 | * @param string $message |
||
| 999 | */ |
||
| 1000 | 24 | public static function startsWithLetter($value, $message = '') |
|
| 1018 | |||
| 1019 | /** |
||
| 1020 | * @param mixed $value |
||
| 1021 | * @param string $suffix |
||
| 1022 | * @param string $message |
||
| 1023 | */ |
||
| 1024 | 48 | View Code Duplication | public static function endsWith($value, $suffix, $message = '') |
| 1034 | |||
| 1035 | /** |
||
| 1036 | * @param mixed $value |
||
| 1037 | * @param mixed $pattern |
||
| 1038 | * @param string $message |
||
| 1039 | */ |
||
| 1040 | 12 | public static function regex($value, $pattern, $message = '') |
|
| 1049 | |||
| 1050 | /** |
||
| 1051 | * @param mixed $value |
||
| 1052 | * @param mixed $pattern |
||
| 1053 | * @param string $message |
||
| 1054 | */ |
||
| 1055 | 12 | public static function notRegex($value, $pattern, $message = '') |
|
| 1066 | |||
| 1067 | /** |
||
| 1068 | * @psalm-assert !numeric $value |
||
| 1069 | * |
||
| 1070 | * @param mixed $value |
||
| 1071 | * @param string $message |
||
| 1072 | */ |
||
| 1073 | 28 | View Code Duplication | public static function unicodeLetters($value, $message = '') |
| 1084 | |||
| 1085 | /** |
||
| 1086 | * @param mixed $value |
||
| 1087 | * @param string $message |
||
| 1088 | */ |
||
| 1089 | 12 | View Code Duplication | public static function alpha($value, $message = '') |
| 1103 | |||
| 1104 | /** |
||
| 1105 | * @param mixed $value |
||
| 1106 | * @param string $message |
||
| 1107 | */ |
||
| 1108 | 12 | View Code Duplication | public static function digits($value, $message = '') |
| 1122 | |||
| 1123 | /** |
||
| 1124 | * @param mixed $value |
||
| 1125 | * @param string $message |
||
| 1126 | */ |
||
| 1127 | 12 | View Code Duplication | public static function alnum($value, $message = '') |
| 1141 | |||
| 1142 | /** |
||
| 1143 | * @param mixed $value |
||
| 1144 | * @param string $message |
||
| 1145 | */ |
||
| 1146 | 16 | View Code Duplication | public static function lower($value, $message = '') |
| 1160 | |||
| 1161 | /** |
||
| 1162 | * @param mixed $value |
||
| 1163 | * @param string $message |
||
| 1164 | */ |
||
| 1165 | 16 | View Code Duplication | public static function upper($value, $message = '') |
| 1179 | |||
| 1180 | /** |
||
| 1181 | * @param mixed $value |
||
| 1182 | * @param mixed $length |
||
| 1183 | * @param string $message |
||
| 1184 | */ |
||
| 1185 | 36 | public static function length($value, $length, $message = '') |
|
| 1195 | |||
| 1196 | /** |
||
| 1197 | * Inclusive min. |
||
| 1198 | * |
||
| 1199 | * @param mixed $value |
||
| 1200 | * @param mixed $min |
||
| 1201 | * @param string $message |
||
| 1202 | */ |
||
| 1203 | 36 | public static function minLength($value, $min, $message = '') |
|
| 1213 | |||
| 1214 | /** |
||
| 1215 | * Inclusive max. |
||
| 1216 | * |
||
| 1217 | * @param mixed $value |
||
| 1218 | * @param mixed $max |
||
| 1219 | * @param string $message |
||
| 1220 | */ |
||
| 1221 | 36 | public static function maxLength($value, $max, $message = '') |
|
| 1231 | |||
| 1232 | /** |
||
| 1233 | * Inclusive , so Assert::lengthBetween('asd', 3, 5); passes the assertion. |
||
| 1234 | * |
||
| 1235 | * @param mixed $value |
||
| 1236 | * @param mixed $min |
||
| 1237 | * @param mixed $max |
||
| 1238 | * @param string $message |
||
| 1239 | */ |
||
| 1240 | 60 | View Code Duplication | public static function lengthBetween($value, $min, $max, $message = '') |
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Will also pass if $value is a directory, use Assert::file() instead if you need to be sure it is a file. |
||
| 1256 | * |
||
| 1257 | * @param mixed $value |
||
| 1258 | * @param string $message |
||
| 1259 | */ |
||
| 1260 | 36 | View Code Duplication | public static function fileExists($value, $message = '') |
| 1271 | |||
| 1272 | /** |
||
| 1273 | * @param mixed $value |
||
| 1274 | * @param string $message |
||
| 1275 | */ |
||
| 1276 | 12 | View Code Duplication | public static function file($value, $message = '') |
| 1287 | |||
| 1288 | /** |
||
| 1289 | * @param mixed $value |
||
| 1290 | * @param string $message |
||
| 1291 | */ |
||
| 1292 | 12 | View Code Duplication | public static function directory($value, $message = '') |
| 1303 | |||
| 1304 | /** |
||
| 1305 | * @param mixed $value |
||
| 1306 | * @param string $message |
||
| 1307 | */ |
||
| 1308 | public static function readable($value, $message = '') |
||
| 1317 | |||
| 1318 | /** |
||
| 1319 | * @param mixed $value |
||
| 1320 | * @param string $message |
||
| 1321 | */ |
||
| 1322 | public static function writable($value, $message = '') |
||
| 1331 | |||
| 1332 | /** |
||
| 1333 | * @psalm-assert class-string $value |
||
| 1334 | * |
||
| 1335 | * @param mixed $value |
||
| 1336 | * @param string $message |
||
| 1337 | */ |
||
| 1338 | 8 | public static function classExists($value, $message = '') |
|
| 1347 | |||
| 1348 | /** |
||
| 1349 | * @param mixed $value |
||
| 1350 | * @param string|object $class |
||
| 1351 | * @param string $message |
||
| 1352 | */ |
||
| 1353 | 8 | public static function subclassOf($value, $class, $message = '') |
|
| 1363 | |||
| 1364 | /** |
||
| 1365 | * @psalm-assert class-string $value |
||
| 1366 | * |
||
| 1367 | * @param mixed $value |
||
| 1368 | * @param string $message |
||
| 1369 | */ |
||
| 1370 | 8 | public static function interfaceExists($value, $message = '') |
|
| 1379 | |||
| 1380 | /** |
||
| 1381 | * @param mixed $value |
||
| 1382 | * @param mixed $interface |
||
| 1383 | * @param string $message |
||
| 1384 | */ |
||
| 1385 | 8 | View Code Duplication | public static function implementsInterface($value, $interface, $message = '') |
| 1395 | |||
| 1396 | /** |
||
| 1397 | * @param string|object $classOrObject |
||
| 1398 | * @param mixed $property |
||
| 1399 | * @param string $message |
||
| 1400 | */ |
||
| 1401 | 12 | View Code Duplication | public static function propertyExists($classOrObject, $property, $message = '') |
| 1410 | |||
| 1411 | /** |
||
| 1412 | * @param string|object $classOrObject |
||
| 1413 | * @param mixed $property |
||
| 1414 | * @param string $message |
||
| 1415 | */ |
||
| 1416 | 12 | View Code Duplication | public static function propertyNotExists($classOrObject, $property, $message = '') |
| 1425 | |||
| 1426 | /** |
||
| 1427 | * @param string|object $classOrObject |
||
| 1428 | * @param mixed $method |
||
| 1429 | * @param string $message |
||
| 1430 | */ |
||
| 1431 | 27 | View Code Duplication | public static function methodExists($classOrObject, $method, $message = '') |
| 1440 | |||
| 1441 | /** |
||
| 1442 | * @param string|object $classOrObject |
||
| 1443 | * @param mixed $method |
||
| 1444 | * @param string $message |
||
| 1445 | */ |
||
| 1446 | 27 | View Code Duplication | public static function methodNotExists($classOrObject, $method, $message = '') |
| 1455 | |||
| 1456 | /** |
||
| 1457 | * @param array $array |
||
| 1458 | * @param string|int $key |
||
| 1459 | * @param string $message |
||
| 1460 | */ |
||
| 1461 | 12 | View Code Duplication | public static function keyExists($array, $key, $message = '') |
| 1470 | |||
| 1471 | /** |
||
| 1472 | * @param array $array |
||
| 1473 | * @param string|int $key |
||
| 1474 | * @param string $message |
||
| 1475 | */ |
||
| 1476 | 12 | View Code Duplication | public static function keyNotExists($array, $key, $message = '') |
| 1485 | |||
| 1486 | /** |
||
| 1487 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1488 | * |
||
| 1489 | * @param mixed $array |
||
| 1490 | * @param mixed $number |
||
| 1491 | * @param string $message |
||
| 1492 | */ |
||
| 1493 | 8 | public static function count($array, $number, $message = '') |
|
| 1501 | |||
| 1502 | /** |
||
| 1503 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1504 | * |
||
| 1505 | * @param mixed $array |
||
| 1506 | * @param mixed $min |
||
| 1507 | * @param string $message |
||
| 1508 | */ |
||
| 1509 | 12 | View Code Duplication | public static function minCount($array, $min, $message = '') |
| 1519 | |||
| 1520 | /** |
||
| 1521 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1522 | * |
||
| 1523 | * @param mixed $array |
||
| 1524 | * @param mixed $max |
||
| 1525 | * @param string $message |
||
| 1526 | */ |
||
| 1527 | 12 | View Code Duplication | public static function maxCount($array, $max, $message = '') |
| 1537 | |||
| 1538 | /** |
||
| 1539 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1540 | * |
||
| 1541 | * @param mixed $array |
||
| 1542 | * @param mixed $min |
||
| 1543 | * @param mixed $max |
||
| 1544 | * @param string $message |
||
| 1545 | */ |
||
| 1546 | 20 | public static function countBetween($array, $min, $max, $message = '') |
|
| 1559 | |||
| 1560 | /** |
||
| 1561 | * @param mixed $array |
||
| 1562 | * @param string $message |
||
| 1563 | */ |
||
| 1564 | 24 | public static function isList($array, $message = '') |
|
| 1572 | |||
| 1573 | /** |
||
| 1574 | * @param mixed $array |
||
| 1575 | * @param string $message |
||
| 1576 | */ |
||
| 1577 | 16 | public static function isMap($array, $message = '') |
|
| 1591 | |||
| 1592 | /** |
||
| 1593 | * @param mixed $value |
||
| 1594 | * @param string $message |
||
| 1595 | */ |
||
| 1596 | 56 | public static function uuid($value, $message = '') |
|
| 1613 | |||
| 1614 | /** |
||
| 1615 | * @param Closure $expression |
||
| 1616 | * @param string|object $class |
||
| 1617 | * @param string $message |
||
| 1618 | */ |
||
| 1619 | 24 | public static function throws(Closure $expression, $class = 'Exception', $message = '') |
|
| 1645 | |||
| 1646 | 1434 | public static function __callStatic($name, $arguments) |
|
| 1674 | |||
| 1675 | /** |
||
| 1676 | * @param mixed $value |
||
| 1677 | * |
||
| 1678 | * @return string |
||
| 1679 | */ |
||
| 1680 | 706 | protected static function valueToString($value) |
|
| 1716 | |||
| 1717 | /** |
||
| 1718 | * @param mixed $value |
||
| 1719 | * |
||
| 1720 | * @return string |
||
| 1721 | */ |
||
| 1722 | 209 | protected static function typeToString($value) |
|
| 1726 | |||
| 1727 | 168 | protected static function strlen($value) |
|
| 1739 | |||
| 1740 | /** |
||
| 1741 | * @param string $message |
||
| 1742 | */ |
||
| 1743 | 958 | protected static function reportInvalidArgument($message) |
|
| 1747 | |||
| 1748 | private function __construct() |
||
| 1751 | } |
||
| 1752 |