Last active
December 19, 2021 10:32
-
-
Save ismail1432/c0b77400f0ced7ca62476c0ef11b9743 to your computer and use it in GitHub Desktop.
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 | |
| class Article | |
| { | |
| public const DELETED = 'deleted'; // 🎉 Use this constant is more readable and prevent typos | |
| public const PUBLISHED = 'published'; | |
| private string $status; | |
| // getters & setters | |
| } | |
| class PublishArticleHandler | |
| { | |
| public function __invoke(Article $article) | |
| { | |
| if ($article->getStatus === Article::DELETED)) { | |
| throw new LogicException(sprintf("Cannot mark as published as the article is deleted")); | |
| } | |
| } | |
| $article->setStatus(Article::PUBLISHED); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment