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 | * @psalm-assert string $value |
||
| 197 | * |
||
| 198 | * @param mixed $value |
||
| 199 | * @param string $message |
||
| 200 | */ |
||
| 201 | 122 | public static function string($value, $message = '') |
|
| 202 | { |
||
| 203 | 122 | if (!\is_string($value)) { |
|
| 204 | 14 | static::reportInvalidArgument(\sprintf( |
|
| 205 | 14 | $message ?: 'Expected a string. Got: %s', |
|
| 206 | 14 | static::typeToString($value) |
|
| 207 | )); |
||
| 208 | } |
||
| 209 | 108 | } |
|
| 210 | |||
| 211 | /** |
||
| 212 | * @psalm-assert string $value |
||
| 213 | * |
||
| 214 | * @param mixed $value |
||
| 215 | * @param string $message |
||
| 216 | */ |
||
| 217 | 16 | public static function stringNotEmpty($value, $message = '') |
|
| 218 | { |
||
| 219 | 16 | static::string($value, $message); |
|
| 220 | 12 | static::notEq($value, '', $message); |
|
| 221 | 8 | } |
|
| 222 | |||
| 223 | /** |
||
| 224 | * @psalm-assert int $value |
||
| 225 | * |
||
| 226 | * @param mixed $value |
||
| 227 | * @param string $message |
||
| 228 | */ |
||
| 229 | 17 | public static function integer($value, $message = '') |
|
| 230 | { |
||
| 231 | 17 | if (!\is_int($value)) { |
|
| 232 | 13 | static::reportInvalidArgument(\sprintf( |
|
| 233 | 13 | $message ?: 'Expected an integer. Got: %s', |
|
| 234 | 13 | static::typeToString($value) |
|
| 235 | )); |
||
| 236 | } |
||
| 237 | 4 | } |
|
| 238 | |||
| 239 | /** |
||
| 240 | * @psalm-assert numeric |
||
| 241 | * |
||
| 242 | * @param mixed $value |
||
| 243 | * @param string $message |
||
| 244 | */ |
||
| 245 | 16 | public static function integerish($value, $message = '') |
|
| 246 | { |
||
| 247 | 16 | if (!\is_numeric($value) || $value != (int) $value) { |
|
| 248 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 249 | 4 | $message ?: 'Expected an integerish value. Got: %s', |
|
| 250 | 4 | static::typeToString($value) |
|
| 251 | )); |
||
| 252 | } |
||
| 253 | 12 | } |
|
| 254 | |||
| 255 | /** |
||
| 256 | * @psalm-assert float $value |
||
| 257 | * |
||
| 258 | * @param mixed $value |
||
| 259 | * @param string $message |
||
| 260 | */ |
||
| 261 | 16 | public static function float($value, $message = '') |
|
| 262 | { |
||
| 263 | 16 | if (!\is_float($value)) { |
|
| 264 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 265 | 8 | $message ?: 'Expected a float. Got: %s', |
|
| 266 | 8 | static::typeToString($value) |
|
| 267 | )); |
||
| 268 | } |
||
| 269 | 8 | } |
|
| 270 | |||
| 271 | /** |
||
| 272 | * @psalm-assert numeric $value |
||
| 273 | * |
||
| 274 | * @param mixed $value |
||
| 275 | * @param string $message |
||
| 276 | */ |
||
| 277 | 20 | public static function numeric($value, $message = '') |
|
| 286 | |||
| 287 | /** |
||
| 288 | * @psalm-assert int $value |
||
| 289 | * |
||
| 290 | * @param mixed $value |
||
| 291 | * @param string $message |
||
| 292 | */ |
||
| 293 | 24 | public static function natural($value, $message = '') |
|
| 294 | { |
||
| 295 | 24 | if (!\is_int($value) || $value < 0) { |
|
| 296 | 16 | static::reportInvalidArgument(\sprintf( |
|
| 297 | 16 | $message ?: 'Expected a non-negative integer. Got %s', |
|
| 298 | 16 | static::valueToString($value) |
|
| 299 | )); |
||
| 300 | } |
||
| 301 | 8 | } |
|
| 302 | |||
| 303 | /** |
||
| 304 | * @psalm-assert bool $value |
||
| 305 | * |
||
| 306 | * @param mixed $value |
||
| 307 | * @param string $message |
||
| 308 | */ |
||
| 309 | 16 | public static function boolean($value, $message = '') |
|
| 310 | { |
||
| 311 | 16 | if (!\is_bool($value)) { |
|
| 312 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 313 | 8 | $message ?: 'Expected a boolean. Got: %s', |
|
| 314 | 8 | static::typeToString($value) |
|
| 315 | )); |
||
| 316 | } |
||
| 317 | 8 | } |
|
| 318 | |||
| 319 | /** |
||
| 320 | * @psalm-assert scalar $value |
||
| 321 | * |
||
| 322 | * @param mixed $value |
||
| 323 | * @param string $message |
||
| 324 | */ |
||
| 325 | 23 | public static function scalar($value, $message = '') |
|
| 326 | { |
||
| 327 | 23 | if (!\is_scalar($value)) { |
|
| 328 | 11 | static::reportInvalidArgument(\sprintf( |
|
| 329 | 11 | $message ?: 'Expected a scalar. Got: %s', |
|
| 330 | 11 | static::typeToString($value) |
|
| 331 | )); |
||
| 332 | } |
||
| 333 | 12 | } |
|
| 334 | |||
| 335 | /** |
||
| 336 | * @psalm-assert object $value |
||
| 337 | * |
||
| 338 | * @param mixed$value |
||
| 339 | * @param string $message |
||
| 340 | */ |
||
| 341 | 23 | public static function object($value, $message = '') |
|
| 342 | { |
||
| 343 | 23 | if (!\is_object($value)) { |
|
| 344 | 15 | static::reportInvalidArgument(\sprintf( |
|
| 345 | 15 | $message ?: 'Expected an object. Got: %s', |
|
| 346 | 15 | static::typeToString($value) |
|
| 347 | )); |
||
| 348 | } |
||
| 349 | 8 | } |
|
| 350 | |||
| 351 | /** |
||
| 352 | * @psalm-assert resource $value |
||
| 353 | * |
||
| 354 | * @param mixed $value |
||
| 355 | * @param string|null $type type of resource this should be. @see https://www.php.net/manual/en/function.get-resource-type.php |
||
| 356 | * @param string $message |
||
| 357 | */ |
||
| 358 | 16 | public static function resource($value, $type = null, $message = '') |
|
| 359 | { |
||
| 360 | 16 | if (!\is_resource($value)) { |
|
| 361 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 362 | 4 | $message ?: 'Expected a resource. Got: %s', |
|
| 363 | 4 | static::typeToString($value) |
|
| 364 | )); |
||
| 365 | } |
||
| 366 | |||
| 367 | 12 | if ($type && $type !== \get_resource_type($value)) { |
|
| 368 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 369 | 4 | $message ?: 'Expected a resource of type %2$s. Got: %s', |
|
| 370 | 4 | static::typeToString($value), |
|
| 371 | 4 | $type |
|
| 372 | )); |
||
| 373 | } |
||
| 374 | 8 | } |
|
| 375 | |||
| 376 | /** |
||
| 377 | * @psalm-assert callable $value |
||
| 378 | * |
||
| 379 | * @param mixed $value |
||
| 380 | * @param string $message |
||
| 381 | */ |
||
| 382 | 20 | public static function isCallable($value, $message = '') |
|
| 383 | { |
||
| 384 | 20 | if (!\is_callable($value)) { |
|
| 385 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 386 | 8 | $message ?: 'Expected a callable. Got: %s', |
|
| 387 | 8 | static::typeToString($value) |
|
| 388 | )); |
||
| 389 | } |
||
| 390 | 12 | } |
|
| 391 | |||
| 392 | /** |
||
| 393 | * @psalm-assert array $value |
||
| 394 | * |
||
| 395 | * @param mixed $value |
||
| 396 | * @param string $message |
||
| 397 | */ |
||
| 398 | 20 | public static function isArray($value, $message = '') |
|
| 399 | { |
||
| 400 | 20 | if (!\is_array($value)) { |
|
| 401 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 402 | 12 | $message ?: 'Expected an array. Got: %s', |
|
| 403 | 12 | static::typeToString($value) |
|
| 404 | )); |
||
| 405 | } |
||
| 406 | 8 | } |
|
| 407 | |||
| 408 | /** |
||
| 409 | * @deprecated use "isIterable" or "isInstanceOf" instead |
||
| 410 | * |
||
| 411 | * @psalm-assert iterable $value |
||
| 412 | * |
||
| 413 | * @param mixed $value |
||
| 414 | * @param string $message |
||
| 415 | */ |
||
| 416 | 20 | public static function isTraversable($value, $message = '') |
|
| 417 | { |
||
| 418 | 20 | @\trigger_error( |
|
| 419 | 20 | \sprintf( |
|
| 420 | 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.', |
|
| 421 | 20 | __METHOD__ |
|
| 422 | ), |
||
| 423 | 20 | \E_USER_DEPRECATED |
|
| 424 | ); |
||
| 425 | |||
| 426 | 20 | if (!\is_array($value) && !($value instanceof Traversable)) { |
|
| 427 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 428 | 8 | $message ?: 'Expected a traversable. Got: %s', |
|
| 429 | 8 | static::typeToString($value) |
|
| 430 | )); |
||
| 431 | } |
||
| 432 | 12 | } |
|
| 433 | |||
| 434 | /** |
||
| 435 | * @param mixed $value |
||
| 436 | * @param string $message |
||
| 437 | */ |
||
| 438 | 20 | View Code Duplication | public static function isArrayAccessible($value, $message = '') |
| 439 | { |
||
| 440 | 20 | if (!\is_array($value) && !($value instanceof ArrayAccess)) { |
|
| 441 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 442 | 8 | $message ?: 'Expected an array accessible. Got: %s', |
|
| 443 | 8 | static::typeToString($value) |
|
| 444 | )); |
||
| 445 | } |
||
| 446 | 12 | } |
|
| 447 | |||
| 448 | /** |
||
| 449 | * @psalm-assert countable $value |
||
| 450 | * |
||
| 451 | * @param mixed $value |
||
| 452 | * @param string $message |
||
| 453 | */ |
||
| 454 | 24 | View Code Duplication | public static function isCountable($value, $message = '') |
| 455 | { |
||
| 456 | 24 | if (!\is_array($value) && !($value instanceof Countable)) { |
|
| 457 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 458 | 12 | $message ?: 'Expected a countable. Got: %s', |
|
| 459 | 12 | static::typeToString($value) |
|
| 460 | )); |
||
| 461 | } |
||
| 462 | 12 | } |
|
| 463 | |||
| 464 | /** |
||
| 465 | * @psalm-assert iterable $value |
||
| 466 | * |
||
| 467 | * @param mixed $value |
||
| 468 | * @param string $message |
||
| 469 | */ |
||
| 470 | 878 | View Code Duplication | public static function isIterable($value, $message = '') |
| 471 | { |
||
| 472 | 878 | if (!\is_array($value) && !($value instanceof Traversable)) { |
|
| 473 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 474 | 8 | $message ?: 'Expected an iterable. Got: %s', |
|
| 475 | 8 | static::typeToString($value) |
|
| 476 | )); |
||
| 477 | } |
||
| 478 | 874 | } |
|
| 479 | |||
| 480 | /** |
||
| 481 | * @psalm-template ExpectedType of object |
||
| 482 | * @psalm-param class-string<ExpectedType> $class |
||
| 483 | * @psalm-assert ExpectedType $value |
||
| 484 | * |
||
| 485 | * @param mixed $value |
||
| 486 | * @param string|object $class |
||
| 487 | * @param string $message |
||
| 488 | */ |
||
| 489 | 16 | public static function isInstanceOf($value, $class, $message = '') |
|
| 490 | { |
||
| 491 | 16 | if (!($value instanceof $class)) { |
|
| 492 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 493 | 12 | $message ?: 'Expected an instance of %2$s. Got: %s', |
|
| 494 | 12 | static::typeToString($value), |
|
| 495 | 12 | $class |
|
| 496 | )); |
||
| 497 | } |
||
| 498 | 4 | } |
|
| 499 | |||
| 500 | /** |
||
| 501 | * @psalm-template ExpectedType of object |
||
| 502 | * @psalm-param class-string<ExpectedType> $class |
||
| 503 | * @psalm-assert !ExpectedType $value |
||
| 504 | * |
||
| 505 | * @param mixed $value |
||
| 506 | * @param string|object $class |
||
| 507 | * @param string $message |
||
| 508 | */ |
||
| 509 | 16 | public static function notInstanceOf($value, $class, $message = '') |
|
| 510 | { |
||
| 511 | 16 | if ($value instanceof $class) { |
|
| 512 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 513 | 4 | $message ?: 'Expected an instance other than %2$s. Got: %s', |
|
| 514 | 4 | static::typeToString($value), |
|
| 515 | 4 | $class |
|
| 516 | )); |
||
| 517 | } |
||
| 518 | 12 | } |
|
| 519 | |||
| 520 | /** |
||
| 521 | * @psalm-template ExpectedType |
||
| 522 | * @psalm-param array<class-string<ExpectedType>|ExpectedType> $classes |
||
| 523 | * @psalm-assert ExpectedType $value |
||
| 524 | * |
||
| 525 | * @param mixed $value |
||
| 526 | * @param array<object|string> $classes |
||
| 527 | * @param string $message |
||
| 528 | */ |
||
| 529 | 20 | public static function isInstanceOfAny($value, array $classes, $message = '') |
|
| 530 | { |
||
| 531 | 20 | foreach ($classes as $class) { |
|
| 532 | 20 | if ($value instanceof $class) { |
|
| 533 | 8 | return; |
|
| 534 | } |
||
| 535 | } |
||
| 536 | |||
| 537 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 538 | 12 | $message ?: 'Expected an instance of any of %2$s. Got: %s', |
|
| 539 | 12 | static::typeToString($value), |
|
| 540 | 12 | \implode(', ', \array_map(array('static', 'valueToString'), $classes)) |
|
| 541 | )); |
||
| 542 | } |
||
| 543 | |||
| 544 | /** |
||
| 545 | * @psalm-assert empty $value |
||
| 546 | * |
||
| 547 | * @param mixed $value |
||
| 548 | * @param string $message |
||
| 549 | */ |
||
| 550 | 23 | public static function isEmpty($value, $message = '') |
|
| 551 | { |
||
| 552 | 23 | if (!empty($value)) { |
|
| 553 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 554 | 8 | $message ?: 'Expected an empty value. Got: %s', |
|
| 555 | 8 | static::valueToString($value) |
|
| 556 | )); |
||
| 557 | } |
||
| 558 | 15 | } |
|
| 559 | |||
| 560 | /** |
||
| 561 | * @psalm-assert !empty $value |
||
| 562 | * |
||
| 563 | * @param mixed $value |
||
| 564 | * @param string $message |
||
| 565 | */ |
||
| 566 | 23 | public static function notEmpty($value, $message = '') |
|
| 567 | { |
||
| 568 | 23 | if (empty($value)) { |
|
| 569 | 15 | static::reportInvalidArgument(\sprintf( |
|
| 570 | 15 | $message ?: 'Expected a non-empty value. Got: %s', |
|
| 571 | 15 | static::valueToString($value) |
|
| 572 | )); |
||
| 573 | } |
||
| 574 | 8 | } |
|
| 575 | |||
| 576 | /** |
||
| 577 | * @psalm-assert null $value |
||
| 578 | * |
||
| 579 | * @param mixed $value |
||
| 580 | * @param string $message |
||
| 581 | */ |
||
| 582 | 11 | public static function null($value, $message = '') |
|
| 583 | { |
||
| 584 | 11 | if (null !== $value) { |
|
| 585 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 586 | 8 | $message ?: 'Expected null. Got: %s', |
|
| 587 | 8 | static::valueToString($value) |
|
| 588 | )); |
||
| 589 | } |
||
| 590 | 3 | } |
|
| 591 | |||
| 592 | /** |
||
| 593 | * @psalm-assert !null $value |
||
| 594 | * |
||
| 595 | * @param mixed $value |
||
| 596 | * @param string $message |
||
| 597 | */ |
||
| 598 | 11 | public static function notNull($value, $message = '') |
|
| 599 | { |
||
| 600 | 11 | if (null === $value) { |
|
| 601 | 3 | static::reportInvalidArgument( |
|
| 602 | 3 | $message ?: 'Expected a value other than null.' |
|
| 603 | ); |
||
| 604 | } |
||
| 605 | 8 | } |
|
| 606 | |||
| 607 | /** |
||
| 608 | * @psalm-assert true $value |
||
| 609 | * |
||
| 610 | * @param mixed $value |
||
| 611 | * @param string $message |
||
| 612 | */ |
||
| 613 | 15 | public static function true($value, $message = '') |
|
| 614 | { |
||
| 615 | 15 | if (true !== $value) { |
|
| 616 | 11 | static::reportInvalidArgument(\sprintf( |
|
| 617 | 11 | $message ?: 'Expected a value to be true. Got: %s', |
|
| 618 | 11 | static::valueToString($value) |
|
| 619 | )); |
||
| 620 | } |
||
| 621 | 4 | } |
|
| 622 | |||
| 623 | /** |
||
| 624 | * @psalm-assert false $value |
||
| 625 | * |
||
| 626 | * @param mixed$value |
||
| 627 | * @param string $message |
||
| 628 | */ |
||
| 629 | 19 | public static function false($value, $message = '') |
|
| 630 | { |
||
| 631 | 19 | if (false !== $value) { |
|
| 632 | 15 | static::reportInvalidArgument(\sprintf( |
|
| 633 | 15 | $message ?: 'Expected a value to be false. Got: %s', |
|
| 634 | 15 | static::valueToString($value) |
|
| 635 | )); |
||
| 636 | } |
||
| 637 | 4 | } |
|
| 638 | |||
| 639 | /** |
||
| 640 | * @param mixed $value |
||
| 641 | * @param string $message |
||
| 642 | */ |
||
| 643 | 47 | View Code Duplication | public static function ip($value, $message = '') |
| 644 | { |
||
| 645 | 47 | if (false === \filter_var($value, \FILTER_VALIDATE_IP)) { |
|
| 646 | 19 | static::reportInvalidArgument(\sprintf( |
|
| 647 | 19 | $message ?: 'Expected a value to be an IP. Got: %s', |
|
| 648 | 19 | static::valueToString($value) |
|
| 649 | )); |
||
| 650 | } |
||
| 651 | 28 | } |
|
| 652 | |||
| 653 | /** |
||
| 654 | * @param mixed $value |
||
| 655 | * @param string $message |
||
| 656 | */ |
||
| 657 | 47 | View Code Duplication | public static function ipv4($value, $message = '') |
| 658 | { |
||
| 659 | 47 | if (false === \filter_var($value, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) { |
|
| 660 | 35 | static::reportInvalidArgument(\sprintf( |
|
| 661 | 35 | $message ?: 'Expected a value to be an IPv4. Got: %s', |
|
| 662 | 35 | static::valueToString($value) |
|
| 663 | )); |
||
| 664 | } |
||
| 665 | 12 | } |
|
| 666 | |||
| 667 | /** |
||
| 668 | * @param mixed $value |
||
| 669 | * @param string $message |
||
| 670 | */ |
||
| 671 | 47 | View Code Duplication | public static function ipv6($value, $message = '') |
| 672 | { |
||
| 673 | 47 | if (false === \filter_var($value, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) { |
|
| 674 | 31 | static::reportInvalidArgument(\sprintf( |
|
| 675 | 31 | $message ?: 'Expected a value to be an IPv6. Got %s', |
|
| 676 | 31 | static::valueToString($value) |
|
| 677 | )); |
||
| 678 | } |
||
| 679 | 16 | } |
|
| 680 | |||
| 681 | /** |
||
| 682 | * @param mixed $value |
||
| 683 | * @param string $message |
||
| 684 | */ |
||
| 685 | 16 | View Code Duplication | public static function email($value, $message = '') |
| 686 | { |
||
| 687 | 16 | if (false === \filter_var($value, FILTER_VALIDATE_EMAIL)) { |
|
| 688 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 689 | 12 | $message ?: 'Expected a value to be a valid e-mail address. Got %s', |
|
| 690 | 12 | static::valueToString($value) |
|
| 691 | )); |
||
| 692 | } |
||
| 693 | 4 | } |
|
| 694 | |||
| 695 | /** |
||
| 696 | * Does non strict comparisons on the items, so ['3', 3] will not pass the assertion. |
||
| 697 | * |
||
| 698 | * @param array $values |
||
| 699 | * @param string $message |
||
| 700 | */ |
||
| 701 | 12 | public static function uniqueValues(array $values, $message = '') |
|
| 702 | { |
||
| 703 | 12 | $allValues = \count($values); |
|
| 704 | 12 | $uniqueValues = \count(\array_unique($values)); |
|
| 705 | |||
| 706 | 12 | if ($allValues !== $uniqueValues) { |
|
| 707 | 8 | $difference = $allValues - $uniqueValues; |
|
| 708 | |||
| 709 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 710 | 8 | $message ?: 'Expected an array of unique values, but %s of them %s duplicated', |
|
| 711 | 8 | $difference, |
|
| 712 | 8 | (1 === $difference ? 'is' : 'are') |
|
| 713 | )); |
||
| 714 | } |
||
| 715 | 4 | } |
|
| 716 | |||
| 717 | /** |
||
| 718 | * @param mixed $value |
||
| 719 | * @param mixed $expect |
||
| 720 | * @param string $message |
||
| 721 | */ |
||
| 722 | 33 | public static function eq($value, $expect, $message = '') |
|
| 732 | |||
| 733 | /** |
||
| 734 | * @param mixed $value |
||
| 735 | * @param mixed $expect |
||
| 736 | * @param string $message |
||
| 737 | */ |
||
| 738 | 28 | public static function notEq($value, $expect, $message = '') |
|
| 739 | { |
||
| 740 | 28 | if ($expect == $value) { |
|
| 741 | 16 | static::reportInvalidArgument(\sprintf( |
|
| 742 | 16 | $message ?: 'Expected a different value than %s.', |
|
| 743 | 16 | static::valueToString($expect) |
|
| 744 | )); |
||
| 745 | } |
||
| 746 | 12 | } |
|
| 747 | |||
| 748 | /** |
||
| 749 | * @psalm-template ExpectedType |
||
| 750 | * @psalm-param ExpectedType $expect |
||
| 751 | * @psalm-assert =ExpectedType $value |
||
| 752 | * |
||
| 753 | * @param mixed $value |
||
| 754 | * @param mixed $expect |
||
| 755 | * @param string $message |
||
| 756 | */ |
||
| 757 | 16 | public static function same($value, $expect, $message = '') |
|
| 758 | { |
||
| 759 | 16 | if ($expect !== $value) { |
|
| 760 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 761 | 12 | $message ?: 'Expected a value identical to %2$s. Got: %s', |
|
| 762 | 12 | static::valueToString($value), |
|
| 763 | 12 | static::valueToString($expect) |
|
| 764 | )); |
||
| 765 | } |
||
| 766 | 4 | } |
|
| 767 | |||
| 768 | /** |
||
| 769 | * @param mixed $value |
||
| 770 | * @param mixed $expect |
||
| 771 | * @param string $message |
||
| 772 | */ |
||
| 773 | 16 | public static function notSame($value, $expect, $message = '') |
|
| 774 | { |
||
| 775 | 16 | if ($expect === $value) { |
|
| 776 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 777 | 4 | $message ?: 'Expected a value not identical to %s.', |
|
| 778 | 4 | static::valueToString($expect) |
|
| 779 | )); |
||
| 780 | } |
||
| 781 | 12 | } |
|
| 782 | |||
| 783 | /** |
||
| 784 | * @param mixed $value |
||
| 785 | * @param mixed $limit |
||
| 786 | * @param string $message |
||
| 787 | */ |
||
| 788 | 8 | public static function greaterThan($value, $limit, $message = '') |
|
| 789 | { |
||
| 790 | 8 | if ($value <= $limit) { |
|
| 791 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 792 | 4 | $message ?: 'Expected a value greater than %2$s. Got: %s', |
|
| 793 | 4 | static::valueToString($value), |
|
| 794 | 4 | static::valueToString($limit) |
|
| 795 | )); |
||
| 796 | } |
||
| 797 | 4 | } |
|
| 798 | |||
| 799 | /** |
||
| 800 | * @param mixed $value |
||
| 801 | * @param mixed $limit |
||
| 802 | * @param string $message |
||
| 803 | */ |
||
| 804 | 12 | public static function greaterThanEq($value, $limit, $message = '') |
|
| 805 | { |
||
| 806 | 12 | if ($value < $limit) { |
|
| 807 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 808 | 4 | $message ?: 'Expected a value greater than or equal to %2$s. Got: %s', |
|
| 809 | 4 | static::valueToString($value), |
|
| 810 | 4 | static::valueToString($limit) |
|
| 811 | )); |
||
| 812 | } |
||
| 813 | 8 | } |
|
| 814 | |||
| 815 | /** |
||
| 816 | * @param mixed $value |
||
| 817 | * @param mixed $limit |
||
| 818 | * @param string $message |
||
| 819 | */ |
||
| 820 | 8 | public static function lessThan($value, $limit, $message = '') |
|
| 821 | { |
||
| 822 | 8 | if ($value >= $limit) { |
|
| 823 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 824 | 4 | $message ?: 'Expected a value less than %2$s. Got: %s', |
|
| 825 | 4 | static::valueToString($value), |
|
| 826 | 4 | static::valueToString($limit) |
|
| 827 | )); |
||
| 828 | } |
||
| 829 | 4 | } |
|
| 830 | |||
| 831 | /** |
||
| 832 | * @param mixed $value |
||
| 833 | * @param mixed $limit |
||
| 834 | * @param string $message |
||
| 835 | */ |
||
| 836 | 12 | public static function lessThanEq($value, $limit, $message = '') |
|
| 837 | { |
||
| 838 | 12 | if ($value > $limit) { |
|
| 839 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 840 | 4 | $message ?: 'Expected a value less than or equal to %2$s. Got: %s', |
|
| 841 | 4 | static::valueToString($value), |
|
| 842 | 4 | static::valueToString($limit) |
|
| 843 | )); |
||
| 844 | } |
||
| 845 | 8 | } |
|
| 846 | |||
| 847 | /** |
||
| 848 | * Inclusive range, so Assert::(3, 3, 5) passes. |
||
| 849 | * |
||
| 850 | * @param mixed $value |
||
| 851 | * @param mixed min |
||
| 852 | * @param mixed max |
||
| 853 | * @param string $message |
||
| 854 | */ |
||
| 855 | 16 | View Code Duplication | public static function range($value, $min, $max, $message = '') |
| 856 | { |
||
| 857 | 16 | if ($value < $min || $value > $max) { |
|
| 858 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 859 | 8 | $message ?: 'Expected a value between %2$s and %3$s. Got: %s', |
|
| 860 | 8 | static::valueToString($value), |
|
| 861 | 8 | static::valueToString($min), |
|
| 862 | 8 | static::valueToString($max) |
|
| 863 | )); |
||
| 864 | } |
||
| 865 | 8 | } |
|
| 866 | |||
| 867 | /** |
||
| 868 | * Does strict comparison, so Assert::oneOf(3, ['3']) does not pass the assertion. |
||
| 869 | * |
||
| 870 | * @psalm-template ExpectedType |
||
| 871 | * @psalm-param array<ExpectedType> $values |
||
| 872 | * @psalm-assert ExpectedType $value |
||
| 873 | * |
||
| 874 | * @param mixed $value |
||
| 875 | * @param array $values |
||
| 876 | * @param string $message |
||
| 877 | */ |
||
| 878 | 8 | public static function oneOf($value, array $values, $message = '') |
|
| 879 | { |
||
| 880 | 8 | if (!\in_array($value, $values, true)) { |
|
| 881 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 882 | 4 | $message ?: 'Expected one of: %2$s. Got: %s', |
|
| 883 | 4 | static::valueToString($value), |
|
| 884 | 4 | \implode(', ', \array_map(array('static', 'valueToString'), $values)) |
|
| 885 | )); |
||
| 886 | } |
||
| 887 | 4 | } |
|
| 888 | |||
| 889 | /** |
||
| 890 | * @param mixed $value |
||
| 891 | * @param string $subString |
||
| 892 | * @param string $message |
||
| 893 | */ |
||
| 894 | 80 | View Code Duplication | public static function contains($value, $subString, $message = '') |
| 895 | { |
||
| 896 | 80 | if (false === \strpos($value, $subString)) { |
|
| 897 | 32 | static::reportInvalidArgument(\sprintf( |
|
| 898 | 32 | $message ?: 'Expected a value to contain %2$s. Got: %s', |
|
| 899 | 32 | static::valueToString($value), |
|
| 900 | 32 | static::valueToString($subString) |
|
| 901 | )); |
||
| 902 | } |
||
| 903 | 48 | } |
|
| 904 | |||
| 905 | /** |
||
| 906 | * @param mixed $value |
||
| 907 | * @param string $subString |
||
| 908 | * @param string $message |
||
| 909 | */ |
||
| 910 | 80 | View Code Duplication | public static function notContains($value, $subString, $message = '') |
| 911 | { |
||
| 912 | 80 | if (false !== \strpos($value, $subString)) { |
|
| 913 | 48 | static::reportInvalidArgument(\sprintf( |
|
| 914 | 48 | $message ?: '%2$s was not expected to be contained in a value. Got: %s', |
|
| 915 | 48 | static::valueToString($value), |
|
| 916 | 48 | static::valueToString($subString) |
|
| 917 | )); |
||
| 918 | } |
||
| 919 | 32 | } |
|
| 920 | |||
| 921 | /** |
||
| 922 | * @param mixed $value |
||
| 923 | * @param string $message |
||
| 924 | */ |
||
| 925 | 40 | public static function notWhitespaceOnly($value, $message = '') |
|
| 926 | { |
||
| 927 | 40 | if (\preg_match('/^\s*$/', $value)) { |
|
| 928 | 24 | static::reportInvalidArgument(\sprintf( |
|
| 929 | 24 | $message ?: 'Expected a non-whitespace string. Got: %s', |
|
| 930 | 24 | static::valueToString($value) |
|
| 931 | )); |
||
| 932 | } |
||
| 933 | 16 | } |
|
| 934 | |||
| 935 | /** |
||
| 936 | * @param mixed $value |
||
| 937 | * @param string $prefix |
||
| 938 | * @param string $message |
||
| 939 | */ |
||
| 940 | 48 | View Code Duplication | public static function startsWith($value, $prefix, $message = '') |
| 941 | { |
||
| 942 | 48 | if (0 !== \strpos($value, $prefix)) { |
|
| 943 | 32 | static::reportInvalidArgument(\sprintf( |
|
| 944 | 32 | $message ?: 'Expected a value to start with %2$s. Got: %s', |
|
| 945 | 32 | static::valueToString($value), |
|
| 946 | 32 | static::valueToString($prefix) |
|
| 947 | )); |
||
| 948 | } |
||
| 949 | 16 | } |
|
| 950 | |||
| 951 | /** |
||
| 952 | * @param mixed $value |
||
| 953 | * @param string $message |
||
| 954 | */ |
||
| 955 | 24 | public static function startsWithLetter($value, $message = '') |
|
| 956 | { |
||
| 957 | 24 | $valid = isset($value[0]); |
|
| 958 | |||
| 959 | 24 | if ($valid) { |
|
| 960 | 20 | $locale = \setlocale(LC_CTYPE, 0); |
|
| 961 | 20 | \setlocale(LC_CTYPE, 'C'); |
|
| 962 | 20 | $valid = \ctype_alpha($value[0]); |
|
| 963 | 20 | \setlocale(LC_CTYPE, $locale); |
|
| 964 | } |
||
| 965 | |||
| 966 | 24 | if (!$valid) { |
|
| 967 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 968 | 12 | $message ?: 'Expected a value to start with a letter. Got: %s', |
|
| 969 | 12 | static::valueToString($value) |
|
| 970 | )); |
||
| 971 | } |
||
| 972 | 12 | } |
|
| 973 | |||
| 974 | /** |
||
| 975 | * @param mixed $value |
||
| 976 | * @param string $suffix |
||
| 977 | * @param string $message |
||
| 978 | */ |
||
| 979 | 48 | View Code Duplication | public static function endsWith($value, $suffix, $message = '') |
| 980 | { |
||
| 981 | 48 | if ($suffix !== \substr($value, -\strlen($suffix))) { |
|
| 982 | 32 | static::reportInvalidArgument(\sprintf( |
|
| 983 | 32 | $message ?: 'Expected a value to end with %2$s. Got: %s', |
|
| 984 | 32 | static::valueToString($value), |
|
| 985 | 32 | static::valueToString($suffix) |
|
| 986 | )); |
||
| 987 | } |
||
| 988 | 16 | } |
|
| 989 | |||
| 990 | /** |
||
| 991 | * @param mixed $value |
||
| 992 | * @param mixed $pattern |
||
| 993 | * @param string $message |
||
| 994 | */ |
||
| 995 | 12 | public static function regex($value, $pattern, $message = '') |
|
| 1004 | |||
| 1005 | /** |
||
| 1006 | * @param mixed $value |
||
| 1007 | * @param mixed $pattern |
||
| 1008 | * @param string $message |
||
| 1009 | */ |
||
| 1010 | 12 | public static function notRegex($value, $pattern, $message = '') |
|
| 1011 | { |
||
| 1012 | 12 | if (\preg_match($pattern, $value, $matches, PREG_OFFSET_CAPTURE)) { |
|
| 1013 | 4 | static::reportInvalidArgument(\sprintf( |
|
| 1014 | 4 | $message ?: 'The value %s matches the pattern %s (at offset %d).', |
|
| 1015 | 4 | static::valueToString($value), |
|
| 1016 | 4 | static::valueToString($pattern), |
|
| 1017 | 4 | $matches[0][1] |
|
| 1018 | )); |
||
| 1019 | } |
||
| 1020 | 8 | } |
|
| 1021 | |||
| 1022 | /** |
||
| 1023 | * @param mixed $value |
||
| 1024 | * @param string $message |
||
| 1025 | */ |
||
| 1026 | 28 | View Code Duplication | public static function unicodeLetters($value, $message = '') |
| 1027 | { |
||
| 1028 | 28 | static::string($value); |
|
| 1029 | |||
| 1030 | 28 | if (!\preg_match('/^\p{L}+$/u', $value)) { |
|
| 1031 | 16 | static::reportInvalidArgument(\sprintf( |
|
| 1032 | 16 | $message ?: 'Expected a value to contain only Unicode letters. Got: %s', |
|
| 1033 | 16 | static::valueToString($value) |
|
| 1034 | )); |
||
| 1035 | } |
||
| 1036 | 12 | } |
|
| 1037 | |||
| 1038 | /** |
||
| 1039 | * @param mixed $value |
||
| 1040 | * @param string $message |
||
| 1041 | */ |
||
| 1042 | 12 | View Code Duplication | public static function alpha($value, $message = '') |
| 1043 | { |
||
| 1044 | 12 | $locale = \setlocale(LC_CTYPE, 0); |
|
| 1045 | 12 | \setlocale(LC_CTYPE, 'C'); |
|
| 1046 | 12 | $valid = !\ctype_alpha($value); |
|
| 1047 | 12 | \setlocale(LC_CTYPE, $locale); |
|
| 1048 | |||
| 1049 | 12 | if ($valid) { |
|
| 1050 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 1051 | 8 | $message ?: 'Expected a value to contain only letters. Got: %s', |
|
| 1052 | 8 | static::valueToString($value) |
|
| 1053 | )); |
||
| 1054 | } |
||
| 1055 | 4 | } |
|
| 1056 | |||
| 1057 | /** |
||
| 1058 | * @param mixed $value |
||
| 1059 | * @param string $message |
||
| 1060 | */ |
||
| 1061 | 12 | View Code Duplication | public static function digits($value, $message = '') |
| 1062 | { |
||
| 1063 | 12 | $locale = \setlocale(LC_CTYPE, 0); |
|
| 1064 | 12 | \setlocale(LC_CTYPE, 'C'); |
|
| 1065 | 12 | $valid = !\ctype_digit($value); |
|
| 1066 | 12 | \setlocale(LC_CTYPE, $locale); |
|
| 1067 | |||
| 1068 | 12 | if ($valid) { |
|
| 1069 | 8 | static::reportInvalidArgument(\sprintf( |
|
| 1070 | 8 | $message ?: 'Expected a value to contain digits only. Got: %s', |
|
| 1071 | 8 | static::valueToString($value) |
|
| 1072 | )); |
||
| 1073 | } |
||
| 1074 | 4 | } |
|
| 1075 | |||
| 1076 | /** |
||
| 1077 | * @param mixed $value |
||
| 1078 | * @param string $message |
||
| 1079 | */ |
||
| 1080 | 12 | View Code Duplication | public static function alnum($value, $message = '') |
| 1094 | |||
| 1095 | /** |
||
| 1096 | * @param mixed $value |
||
| 1097 | * @param string $message |
||
| 1098 | */ |
||
| 1099 | 16 | View Code Duplication | public static function lower($value, $message = '') |
| 1100 | { |
||
| 1101 | 16 | $locale = \setlocale(LC_CTYPE, 0); |
|
| 1102 | 16 | \setlocale(LC_CTYPE, 'C'); |
|
| 1103 | 16 | $valid = !\ctype_lower($value); |
|
| 1104 | 16 | \setlocale(LC_CTYPE, $locale); |
|
| 1105 | |||
| 1106 | 16 | if ($valid) { |
|
| 1107 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 1108 | 12 | $message ?: 'Expected a value to contain lowercase characters only. Got: %s', |
|
| 1109 | 12 | static::valueToString($value) |
|
| 1110 | )); |
||
| 1111 | } |
||
| 1112 | 4 | } |
|
| 1113 | |||
| 1114 | /** |
||
| 1115 | * @param mixed $value |
||
| 1116 | * @param string $message |
||
| 1117 | */ |
||
| 1118 | 16 | View Code Duplication | public static function upper($value, $message = '') |
| 1119 | { |
||
| 1120 | 16 | $locale = \setlocale(LC_CTYPE, 0); |
|
| 1121 | 16 | \setlocale(LC_CTYPE, 'C'); |
|
| 1122 | 16 | $valid = !\ctype_upper($value); |
|
| 1123 | 16 | \setlocale(LC_CTYPE, $locale); |
|
| 1124 | |||
| 1125 | 16 | if ($valid) { |
|
| 1126 | 12 | static::reportInvalidArgument(\sprintf( |
|
| 1127 | 12 | $message ?: 'Expected a value to contain uppercase characters only. Got: %s', |
|
| 1128 | 12 | static::valueToString($value) |
|
| 1129 | )); |
||
| 1130 | } |
||
| 1131 | 4 | } |
|
| 1132 | |||
| 1133 | /** |
||
| 1134 | * @param mixed $value |
||
| 1135 | * @param mixed $length |
||
| 1136 | * @param string $message |
||
| 1137 | */ |
||
| 1138 | 36 | public static function length($value, $length, $message = '') |
|
| 1139 | { |
||
| 1140 | 36 | if ($length !== static::strlen($value)) { |
|
| 1141 | 24 | static::reportInvalidArgument(\sprintf( |
|
| 1142 | 24 | $message ?: 'Expected a value to contain %2$s characters. Got: %s', |
|
| 1143 | 24 | static::valueToString($value), |
|
| 1144 | 24 | $length |
|
| 1148 | |||
| 1149 | /** |
||
| 1150 | * Inclusive min. |
||
| 1151 | * |
||
| 1152 | * @param mixed $value |
||
| 1153 | * @param mixed $min |
||
| 1154 | * @param string $message |
||
| 1155 | */ |
||
| 1156 | 36 | public static function minLength($value, $min, $message = '') |
|
| 1166 | |||
| 1167 | /** |
||
| 1168 | * Inclusive max. |
||
| 1169 | * |
||
| 1170 | * @param mixed $value |
||
| 1171 | * @param mixed $max |
||
| 1172 | * @param string $message |
||
| 1173 | */ |
||
| 1174 | 36 | public static function maxLength($value, $max, $message = '') |
|
| 1184 | |||
| 1185 | /** |
||
| 1186 | * Inclusive , so Assert::lengthBetween('asd', 3, 5); passes the assertion. |
||
| 1187 | * |
||
| 1188 | * @param mixed $value |
||
| 1189 | * @param mixed $min |
||
| 1190 | * @param mixed $max |
||
| 1191 | * @param string $message |
||
| 1192 | */ |
||
| 1193 | 60 | View Code Duplication | public static function lengthBetween($value, $min, $max, $message = '') |
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Will also pass if $value is a directory, use Assert::file() instead if you need to be sure it is a file. |
||
| 1209 | * |
||
| 1210 | * @param mixed $value |
||
| 1211 | * @param string $message |
||
| 1212 | */ |
||
| 1213 | 36 | View Code Duplication | public static function fileExists($value, $message = '') |
| 1224 | |||
| 1225 | /** |
||
| 1226 | * @param mixed $value |
||
| 1227 | * @param string $message |
||
| 1228 | */ |
||
| 1229 | 12 | View Code Duplication | public static function file($value, $message = '') |
| 1240 | |||
| 1241 | /** |
||
| 1242 | * @param mixed $value |
||
| 1243 | * @param string $message |
||
| 1244 | */ |
||
| 1245 | 12 | View Code Duplication | public static function directory($value, $message = '') |
| 1256 | |||
| 1257 | /** |
||
| 1258 | * @param mixed $value |
||
| 1259 | * @param string $message |
||
| 1260 | */ |
||
| 1261 | public static function readable($value, $message = '') |
||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * @param mixed $value |
||
| 1273 | * @param string $message |
||
| 1274 | */ |
||
| 1275 | public static function writable($value, $message = '') |
||
| 1284 | |||
| 1285 | /** |
||
| 1286 | * @psalm-assert class-string $value |
||
| 1287 | * |
||
| 1288 | * @param mixed $value |
||
| 1289 | * @param string $message |
||
| 1290 | */ |
||
| 1291 | 8 | public static function classExists($value, $message = '') |
|
| 1300 | |||
| 1301 | /** |
||
| 1302 | * @param mixed $value |
||
| 1303 | * @param string|object $class |
||
| 1304 | * @param string $message |
||
| 1305 | */ |
||
| 1306 | 8 | public static function subclassOf($value, $class, $message = '') |
|
| 1316 | |||
| 1317 | /** |
||
| 1318 | * @psalm-assert class-string $value |
||
| 1319 | * |
||
| 1320 | * @param mixed $value |
||
| 1321 | * @param string $message |
||
| 1322 | */ |
||
| 1323 | 8 | public static function interfaceExists($value, $message = '') |
|
| 1332 | |||
| 1333 | /** |
||
| 1334 | * @param mixed $value |
||
| 1335 | * @param mixed $interface |
||
| 1336 | * @param string $message |
||
| 1337 | */ |
||
| 1338 | 8 | View Code Duplication | public static function implementsInterface($value, $interface, $message = '') |
| 1348 | |||
| 1349 | /** |
||
| 1350 | * @param string|object $classOrObject |
||
| 1351 | * @param mixed $property |
||
| 1352 | * @param string $message |
||
| 1353 | */ |
||
| 1354 | 12 | View Code Duplication | public static function propertyExists($classOrObject, $property, $message = '') |
| 1363 | |||
| 1364 | /** |
||
| 1365 | * @param string|object $classOrObject |
||
| 1366 | * @param mixed $property |
||
| 1367 | * @param string $message |
||
| 1368 | */ |
||
| 1369 | 12 | View Code Duplication | public static function propertyNotExists($classOrObject, $property, $message = '') |
| 1378 | |||
| 1379 | /** |
||
| 1380 | * @param string|object $classOrObject |
||
| 1381 | * @param mixed $method |
||
| 1382 | * @param string $message |
||
| 1383 | */ |
||
| 1384 | 27 | View Code Duplication | public static function methodExists($classOrObject, $method, $message = '') |
| 1393 | |||
| 1394 | /** |
||
| 1395 | * @param string|object $classOrObject |
||
| 1396 | * @param mixed $method |
||
| 1397 | * @param string $message |
||
| 1398 | */ |
||
| 1399 | 27 | View Code Duplication | public static function methodNotExists($classOrObject, $method, $message = '') |
| 1408 | |||
| 1409 | /** |
||
| 1410 | * @param array $array |
||
| 1411 | * @param string|int $key |
||
| 1412 | * @param string $message |
||
| 1413 | */ |
||
| 1414 | 12 | View Code Duplication | public static function keyExists($array, $key, $message = '') |
| 1423 | |||
| 1424 | /** |
||
| 1425 | * @param array $array |
||
| 1426 | * @param string|int $key |
||
| 1427 | * @param string $message |
||
| 1428 | */ |
||
| 1429 | 12 | View Code Duplication | public static function keyNotExists($array, $key, $message = '') |
| 1438 | |||
| 1439 | /** |
||
| 1440 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1441 | * |
||
| 1442 | * @param mixed $array |
||
| 1443 | * @param mixed $number |
||
| 1444 | * @param string $message |
||
| 1445 | */ |
||
| 1446 | 8 | public static function count($array, $number, $message = '') |
|
| 1454 | |||
| 1455 | /** |
||
| 1456 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1457 | * |
||
| 1458 | * @param mixed $array |
||
| 1459 | * @param mixed $min |
||
| 1460 | * @param string $message |
||
| 1461 | */ |
||
| 1462 | 12 | View Code Duplication | public static function minCount($array, $min, $message = '') |
| 1472 | |||
| 1473 | /** |
||
| 1474 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1475 | * |
||
| 1476 | * @param mixed $array |
||
| 1477 | * @param mixed $max |
||
| 1478 | * @param string $message |
||
| 1479 | */ |
||
| 1480 | 12 | View Code Duplication | public static function maxCount($array, $max, $message = '') |
| 1490 | |||
| 1491 | /** |
||
| 1492 | * Does not check if $array is countable, this can generate a warning on php versions after 7.2. |
||
| 1493 | * |
||
| 1494 | * @param mixed $array |
||
| 1495 | * @param mixed $min |
||
| 1496 | * @param mixed $max |
||
| 1497 | * @param string $message |
||
| 1498 | */ |
||
| 1499 | 20 | public static function countBetween($array, $min, $max, $message = '') |
|
| 1512 | |||
| 1513 | /** |
||
| 1514 | * @param mixed $array |
||
| 1515 | * @param string $message |
||
| 1516 | */ |
||
| 1517 | 24 | public static function isList($array, $message = '') |
|
| 1525 | |||
| 1526 | /** |
||
| 1527 | * @param mixed $array |
||
| 1528 | * @param string $message |
||
| 1529 | */ |
||
| 1530 | 16 | public static function isMap($array, $message = '') |
|
| 1544 | |||
| 1545 | /** |
||
| 1546 | * @param mixed $value |
||
| 1547 | * @param string $message |
||
| 1548 | */ |
||
| 1549 | 56 | public static function uuid($value, $message = '') |
|
| 1566 | |||
| 1567 | /** |
||
| 1568 | * @param Closure $expression |
||
| 1569 | * @param string|object $class |
||
| 1570 | * @param string $message |
||
| 1571 | */ |
||
| 1572 | 24 | public static function throws(Closure $expression, $class = 'Exception', $message = '') |
|
| 1598 | |||
| 1599 | 1383 | public static function __callStatic($name, $arguments) |
|
| 1627 | |||
| 1628 | /** |
||
| 1629 | * @param mixed $value |
||
| 1630 | * |
||
| 1631 | * @return string |
||
| 1632 | */ |
||
| 1633 | 694 | protected static function valueToString($value) |
|
| 1669 | |||
| 1670 | /** |
||
| 1671 | * @param mixed $value |
||
| 1672 | * |
||
| 1673 | * @return string |
||
| 1674 | */ |
||
| 1675 | 169 | protected static function typeToString($value) |
|
| 1679 | |||
| 1680 | 168 | protected static function strlen($value) |
|
| 1692 | |||
| 1693 | /** |
||
| 1694 | * @param string $message |
||
| 1695 | */ |
||
| 1696 | 918 | protected static function reportInvalidArgument($message) |
|
| 1700 | |||
| 1701 | private function __construct() |
||
| 1704 | } |
||
| 1705 |