diff --git a/src/Glassboxx/Request/AbstractRequest.php b/src/Glassboxx/Request/AbstractRequest.php index a51cc3d..63dd206 100644 --- a/src/Glassboxx/Request/AbstractRequest.php +++ b/src/Glassboxx/Request/AbstractRequest.php @@ -15,7 +15,7 @@ abstract class AbstractRequest public const BASE_URL = 'https://server.glassboxx.co.uk'; - /** @var HttpClient */ + /** @var HttpClientInterface */ protected $client; public function __construct(HttpClientInterface $client = null) diff --git a/src/Glassboxx/Request/AuthTokenRequest.php b/src/Glassboxx/Request/AuthTokenRequest.php index 5333214..0cf72ea 100644 --- a/src/Glassboxx/Request/AuthTokenRequest.php +++ b/src/Glassboxx/Request/AuthTokenRequest.php @@ -4,10 +4,16 @@ declare(strict_types=1); namespace Opdavies\Glassboxx\Request; +use RuntimeException; + final class AuthTokenRequest extends AbstractRequest implements AuthTokenRequestInterface { public function getToken(): string { + if (!$this->config) { + throw new RuntimeException('There is no config'); + } + $response = $this->client->request( 'POST', self::ENDPOINT, diff --git a/src/Glassboxx/Request/CustomerRequest.php b/src/Glassboxx/Request/CustomerRequest.php index d290060..953189e 100644 --- a/src/Glassboxx/Request/CustomerRequest.php +++ b/src/Glassboxx/Request/CustomerRequest.php @@ -6,12 +6,13 @@ namespace Opdavies\Glassboxx\Request; use Opdavies\Glassboxx\Traits\UsesAuthTokenTrait; use Opdavies\Glassboxx\ValueObject\CustomerInterface; +use RuntimeException; final class CustomerRequest extends AbstractRequest implements CustomerRequestInterface { use UsesAuthTokenTrait; - /** @var CustomerInterface */ + /** @var CustomerInterface|null */ protected $customer; public function forCustomer(CustomerInterface $customer): AbstractRequest @@ -23,6 +24,14 @@ final class CustomerRequest extends AbstractRequest implements CustomerRequestIn public function execute(): string { + if (!$this->config) { + throw new RuntimeException('There is no config'); + } + + if (!$this->customer) { + throw new RuntimeException('There is no customer'); + } + $body = [ 'customer' => [ 'created_in' => $this->config->getVendorId(), diff --git a/src/Glassboxx/Request/OrderRequest.php b/src/Glassboxx/Request/OrderRequest.php index ee6bb2c..428ece2 100644 --- a/src/Glassboxx/Request/OrderRequest.php +++ b/src/Glassboxx/Request/OrderRequest.php @@ -8,13 +8,14 @@ use Opdavies\Glassboxx\Enum\InteractionType; use Opdavies\Glassboxx\Traits\UsesAuthTokenTrait; use Opdavies\Glassboxx\Traits\UsesCreatedAtTrait; use Opdavies\Glassboxx\ValueObject\OrderInterface; +use RuntimeException; class OrderRequest extends AbstractRequest implements OrderRequestInterface { use UsesCreatedAtTrait; use UsesAuthTokenTrait; - /** @var OrderInterface */ + /** @var OrderInterface|null */ private $order; public function forOrder(OrderInterface $order): AbstractRequest @@ -26,6 +27,18 @@ class OrderRequest extends AbstractRequest implements OrderRequestInterface public function execute(): string { + if (!$this->config) { + throw new RuntimeException('There is no config'); + } + + if (!$this->order) { + throw new RuntimeException('There is no order'); + } + + if (!$this->order->getCustomer()) { + throw new RuntimeException('There is no customer'); + } + $body = [ 'items' => [ [ diff --git a/src/Glassboxx/Traits/UsesAuthTokenTrait.php b/src/Glassboxx/Traits/UsesAuthTokenTrait.php index 81f441b..9117a26 100644 --- a/src/Glassboxx/Traits/UsesAuthTokenTrait.php +++ b/src/Glassboxx/Traits/UsesAuthTokenTrait.php @@ -6,6 +6,7 @@ namespace Opdavies\Glassboxx\Traits; trait UsesAuthTokenTrait { + /** @var string|null */ protected $authToken; public function withAuthToken(string $authToken): self diff --git a/src/Glassboxx/Traits/UsesConfigTrait.php b/src/Glassboxx/Traits/UsesConfigTrait.php index dad7f0f..801f1bd 100644 --- a/src/Glassboxx/Traits/UsesConfigTrait.php +++ b/src/Glassboxx/Traits/UsesConfigTrait.php @@ -8,7 +8,7 @@ use Opdavies\Glassboxx\Config; trait UsesConfigTrait { - /** @var Config */ + /** @var Config|null */ protected $config; public function withConfig(Config $config): self