@@ -30,27 +30,33 @@ public function validate(array $payload): array
3030
3131 if (!isset ($ extra [self ::EMAIL ])) {
3232 $ errors [] = 'Email is required. ' ;
33+ } else {
34+ $ email = $ extra [self ::EMAIL ];
35+
36+ if (!is_string ($ email ) || false === filter_var ($ email , \FILTER_VALIDATE_EMAIL )) {
37+ $ errors [] = 'Email is not valid. ' ;
38+ }
3339 }
3440
35- $ email = $ extra [self ::EMAIL ];
41+ if (!isset ($ extra [self ::AGREEMENTS ])) {
42+ $ errors [] = 'Agreements are required. ' ;
3643
37- if (!is_string ($ email ) || false === filter_var ($ email , \FILTER_VALIDATE_EMAIL )) {
38- $ errors [] = 'Email is not valid. ' ;
44+ return $ errors ;
3945 }
4046
4147 if (false === is_array ($ extra [self ::AGREEMENTS ]) ||
4248 [] === $ extra [self ::AGREEMENTS ]
4349 ) {
4450 $ errors [] = 'Agreements are required. ' ;
45- }
46-
47- foreach ($ extra [self ::AGREEMENTS ] as $ agreement => $ value ) {
48- if (!isset ($ agreement ) || !is_string ($ agreement )) {
49- $ errors [] = 'Agreement code is required and must be a string. ' ;
50- }
51+ } else {
52+ foreach ($ extra [self ::AGREEMENTS ] as $ agreement => $ value ) {
53+ if (!is_string ($ agreement )) {
54+ $ errors [] = 'Agreement code is required and must be a string. ' ;
55+ }
5156
52- if (false === is_bool ($ value )) {
53- $ errors [] = 'Agreement value is required and must be a boolean. ' ;
57+ if (false === is_bool ($ value )) {
58+ $ errors [] = 'Agreement value is required and must be a boolean. ' ;
59+ }
5460 }
5561 }
5662
0 commit comments