Skip to content

Instantly share code, notes, and snippets.

@avosalmon
Last active May 7, 2019 12:56
Show Gist options
  • Save avosalmon/c2e2296d96ab288bed1dd11bf007a333 to your computer and use it in GitHub Desktop.
Save avosalmon/c2e2296d96ab288bed1dd11bf007a333 to your computer and use it in GitHub Desktop.
<?php
interface OrderValidationInterface
{
public function validate(Order $order) : void;
}
class OrderHasAmount implements OrderValidationInterface
{
public function validate(Order $order) : void
{
if (! $order->getAmount() > 0) {
throw new Exception('Order amount must be more than zero.');
}
}
}
class OrderIsApproved implements OrderValidationInterface
{
public function validate(Order $order) : void
{
if (! $order->isApproved()) {
throw new Exception('Order is not approved.');
}
}
}
class OrderIsNotCancelled implements OrderValidationInterface
{
public function validate(Order $order) : void
{
if (! $order->isCancelled()) {
throw new Exception('Cancelled order cannot be processed.');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment