File tree Expand file tree Collapse file tree 2 files changed +27
-7
lines changed
examples/php/php-user_modelling-02_value_objects/src Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace CodelyTv \UserModelling ;
6+
7+ final class Locale
8+ {
9+ private const SPANISH_LANGUAGE = "es " ;
10+
11+ private string $ value ;
12+
13+ public function __construct (string $ value )
14+ {
15+ $ this ->value = $ value ;
16+ }
17+
18+ public function understandSpanish (): bool
19+ {
20+ $ language = substr ($ this ->value , 0 , 2 );
21+
22+ return $ language === self ::SPANISH_LANGUAGE ;
23+ }
24+ }
Original file line number Diff line number Diff line change 66
77final class User
88{
9- private const SPANISH_LANGUAGE = "es " ;
10-
11- private string $ locale ;
9+ private Locale $ locale ;
1210 private Age $ age ;
1311
1412 public function __construct (string $ locale , Age $ age )
1513 {
16- $ this ->locale = $ locale ;
14+ $ this ->locale = new Locale ( $ locale) ;
1715 $ this ->age = $ age ;
1816 }
1917
2018 public function understandSpanish (): bool
2119 {
22- $ language = substr ($ this ->locale , 0 , 2 );
23-
24- return $ language === self ::SPANISH_LANGUAGE ;
20+ return $ this ->locale ->understandSpanish ();
2521 }
2622
2723 public function isUnderage (): bool
You can’t perform that action at this time.
0 commit comments