Created
August 28, 2019 08:06
-
-
Save mangelsnc/16d7b189e0d21e7a5d61e7b805db9614 to your computer and use it in GitHub Desktop.
Without Demeter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
interface EmailService | |
{ | |
public function sendEmail(Email $email): void; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
class MySqlUserRepository implements UserRepository | |
{ | |
public function save(User $user): void | |
{ | |
// Implementation | |
} | |
public function get(string $userId): User | |
{ | |
// Implementation | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
class RegisterUserHandler | |
{ | |
private $userRepository; | |
private $notifications | |
public function __construct(UserRepository $userRepository, WelcomeEmailSender $notificationService) | |
{ | |
$this->userRepository = $userRepository; | |
$this->notificationService = $notificationService; | |
} | |
public function handle($name, $email) | |
{ | |
$user = new User($email, $name); | |
$this->userRepository->save($user); | |
$this->notificationService->send($user->getEmail(), $user->getName()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
class SmtpEmailService implements EmailService | |
{ | |
public function sendEmail(Email $email): void | |
{ | |
// implementation | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
interface UserRepository | |
{ | |
public function save(User $user): void; | |
public function get(string $userId): User; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
final class WelcomeEmailSender | |
{ | |
private $emailService; | |
public function __construct(EmailService $emailService) | |
{ | |
$this->emailService = $emailService; | |
} | |
public function send(string $emailAddress, string $username): void | |
{ | |
$body = $this->composeBody($username); | |
$email = new Email($emailAddress, 'Welcome to our platform', $body); | |
} | |
private function composeBody(string $username) | |
{ | |
// Code to compose body | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment