Fix Psalm issues

This commit is contained in:
Oliver Davies 2020-06-05 21:37:17 +01:00
parent ce05172932
commit 259946d961
6 changed files with 33 additions and 4 deletions

View file

@ -15,7 +15,7 @@ abstract class AbstractRequest
public const BASE_URL = 'https://server.glassboxx.co.uk'; public const BASE_URL = 'https://server.glassboxx.co.uk';
/** @var HttpClient */ /** @var HttpClientInterface */
protected $client; protected $client;
public function __construct(HttpClientInterface $client = null) public function __construct(HttpClientInterface $client = null)

View file

@ -4,10 +4,16 @@ declare(strict_types=1);
namespace Opdavies\Glassboxx\Request; namespace Opdavies\Glassboxx\Request;
use RuntimeException;
final class AuthTokenRequest extends AbstractRequest implements AuthTokenRequestInterface final class AuthTokenRequest extends AbstractRequest implements AuthTokenRequestInterface
{ {
public function getToken(): string public function getToken(): string
{ {
if (!$this->config) {
throw new RuntimeException('There is no config');
}
$response = $this->client->request( $response = $this->client->request(
'POST', 'POST',
self::ENDPOINT, self::ENDPOINT,

View file

@ -6,12 +6,13 @@ namespace Opdavies\Glassboxx\Request;
use Opdavies\Glassboxx\Traits\UsesAuthTokenTrait; use Opdavies\Glassboxx\Traits\UsesAuthTokenTrait;
use Opdavies\Glassboxx\ValueObject\CustomerInterface; use Opdavies\Glassboxx\ValueObject\CustomerInterface;
use RuntimeException;
final class CustomerRequest extends AbstractRequest implements CustomerRequestInterface final class CustomerRequest extends AbstractRequest implements CustomerRequestInterface
{ {
use UsesAuthTokenTrait; use UsesAuthTokenTrait;
/** @var CustomerInterface */ /** @var CustomerInterface|null */
protected $customer; protected $customer;
public function forCustomer(CustomerInterface $customer): AbstractRequest public function forCustomer(CustomerInterface $customer): AbstractRequest
@ -23,6 +24,14 @@ final class CustomerRequest extends AbstractRequest implements CustomerRequestIn
public function execute(): string 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 = [ $body = [
'customer' => [ 'customer' => [
'created_in' => $this->config->getVendorId(), 'created_in' => $this->config->getVendorId(),

View file

@ -8,13 +8,14 @@ use Opdavies\Glassboxx\Enum\InteractionType;
use Opdavies\Glassboxx\Traits\UsesAuthTokenTrait; use Opdavies\Glassboxx\Traits\UsesAuthTokenTrait;
use Opdavies\Glassboxx\Traits\UsesCreatedAtTrait; use Opdavies\Glassboxx\Traits\UsesCreatedAtTrait;
use Opdavies\Glassboxx\ValueObject\OrderInterface; use Opdavies\Glassboxx\ValueObject\OrderInterface;
use RuntimeException;
class OrderRequest extends AbstractRequest implements OrderRequestInterface class OrderRequest extends AbstractRequest implements OrderRequestInterface
{ {
use UsesCreatedAtTrait; use UsesCreatedAtTrait;
use UsesAuthTokenTrait; use UsesAuthTokenTrait;
/** @var OrderInterface */ /** @var OrderInterface|null */
private $order; private $order;
public function forOrder(OrderInterface $order): AbstractRequest public function forOrder(OrderInterface $order): AbstractRequest
@ -26,6 +27,18 @@ class OrderRequest extends AbstractRequest implements OrderRequestInterface
public function execute(): string 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 = [ $body = [
'items' => [ 'items' => [
[ [

View file

@ -6,6 +6,7 @@ namespace Opdavies\Glassboxx\Traits;
trait UsesAuthTokenTrait trait UsesAuthTokenTrait
{ {
/** @var string|null */
protected $authToken; protected $authToken;
public function withAuthToken(string $authToken): self public function withAuthToken(string $authToken): self

View file

@ -8,7 +8,7 @@ use Opdavies\Glassboxx\Config;
trait UsesConfigTrait trait UsesConfigTrait
{ {
/** @var Config */ /** @var Config|null */
protected $config; protected $config;
public function withConfig(Config $config): self public function withConfig(Config $config): self