File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 1010final class UserController
1111{
1212 public function post (string $ emailAddress ): User
13+ {
14+ $ this ->ensureEmailIsNotEmpty ($ emailAddress );
15+ $ this ->ensureEmailIsFormattedCorrectly ($ emailAddress );
16+ $ this ->ensureEmailHasCommonProvider ($ emailAddress );
17+
18+ return new User ($ emailAddress );
19+ }
20+
21+ private function ensureEmailIsNotEmpty (string $ emailAddress ): void
1322 {
1423 if ('' === $ emailAddress ) {
1524 throw new InvalidArgumentException ('The email address is empty ' );
1625 }
26+ }
1727
28+ private function ensureEmailIsFormattedCorrectly (string $ emailAddress ): void
29+ {
1830 if (!filter_var ($ emailAddress , FILTER_VALIDATE_EMAIL )) {
1931 throw new InvalidArgumentException ("The email address < $ emailAddress> is not valid " );
2032 }
33+ }
2134
22- if (!(strpos ($ emailAddress , '@yahoo ' ) || strpos ($ emailAddress , '@gmail ' ) || strpos ($ emailAddress , '@outlook ' ))) {
35+ private function ensureEmailHasCommonProvider (string $ emailAddress ): void
36+ {
37+ if (!$ this ->emailHasCommonProvider ($ emailAddress )) {
2338 throw new InvalidArgumentException ("The email address < $ emailAddress> has not a common provider " );
2439 }
40+ }
2541
26- return new User ($ emailAddress );
42+ private function emailHasCommonProvider (string $ emailAddress ): bool
43+ {
44+ return strpos ($ emailAddress , '@yahoo ' ) || strpos ($ emailAddress , '@gmail ' ) || strpos ($ emailAddress , '@outlook ' );
2745 }
2846}
You can’t perform that action at this time.
0 commit comments