Skip to content

Instantly share code, notes, and snippets.

@ismail1432
Last active December 19, 2021 10:32
Show Gist options
  • Save ismail1432/c0b77400f0ced7ca62476c0ef11b9743 to your computer and use it in GitHub Desktop.
Save ismail1432/c0b77400f0ced7ca62476c0ef11b9743 to your computer and use it in GitHub Desktop.
<?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