File tree Expand file tree Collapse file tree 7 files changed +49
-29
lines changed
examples/php/php-user_email-05_user_email_vo Expand file tree Collapse file tree 7 files changed +49
-29
lines changed Original file line number Diff line number Diff line change 44
55namespace CodelyTv \Controller ;
66
7- use CodelyTv \Model \EmailAddress ;
87use CodelyTv \Model \Newsletter ;
8+ use CodelyTv \Model \UserEmailAddress ;
99
1010final class NewsletterController
1111{
1212 public function post (string $ emailAddress ): Newsletter
1313 {
14- return new Newsletter (new EmailAddress ($ emailAddress ));
14+ return new Newsletter (new UserEmailAddress ($ emailAddress ));
1515 }
1616}
Original file line number Diff line number Diff line change 44
55namespace CodelyTv \Controller ;
66
7- use CodelyTv \Model \EmailAddress ;
87use CodelyTv \Model \User ;
8+ use CodelyTv \Model \UserEmailAddress ;
99
1010final class UserController
1111{
1212 public function post (string $ emailAddress ): User
1313 {
14- return new User (new EmailAddress ($ emailAddress ));
14+ return new User (new UserEmailAddress ($ emailAddress ));
1515 }
1616}
Original file line number Diff line number Diff line change 66
77final class Newsletter
88{
9- private EmailAddress $ emailAddress ;
9+ private UserEmailAddress $ emailAddress ;
1010
11- public function __construct (EmailAddress $ emailAddress )
11+ public function __construct (UserEmailAddress $ emailAddress )
1212 {
13- User::ensureEmailIsValid ($ emailAddress );
14-
1513 $ this ->emailAddress = $ emailAddress ;
1614 }
1715
18- public function emailAddress (): EmailAddress
16+ public function emailAddress (): UserEmailAddress
1917 {
2018 return $ this ->emailAddress ;
2119 }
Original file line number Diff line number Diff line change 44
55namespace CodelyTv \Model ;
66
7- use InvalidArgumentException ;
8-
97final class User
108{
11- private EmailAddress $ emailAddress ;
9+ private UserEmailAddress $ emailAddress ;
1210
13- public function __construct (EmailAddress $ emailAddress )
11+ public function __construct (UserEmailAddress $ emailAddress )
1412 {
15- self ::ensureEmailIsValid ($ emailAddress );
16-
1713 $ this ->emailAddress = $ emailAddress ;
1814 }
1915
20- public static function ensureEmailIsValid (EmailAddress $ emailAddress ): void
21- {
22- if (!$ emailAddress ->emailHasCommonProvider ()) {
23- throw new InvalidArgumentException (
24- "The email address < {$ emailAddress ->value ()}> has not a common provider "
25- );
26- }
27- }
28-
29- public function emailAddress (): EmailAddress
16+ public function emailAddress (): UserEmailAddress
3017 {
3118 return $ this ->emailAddress ;
3219 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace CodelyTv \Model ;
6+
7+ use InvalidArgumentException ;
8+
9+ final class UserEmailAddress
10+ {
11+ private EmailAddress $ value ;
12+
13+ public function __construct (string $ value )
14+ {
15+ $ emailAddress = new EmailAddress ($ value );
16+
17+ $ this ->ensureEmailIsValid ($ emailAddress );
18+
19+ $ this ->value = $ emailAddress ;
20+ }
21+
22+ public function ensureEmailIsValid (EmailAddress $ emailAddress ): void
23+ {
24+ if (!$ emailAddress ->emailHasCommonProvider ()) {
25+ throw new InvalidArgumentException (
26+ "The email address < {$ emailAddress ->value ()}> has not a common provider "
27+ );
28+ }
29+ }
30+
31+ public function value (): string
32+ {
33+ return $ this ->value ->value ();
34+ }
35+ }
Original file line number Diff line number Diff line change 55namespace CodelyTv \Tests \Controller ;
66
77use CodelyTv \Controller \NewsletterController ;
8- use CodelyTv \Model \EmailAddress ;
98use CodelyTv \Model \Newsletter ;
9+ use CodelyTv \Model \UserEmailAddress ;
1010use InvalidArgumentException ;
1111use PHPUnit \Framework \TestCase ;
1212
@@ -19,7 +19,7 @@ public function it_should_create_a_valid_newsletter(): void
1919
2020 $ emailAddress = 'codely@gmail.com ' ;
2121
22- self ::assertEquals (new Newsletter (new EmailAddress ('codely@gmail.com ' )), $ controller ->post ($ emailAddress ));
22+ self ::assertEquals (new Newsletter (new UserEmailAddress ('codely@gmail.com ' )), $ controller ->post ($ emailAddress ));
2323 }
2424
2525 /** @test */
Original file line number Diff line number Diff line change 55namespace CodelyTv \Tests \Controller ;
66
77use CodelyTv \Controller \UserController ;
8- use CodelyTv \Model \EmailAddress ;
98use CodelyTv \Model \User ;
9+ use CodelyTv \Model \UserEmailAddress ;
1010use InvalidArgumentException ;
1111use PHPUnit \Framework \TestCase ;
1212
@@ -19,7 +19,7 @@ public function it_should_create_a_valid_user(): void
1919
2020 $ emailAddress = 'codely@gmail.com ' ;
2121
22- self ::assertEquals (new User (new EmailAddress ('codely@gmail.com ' )), $ controller ->post ($ emailAddress ));
22+ self ::assertEquals (new User (new UserEmailAddress ('codely@gmail.com ' )), $ controller ->post ($ emailAddress ));
2323 }
2424
2525 /** @test */
You can’t perform that action at this time.
0 commit comments