| Total Lines | 567 | 
| Code Lines | 413 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php | ||
| 514 | public function skipOnEmptyDataProvider(): array | ||
| 515 |     { | ||
| 516 | $translator = (new TranslatorFactory())->create(); | ||
| 517 | $validator = ValidatorFactory::make(); | ||
| 518 | $rules = [ | ||
| 519 | 'name' => [new HasLength(min: 8)], | ||
| 520 | 'age' => [new Number(asInteger: true, min: 18)], | ||
| 521 | ]; | ||
| 522 | $stringLessThanMinMessage = 'This value must contain at least 8 characters.'; | ||
| 523 | $incorrectNumberMessage = 'The allowed types are integer, float and string.'; | ||
| 524 | $intMessage = 'Value must be an integer.'; | ||
| 525 | $intLessThanMinMessage = 'Value must be no less than 18.'; | ||
| 526 | |||
| 527 | return [ | ||
| 528 | 'rule / validator, skipOnEmpty: false, value not passed' => [ | ||
| 529 | $validator, | ||
| 530 | new ArrayDataSet([ | ||
| 531 | 'name' => 'Dmitriy', | ||
| 532 | ]), | ||
| 533 | $rules, | ||
| 534 | [ | ||
| 535 | new Error($stringLessThanMinMessage, [ | ||
| 536 | 'min' => 8, | ||
| 537 | 'attribute' => 'name', | ||
| 538 | 'number' => 7, | ||
| 539 | ], ['name']), | ||
| 540 | new Error($incorrectNumberMessage, [ | ||
| 541 | 'attribute' => 'age', | ||
| 542 | 'type' => 'null', | ||
| 543 | ], ['age']), | ||
| 544 | ], | ||
| 545 | ], | ||
| 546 | 'rule / validator, skipOnEmpty: false, value is empty' => [ | ||
| 547 | $validator, | ||
| 548 | new ArrayDataSet([ | ||
| 549 | 'name' => 'Dmitriy', | ||
| 550 | 'age' => null, | ||
| 551 | ]), | ||
| 552 | $rules, | ||
| 553 | [ | ||
| 554 | new Error($stringLessThanMinMessage, [ | ||
| 555 | 'min' => 8, | ||
| 556 | 'attribute' => 'name', | ||
| 557 | 'number' => 7, | ||
| 558 | ], ['name']), | ||
| 559 | new Error($incorrectNumberMessage, [ | ||
| 560 | 'attribute' => 'age', | ||
| 561 | 'type' => 'null', | ||
| 562 | ], ['age']), | ||
| 563 | ], | ||
| 564 | ], | ||
| 565 | 'rule / validator, skipOnEmpty: false, value is not empty' => [ | ||
| 566 | $validator, | ||
| 567 | new ArrayDataSet([ | ||
| 568 | 'name' => 'Dmitriy', | ||
| 569 | 'age' => 17, | ||
| 570 | ]), | ||
| 571 | $rules, | ||
| 572 | [ | ||
| 573 | new Error($stringLessThanMinMessage, [ | ||
| 574 | 'min' => 8, | ||
| 575 | 'attribute' => 'name', | ||
| 576 | 'number' => 7, | ||
| 577 | ], ['name']), | ||
| 578 | new Error($intLessThanMinMessage, [ | ||
| 579 | 'min' => 18, | ||
| 580 | 'attribute' => 'age', | ||
| 581 | 'value' => 17, | ||
| 582 | ], ['age']), | ||
| 583 | ], | ||
| 584 | ], | ||
| 585 | |||
| 586 | 'rule, skipOnEmpty: true, value not passed' => [ | ||
| 587 | $validator, | ||
| 588 | new ArrayDataSet([ | ||
| 589 | 'name' => 'Dmitriy', | ||
| 590 | ]), | ||
| 591 | [ | ||
| 592 | 'name' => [new HasLength(min: 8)], | ||
| 593 | 'age' => [new Number(asInteger: true, min: 18, skipOnEmpty: true)], | ||
| 594 | ], | ||
| 595 | [ | ||
| 596 | new Error($stringLessThanMinMessage, [ | ||
| 597 | 'min' => 8, | ||
| 598 | 'attribute' => 'name', | ||
| 599 | 'number' => 7, | ||
| 600 | ], ['name']), | ||
| 601 | ], | ||
| 602 | ], | ||
| 603 | 'rule, skipOnEmpty: true, value is empty (null)' => [ | ||
| 604 | $validator, | ||
| 605 | new ArrayDataSet([ | ||
| 606 | 'name' => 'Dmitriy', | ||
| 607 | 'age' => null, | ||
| 608 | ]), | ||
| 609 | [ | ||
| 610 | 'name' => [new HasLength(min: 8)], | ||
| 611 | 'age' => [new Number(asInteger: true, min: 18, skipOnEmpty: true)], | ||
| 612 | ], | ||
| 613 | [ | ||
| 614 | new Error($stringLessThanMinMessage, [ | ||
| 615 | 'min' => 8, | ||
| 616 | 'attribute' => 'name', | ||
| 617 | 'number' => 7, | ||
| 618 | ], ['name']), | ||
| 619 | ], | ||
| 620 | ], | ||
| 621 | 'rule, skipOnEmpty: true, value is empty (empty string after trimming), trimString is false' => [ | ||
| 622 | $validator, | ||
| 623 | new ArrayDataSet([ | ||
| 624 | 'name' => ' ', | ||
| 625 | 'age' => 17, | ||
| 626 | ]), | ||
| 627 | [ | ||
| 628 | 'name' => [new HasLength(min: 8, skipOnEmpty: true)], | ||
| 629 | 'age' => [new Number(asInteger: true, min: 18)], | ||
| 630 | ], | ||
| 631 | [ | ||
| 632 | new Error($stringLessThanMinMessage, [ | ||
| 633 | 'min' => 8, | ||
| 634 | 'attribute' => 'name', | ||
| 635 | 'number' => 1, | ||
| 636 | ], ['name']), | ||
| 637 | new Error($intLessThanMinMessage, [ | ||
| 638 | 'min' => 18, | ||
| 639 | 'attribute' => 'age', | ||
| 640 | 'value' => 17, | ||
| 641 | ], ['age']), | ||
| 642 | ], | ||
| 643 | ], | ||
| 644 | 'rule, skipOnEmpty: SkipOnEmpty, value is empty (empty string after trimming), trimString is true' => [ | ||
| 645 | $validator, | ||
| 646 | new ArrayDataSet([ | ||
| 647 | 'name' => ' ', | ||
| 648 | 'age' => 17, | ||
| 649 | ]), | ||
| 650 | [ | ||
| 651 | 'name' => [new HasLength(min: 8, skipOnEmpty: new WhenEmpty(trimString: true))], | ||
| 652 | 'age' => [new Number(asInteger: true, min: 18)], | ||
| 653 | ], | ||
| 654 | [ | ||
| 655 | new Error($intLessThanMinMessage, [ | ||
| 656 | 'min' => 18, | ||
| 657 | 'attribute' => 'age', | ||
| 658 | 'value' => 17, | ||
| 659 | ], ['age']), | ||
| 660 | ], | ||
| 661 | ], | ||
| 662 | 'rule, skipOnEmpty: true, value is not empty' => [ | ||
| 663 | $validator, | ||
| 664 | new ArrayDataSet([ | ||
| 665 | 'name' => 'Dmitriy', | ||
| 666 | 'age' => 17, | ||
| 667 | ]), | ||
| 668 | [ | ||
| 669 | 'name' => [new HasLength(min: 8)], | ||
| 670 | 'age' => [new Number(asInteger: true, min: 18, skipOnEmpty: true)], | ||
| 671 | ], | ||
| 672 | [ | ||
| 673 | new Error($stringLessThanMinMessage, [ | ||
| 674 | 'min' => 8, | ||
| 675 | 'attribute' => 'name', | ||
| 676 | 'number' => 7, | ||
| 677 | ], ['name']), | ||
| 678 | new Error($intLessThanMinMessage, [ | ||
| 679 | 'min' => 18, | ||
| 680 | 'attribute' => 'age', | ||
| 681 | 'value' => 17, | ||
| 682 | ], ['age']), | ||
| 683 | ], | ||
| 684 | ], | ||
| 685 | |||
| 686 | 'rule, skipOnEmpty: SkipOnNull, value not passed' => [ | ||
| 687 | $validator, | ||
| 688 | new ArrayDataSet([ | ||
| 689 | 'name' => 'Dmitriy', | ||
| 690 | ]), | ||
| 691 | [ | ||
| 692 | 'name' => [new HasLength(min: 8)], | ||
| 693 | 'age' => [new Number(asInteger: true, min: 18, skipOnEmpty: new WhenNull())], | ||
| 694 | ], | ||
| 695 | [ | ||
| 696 | new Error($stringLessThanMinMessage, [ | ||
| 697 | 'min' => 8, | ||
| 698 | 'attribute' => 'name', | ||
| 699 | 'number' => 7, | ||
| 700 | ], ['name']), | ||
| 701 | ], | ||
| 702 | ], | ||
| 703 | 'rule, skipOnEmpty: SkipOnNull, value is empty' => [ | ||
| 704 | $validator, | ||
| 705 | new ArrayDataSet([ | ||
| 706 | 'name' => 'Dmitriy', | ||
| 707 | 'age' => null, | ||
| 708 | ]), | ||
| 709 | [ | ||
| 710 | 'name' => [new HasLength(min: 8)], | ||
| 711 | 'age' => [new Number(asInteger: true, min: 18, skipOnEmpty: new WhenNull())], | ||
| 712 | ], | ||
| 713 | [ | ||
| 714 | new Error($stringLessThanMinMessage, [ | ||
| 715 | 'min' => 8, | ||
| 716 | 'attribute' => 'name', | ||
| 717 | 'number' => 7, | ||
| 718 | ], ['name']), | ||
| 719 | ], | ||
| 720 | ], | ||
| 721 | 'rule, skipOnEmpty: SkipOnNull, value is not empty' => [ | ||
| 722 | $validator, | ||
| 723 | new ArrayDataSet([ | ||
| 724 | 'name' => 'Dmitriy', | ||
| 725 | 'age' => 17, | ||
| 726 | ]), | ||
| 727 | [ | ||
| 728 | 'name' => [new HasLength(min: 8)], | ||
| 729 | 'age' => [new Number(asInteger: true, min: 18, skipOnEmpty: new WhenNull())], | ||
| 730 | ], | ||
| 731 | [ | ||
| 732 | new Error($stringLessThanMinMessage, [ | ||
| 733 | 'min' => 8, | ||
| 734 | 'attribute' => 'name', | ||
| 735 | 'number' => 7, | ||
| 736 | ], ['name']), | ||
| 737 | new Error($intLessThanMinMessage, [ | ||
| 738 | 'min' => 18, | ||
| 739 | 'attribute' => 'age', | ||
| 740 | 'value' => 17, | ||
| 741 | ], ['age']), | ||
| 742 | ], | ||
| 743 | ], | ||
| 744 | 'rule, skipOnEmpty: SkipOnNull, value is not empty (empty string)' => [ | ||
| 745 | $validator, | ||
| 746 | new ArrayDataSet([ | ||
| 747 | 'name' => 'Dmitriy', | ||
| 748 | 'age' => '', | ||
| 749 | ]), | ||
| 750 | [ | ||
| 751 | 'name' => [new HasLength(min: 8)], | ||
| 752 | 'age' => [new Number(asInteger: true, min: 18, skipOnEmpty: new WhenNull())], | ||
| 753 | ], | ||
| 754 | [ | ||
| 755 | new Error($stringLessThanMinMessage, [ | ||
| 756 | 'min' => 8, | ||
| 757 | 'attribute' => 'name', | ||
| 758 | 'number' => 7, | ||
| 759 | ], ['name']), | ||
| 760 | new Error($intMessage, [ | ||
| 761 | 'attribute' => 'age', | ||
| 762 | 'value' => '', | ||
| 763 | ], ['age']), | ||
| 764 | ], | ||
| 765 | ], | ||
| 766 | |||
| 767 | 'rule, skipOnEmpty: custom callback, value not passed' => [ | ||
| 768 | $validator, | ||
| 769 | new ArrayDataSet([ | ||
| 770 | 'name' => 'Dmitriy', | ||
| 771 | ]), | ||
| 772 | [ | ||
| 773 | 'name' => [new HasLength(min: 8)], | ||
| 774 | 'age' => [ | ||
| 775 | new Number( | ||
| 776 | asInteger: true, | ||
| 777 | min: 18, | ||
| 778 | skipOnEmpty: static fn (mixed $value, bool $isAttributeMissing): bool => $value === 0 | ||
| 779 | ), | ||
| 780 | ], | ||
| 781 | ], | ||
| 782 | [ | ||
| 783 | new Error($stringLessThanMinMessage, [ | ||
| 784 | 'min' => 8, | ||
| 785 | 'attribute' => 'name', | ||
| 786 | 'number' => 7, | ||
| 787 | ], ['name']), | ||
| 788 | new Error($incorrectNumberMessage, [ | ||
| 789 | 'attribute' => 'age', | ||
| 790 | 'type' => 'null', | ||
| 791 | ], ['age']), | ||
| 792 | ], | ||
| 793 | ], | ||
| 794 | 'rule, skipOnEmpty: custom callback, value is empty' => [ | ||
| 795 | $validator, | ||
| 796 | new ArrayDataSet([ | ||
| 797 | 'name' => 'Dmitriy', | ||
| 798 | 'age' => 0, | ||
| 799 | ]), | ||
| 800 | [ | ||
| 801 | 'name' => [new HasLength(min: 8)], | ||
| 802 | 'age' => [ | ||
| 803 | new Number( | ||
| 804 | asInteger: true, | ||
| 805 | min: 18, | ||
| 806 | skipOnEmpty: static fn (mixed $value, bool $isAttributeMissing): bool => $value === 0 | ||
| 807 | ), | ||
| 808 | ], | ||
| 809 | ], | ||
| 810 | [ | ||
| 811 | new Error($stringLessThanMinMessage, [ | ||
| 812 | 'min' => 8, | ||
| 813 | 'attribute' => 'name', | ||
| 814 | 'number' => 7, | ||
| 815 | ], ['name']), | ||
| 816 | ], | ||
| 817 | ], | ||
| 818 | 'rule, skipOnEmpty, custom callback, value is not empty' => [ | ||
| 819 | $validator, | ||
| 820 | new ArrayDataSet([ | ||
| 821 | 'name' => 'Dmitriy', | ||
| 822 | 'age' => 17, | ||
| 823 | ]), | ||
| 824 | [ | ||
| 825 | 'name' => [new HasLength(min: 8)], | ||
| 826 | 'age' => [ | ||
| 827 | new Number( | ||
| 828 | asInteger: true, | ||
| 829 | min: 18, | ||
| 830 | skipOnEmpty: static fn (mixed $value, bool $isAttributeMissing): bool => $value === 0 | ||
| 831 | ), | ||
| 832 | ], | ||
| 833 | ], | ||
| 834 | [ | ||
| 835 | new Error($stringLessThanMinMessage, [ | ||
| 836 | 'min' => 8, | ||
| 837 | 'attribute' => 'name', | ||
| 838 | 'number' => 7, | ||
| 839 | ], ['name']), | ||
| 840 | new Error($intLessThanMinMessage, [ | ||
| 841 | 'min' => 18, | ||
| 842 | 'attribute' => 'age', | ||
| 843 | 'value' => 17, | ||
| 844 | ], ['age']), | ||
| 845 | ], | ||
| 846 | ], | ||
| 847 | 'rule, skipOnEmpty, custom callback, value is not empty (null)' => [ | ||
| 848 | $validator, | ||
| 849 | new ArrayDataSet([ | ||
| 850 | 'name' => 'Dmitriy', | ||
| 851 | 'age' => null, | ||
| 852 | ]), | ||
| 853 | [ | ||
| 854 | 'name' => [new HasLength(min: 8)], | ||
| 855 | 'age' => [ | ||
| 856 | new Number( | ||
| 857 | asInteger: true, | ||
| 858 | min: 18, | ||
| 859 | skipOnEmpty: static fn (mixed $value, bool $isAttributeMissing): bool => $value === 0 | ||
| 860 | ), | ||
| 861 | ], | ||
| 862 | ], | ||
| 863 | [ | ||
| 864 | new Error($stringLessThanMinMessage, [ | ||
| 865 | 'min' => 8, | ||
| 866 | 'attribute' => 'name', | ||
| 867 | 'number' => 7, | ||
| 868 | ], ['name']), | ||
| 869 | new Error($incorrectNumberMessage, [ | ||
| 870 | 'attribute' => 'age', | ||
| 871 | 'type' => 'null', | ||
| 872 | ], ['age']), | ||
| 873 | ], | ||
| 874 | ], | ||
| 875 | |||
| 876 | 'validator, skipOnEmpty: true, value not passed' => [ | ||
| 877 | new Validator(new SimpleRuleHandlerContainer(), $translator, defaultSkipOnEmpty: true), | ||
| 878 | new ArrayDataSet([ | ||
| 879 | 'name' => 'Dmitriy', | ||
| 880 | ]), | ||
| 881 | $rules, | ||
| 882 | [ | ||
| 883 | new Error($stringLessThanMinMessage, [ | ||
| 884 | 'min' => 8, | ||
| 885 | 'attribute' => 'name', | ||
| 886 | 'number' => 7, | ||
| 887 | ], ['name']), | ||
| 888 | ], | ||
| 889 | ], | ||
| 890 | 'validator, skipOnEmpty: true, value is empty' => [ | ||
| 891 | new Validator(new SimpleRuleHandlerContainer(), $translator, defaultSkipOnEmpty: true), | ||
| 892 | new ArrayDataSet([ | ||
| 893 | 'name' => 'Dmitriy', | ||
| 894 | 'age' => null, | ||
| 895 | ]), | ||
| 896 | $rules, | ||
| 897 | [ | ||
| 898 | new Error($stringLessThanMinMessage, [ | ||
| 899 | 'min' => 8, | ||
| 900 | 'attribute' => 'name', | ||
| 901 | 'number' => 7, | ||
| 902 | ], ['name']), | ||
| 903 | ], | ||
| 904 | ], | ||
| 905 | 'validator, skipOnEmpty: true, value is not empty' => [ | ||
| 906 | new Validator(new SimpleRuleHandlerContainer(), $translator, defaultSkipOnEmpty: true), | ||
| 907 | new ArrayDataSet([ | ||
| 908 | 'name' => 'Dmitriy', | ||
| 909 | 'age' => 17, | ||
| 910 | ]), | ||
| 911 | $rules, | ||
| 912 | [ | ||
| 913 | new Error($stringLessThanMinMessage, [ | ||
| 914 | 'min' => 8, | ||
| 915 | 'attribute' => 'name', | ||
| 916 | 'number' => 7, | ||
| 917 | ], ['name']), | ||
| 918 | new Error($intLessThanMinMessage, [ | ||
| 919 | 'min' => 18, | ||
| 920 | 'attribute' => 'age', | ||
| 921 | 'value' => 17, | ||
| 922 | ], ['age']), | ||
| 923 | ], | ||
| 924 | ], | ||
| 925 | |||
| 926 | 'validator, skipOnEmpty: SkipOnNull, value not passed' => [ | ||
| 927 | new Validator(new SimpleRuleHandlerContainer(), $translator, defaultSkipOnEmpty: new WhenNull()), | ||
| 928 | new ArrayDataSet([ | ||
| 929 | 'name' => 'Dmitriy', | ||
| 930 | ]), | ||
| 931 | $rules, | ||
| 932 | [ | ||
| 933 | new Error($stringLessThanMinMessage, [ | ||
| 934 | 'min' => 8, | ||
| 935 | 'attribute' => 'name', | ||
| 936 | 'number' => 7, | ||
| 937 | ], ['name']), | ||
| 938 | ], | ||
| 939 | ], | ||
| 940 | 'validator, skipOnEmpty: SkipOnNull, value is empty' => [ | ||
| 941 | new Validator(new SimpleRuleHandlerContainer(), $translator, defaultSkipOnEmpty: new WhenNull()), | ||
| 942 | new ArrayDataSet([ | ||
| 943 | 'name' => 'Dmitriy', | ||
| 944 | 'age' => null, | ||
| 945 | ]), | ||
| 946 | $rules, | ||
| 947 | [ | ||
| 948 | new Error($stringLessThanMinMessage, [ | ||
| 949 | 'min' => 8, | ||
| 950 | 'attribute' => 'name', | ||
| 951 | 'number' => 7, | ||
| 952 | ], ['name']), | ||
| 953 | ], | ||
| 954 | ], | ||
| 955 | 'validator, skipOnEmpty: SkipOnNull, value is not empty' => [ | ||
| 956 | new Validator(new SimpleRuleHandlerContainer(), $translator, defaultSkipOnEmpty: new WhenNull()), | ||
| 957 | new ArrayDataSet([ | ||
| 958 | 'name' => 'Dmitriy', | ||
| 959 | 'age' => 17, | ||
| 960 | ]), | ||
| 961 | $rules, | ||
| 962 | [ | ||
| 963 | new Error($stringLessThanMinMessage, [ | ||
| 964 | 'min' => 8, | ||
| 965 | 'attribute' => 'name', | ||
| 966 | 'number' => 7, | ||
| 967 | ], ['name']), | ||
| 968 | new Error($intLessThanMinMessage, [ | ||
| 969 | 'min' => 18, | ||
| 970 | 'attribute' => 'age', | ||
| 971 | 'value' => 17, | ||
| 972 | ], ['age']), | ||
| 973 | ], | ||
| 974 | ], | ||
| 975 | 'validator, skipOnEmpty: SkipOnNull, value is not empty (empty string)' => [ | ||
| 976 | new Validator(new SimpleRuleHandlerContainer(), $translator, defaultSkipOnEmpty: new WhenNull()), | ||
| 977 | new ArrayDataSet([ | ||
| 978 | 'name' => 'Dmitriy', | ||
| 979 | 'age' => '', | ||
| 980 | ]), | ||
| 981 | $rules, | ||
| 982 | [ | ||
| 983 | new Error($stringLessThanMinMessage, [ | ||
| 984 | 'min' => 8, | ||
| 985 | 'attribute' => 'name', | ||
| 986 | 'number' => 7, | ||
| 987 | ], ['name']), | ||
| 988 | new Error($intMessage, [ | ||
| 989 | 'attribute' => 'age', | ||
| 990 | 'value' => '', | ||
| 991 | ], ['age']), | ||
| 992 | ], | ||
| 993 | ], | ||
| 994 | |||
| 995 | 'validator, skipOnEmpty: custom callback, value not passed' => [ | ||
| 996 | new Validator( | ||
| 997 | new SimpleRuleHandlerContainer(), | ||
| 998 | $translator, | ||
| 999 | defaultSkipOnEmpty: static fn (mixed $value, bool $isAttributeMissing): bool => $value === 0 | ||
| 1000 | ), | ||
| 1001 | new ArrayDataSet([ | ||
| 1002 | 'name' => 'Dmitriy', | ||
| 1003 | ]), | ||
| 1004 | $rules, | ||
| 1005 | [ | ||
| 1006 | new Error($stringLessThanMinMessage, [ | ||
| 1007 | 'min' => 8, | ||
| 1008 | 'attribute' => 'name', | ||
| 1009 | 'number' => 7, | ||
| 1010 | ], ['name']), | ||
| 1011 | new Error($incorrectNumberMessage, [ | ||
| 1012 | 'attribute' => 'age', | ||
| 1013 | 'type' => 'null', | ||
| 1014 | ], ['age']), | ||
| 1015 | ], | ||
| 1016 | ], | ||
| 1017 | 'validator, skipOnEmpty: custom callback, value is empty' => [ | ||
| 1018 | new Validator( | ||
| 1019 | new SimpleRuleHandlerContainer(), | ||
| 1020 | $translator, | ||
| 1021 | defaultSkipOnEmpty: static fn (mixed $value, bool $isAttributeMissing): bool => $value === 0 | ||
| 1022 | ), | ||
| 1023 | new ArrayDataSet([ | ||
| 1024 | 'name' => 'Dmitriy', | ||
| 1025 | 'age' => 0, | ||
| 1026 | ]), | ||
| 1027 | $rules, | ||
| 1028 | [ | ||
| 1029 | new Error($stringLessThanMinMessage, [ | ||
| 1030 | 'min' => 8, | ||
| 1031 | 'attribute' => 'name', | ||
| 1032 | 'number' => 7, | ||
| 1033 | ], ['name']), | ||
| 1034 | ], | ||
| 1035 | ], | ||
| 1036 | 'validator, skipOnEmpty: custom callback, value is not empty' => [ | ||
| 1037 | new Validator( | ||
| 1038 | new SimpleRuleHandlerContainer(), | ||
| 1039 | $translator, | ||
| 1040 | defaultSkipOnEmpty: static fn (mixed $value, bool $isAttributeMissing): bool => $value === 0 | ||
| 1041 | ), | ||
| 1042 | new ArrayDataSet([ | ||
| 1043 | 'name' => 'Dmitriy', | ||
| 1044 | 'age' => 17, | ||
| 1045 | ]), | ||
| 1046 | $rules, | ||
| 1047 | [ | ||
| 1048 | new Error($stringLessThanMinMessage, [ | ||
| 1049 | 'min' => 8, | ||
| 1050 | 'attribute' => 'name', | ||
| 1051 | 'number' => 7, | ||
| 1052 | ], ['name']), | ||
| 1053 | new Error($intLessThanMinMessage, [ | ||
| 1054 | 'min' => 18, | ||
| 1055 | 'attribute' => 'age', | ||
| 1056 | 'value' => 17, | ||
| 1057 | ], ['age']), | ||
| 1058 | ], | ||
| 1059 | ], | ||
| 1060 | 'validator, skipOnEmpty: custom callback, value is not empty (null)' => [ | ||
| 1061 | new Validator( | ||
| 1062 | new SimpleRuleHandlerContainer(), | ||
| 1063 | $translator, | ||
| 1064 | defaultSkipOnEmpty: static fn (mixed $value, bool $isAttributeMissing): bool => $value === 0 | ||
| 1065 | ), | ||
| 1066 | new ArrayDataSet([ | ||
| 1067 | 'name' => 'Dmitriy', | ||
| 1068 | 'age' => null, | ||
| 1069 | ]), | ||
| 1070 | $rules, | ||
| 1071 | [ | ||
| 1072 | new Error($stringLessThanMinMessage, [ | ||
| 1073 | 'min' => 8, | ||
| 1074 | 'attribute' => 'name', | ||
| 1075 | 'number' => 7, | ||
| 1076 | ], ['name']), | ||
| 1077 | new Error($incorrectNumberMessage, [ | ||
| 1078 | 'attribute' => 'age', | ||
| 1079 | 'type' => 'null', | ||
| 1080 | ], ['age']), | ||
| 1081 | ], | ||
| 1334 | 
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.