PHP7 State

This commit is contained in:
Dominik Liebler
2016-09-22 11:45:38 +02:00
parent 1c30978a70
commit ea8c91ac68
8 changed files with 98 additions and 126 deletions

View File

@@ -2,46 +2,34 @@
namespace DesignPatterns\Behavioral\State;
class CreateOrder implements OrderInterface
class CreateOrder implements Order
{
/**
* @var array
*/
private $order;
private $details;
/**
* @param array $order
*
* @throws \Exception
* @param array $details
*/
public function __construct(array $order)
public function __construct(array $details)
{
if (empty($order)) {
throw new \Exception('Order can not be empty!');
}
$this->order = $order;
$this->details = $details;
}
/**
* @return mixed
*/
public function shipOrder()
{
$this->order['status'] = 'shipping';
$this->order['updatedTime'] = time();
// Setting the new order status into database;
return $this->updateOrder($this->order);
$this->details['status'] = 'shipping';
$this->details['updatedTime'] = time();
}
/**
* @throws \Exception
*
* @return mixed|void
*/
public function completeOrder()
{
//Can not complete the order which status is created, throw exception;
throw new \Exception('Can not complete the order which status is created!');
throw new \Exception('Can not complete the order which status is created');
}
public function getStatus(): string
{
return $this->details['status'];
}
}