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';
/** @var HttpClient */
/** @var HttpClientInterface */
protected $client;
public function __construct(HttpClientInterface $client = null)

View file

@ -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,

View file

@ -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(),

View file

@ -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' => [
[

View file

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

View file

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