Skip to content

Commit 8df5112

Browse files
committed
[PHP] [User Modelling Example] Replace Data Value with Object for Locale temporary state where some clients call to the deprecated API
1 parent 2fefa68 commit 8df5112

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

examples/php/php-user_modelling-02_value_objects/src/Locale.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public function __construct(string $value)
1515
$this->value = $value;
1616
}
1717

18+
public function value(): string
19+
{
20+
return $this->value;
21+
}
22+
1823
public function understandSpanish(): bool
1924
{
2025
$language = substr($this->value, 0, 2);

examples/php/php-user_modelling-02_value_objects/src/User.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public function __construct(string $locale, Age $age)
1515
$this->age = $age;
1616
}
1717

18+
public static function signUp(Locale $locale, Age $age)
19+
{
20+
return new self($locale->value(), $age);
21+
}
22+
1823
public function understandSpanish(): bool
1924
{
2025
return $this->locale->understandSpanish();

examples/php/php-user_modelling-02_value_objects/tests/UserTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace CodelyTv\UserModelling\Test;
66

77
use CodelyTv\UserModelling\Age;
8+
use CodelyTv\UserModelling\Locale;
89
use CodelyTv\UserModelling\User;
910
use PHPUnit\Framework\TestCase;
1011

@@ -13,7 +14,7 @@ final class UserTest extends TestCase
1314
/** @test */
1415
public function should_detect_spanish_from_spain_as_spanish_language(): void
1516
{
16-
$user = new User("es_ES", new Age(20));
17+
$user = User::signUp(new Locale("es_ES"), new Age(20));
1718

1819
self::assertTrue($user->understandSpanish());
1920
}

0 commit comments

Comments
 (0)