diff --git a/composer.json b/composer.json index 8451004..362c5cc 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "license": "OSL-3.0", "description": "Robin HQ library", "require": { - "php": ">=8.0 <=8.3", + "php": ">=8.0 <=8.4", "guzzlehttp/guzzle": "^7.4", "psr/log": "*", "psr/container": "^1.0|^2.0", diff --git a/src/Client/RobinClient.php b/src/Client/RobinClient.php index a208d0e..be5f56a 100644 --- a/src/Client/RobinClient.php +++ b/src/Client/RobinClient.php @@ -14,6 +14,7 @@ use Emico\RobinHqLib\Model\Customer; use Emico\RobinHqLib\Model\Order; use GuzzleHttp\Client; +use GuzzleHttp\Utils; use JsonSerializable; use Psr\Http\Message\ResponseInterface; use Psr\Log\LoggerInterface; @@ -112,7 +113,7 @@ public function postDynamicCustomer(Customer $customer): ResponseInterface */ protected function post(string $path, $payload): ResponseInterface { - $this->logger->debug('Payload: ' . \GuzzleHttp\json_encode($payload)); + $this->logger->debug('Payload: ' . Utils::jsonEncode($payload)); $response = $this->httpClient->post($path, [ 'auth' => [ $this->config->getApiKey(), $this->config->getApiSecret() ], diff --git a/src/Client/RobinClientFactory.php b/src/Client/RobinClientFactory.php index 02c7033..3df078a 100644 --- a/src/Client/RobinClientFactory.php +++ b/src/Client/RobinClientFactory.php @@ -8,7 +8,6 @@ use Emico\RobinHqLib\Config\Config; -use GuzzleHttp\Client; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; @@ -33,4 +32,4 @@ public function __invoke(ContainerInterface $container): RobinClient return new RobinClient($config, $container->get(LoggerInterface::class)); } -} \ No newline at end of file +} diff --git a/src/EventProcessor/CustomerEventProcessor.php b/src/EventProcessor/CustomerEventProcessor.php index 2646b46..1045e95 100644 --- a/src/EventProcessor/CustomerEventProcessor.php +++ b/src/EventProcessor/CustomerEventProcessor.php @@ -10,8 +10,6 @@ use Emico\RobinHqLib\Client\RobinClient; use Emico\RobinHqLib\Event\CustomerEvent; use Emico\RobinHqLib\Event\EventInterface; -use Exception; -use Psr\Log\LoggerInterface; class CustomerEventProcessor implements EventProcessorInterface { @@ -32,4 +30,4 @@ public function processEvent(EventInterface $event): bool $this->robinClient->postDynamicCustomer($event->getCustomer()); return true; } -} \ No newline at end of file +} diff --git a/src/EventProcessor/CustomerEventProcessorFactory.php b/src/EventProcessor/CustomerEventProcessorFactory.php index e405f19..a9d4929 100644 --- a/src/EventProcessor/CustomerEventProcessorFactory.php +++ b/src/EventProcessor/CustomerEventProcessorFactory.php @@ -8,11 +8,9 @@ use Emico\RobinHqLib\Client\RobinClient; -use Emico\RobinHqLib\Queue\EventInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; -use Psr\Log\LoggerInterface; class CustomerEventProcessorFactory { @@ -26,4 +24,4 @@ public function __invoke(ContainerInterface $container): CustomerEventProcessor { return new CustomerEventProcessor($container->get(RobinClient::class)); } -} \ No newline at end of file +} diff --git a/src/EventProcessor/OrderEventProcessor.php b/src/EventProcessor/OrderEventProcessor.php index 4136e29..f01f7c5 100644 --- a/src/EventProcessor/OrderEventProcessor.php +++ b/src/EventProcessor/OrderEventProcessor.php @@ -10,7 +10,6 @@ use Emico\RobinHqLib\Client\RobinClient; use Emico\RobinHqLib\Event\EventInterface; use Emico\RobinHqLib\Event\OrderEvent; -use Psr\Log\LoggerInterface; class OrderEventProcessor implements EventProcessorInterface { @@ -31,4 +30,4 @@ public function processEvent(EventInterface $event): bool $this->robinClient->postDynamicOrder($event->getOrder()); return true; } -} \ No newline at end of file +} diff --git a/src/Model/Collection.php b/src/Model/Collection.php index 2a201dd..8ee7309 100644 --- a/src/Model/Collection.php +++ b/src/Model/Collection.php @@ -24,7 +24,7 @@ class Collection implements JsonSerializable, \Countable /** * Collection constructor. * @param array $elements - * @param string $key + * @param null|string $key */ public function __construct(array $elements, string $key = null) { diff --git a/src/Model/Customer.php b/src/Model/Customer.php index 71f810f..217b62b 100644 --- a/src/Model/Customer.php +++ b/src/Model/Customer.php @@ -6,7 +6,6 @@ namespace Emico\RobinHqLib\Model; -use DateTime; use DateTimeInterface; use Emico\RobinHqLib\Config\Config; use JsonSerializable; @@ -242,7 +241,7 @@ public function jsonSerialize() 'email_address' => $this->emailAddress, 'name' => $this->name, 'phone_number' => $this->phoneNumber, - 'customer_since' => $this->customerSince ? $this->customerSince->format(DateTime::ISO8601) : '', + 'customer_since' => $this->customerSince ? $this->customerSince->format(\DateTimeInterface::ISO8601) : '', 'order_count' => $this->orderCount, 'total_revenue' => $this->totalRevenue, 'total_spent' => (string) $this->totalRevenue, diff --git a/src/Model/Order.php b/src/Model/Order.php index 893300d..a02f8bf 100644 --- a/src/Model/Order.php +++ b/src/Model/Order.php @@ -7,11 +7,9 @@ namespace Emico\RobinHqLib\Model; -use DateTime; use DateTimeInterface; use Emico\RobinHqLib\Config\Config; use Emico\RobinHqLib\Model\Order\DetailsView; -use PhpOffice\PhpSpreadsheet\Shared\Date; class Order implements \JsonSerializable { diff --git a/src/Model/Order/DetailsView.php b/src/Model/Order/DetailsView.php index 3026d58..9ef3f1e 100644 --- a/src/Model/Order/DetailsView.php +++ b/src/Model/Order/DetailsView.php @@ -7,7 +7,6 @@ namespace Emico\RobinHqLib\Model\Order; use DateTimeInterface; -use Emico\RobinHqLib\Config\Config; use JsonSerializable; class DetailsView implements JsonSerializable diff --git a/src/Model/SearchResult.php b/src/Model/SearchResult.php index 9891d92..074706e 100644 --- a/src/Model/SearchResult.php +++ b/src/Model/SearchResult.php @@ -7,9 +7,6 @@ namespace Emico\RobinHqLib\Model; -use DateTime; -use DateTimeInterface; - class SearchResult implements \JsonSerializable { /** diff --git a/src/Queue/FileQueueFactory.php b/src/Queue/FileQueueFactory.php index 8b81ad2..bc5fe2d 100644 --- a/src/Queue/FileQueueFactory.php +++ b/src/Queue/FileQueueFactory.php @@ -22,12 +22,10 @@ class FileQueueFactory */ public function __invoke(ContainerInterface $container): FileQueue { - $queue = new FileQueue( + return new FileQueue( __DIR__ . '/../../var/queue', $container->get(EventProcessingService::class), $container->get(LoggerInterface::class) ); - - return $queue; } -} \ No newline at end of file +} diff --git a/src/Queue/QueueInterface.php b/src/Queue/QueueInterface.php index 849f9c0..2012fd2 100644 --- a/src/Queue/QueueInterface.php +++ b/src/Queue/QueueInterface.php @@ -7,13 +7,11 @@ namespace Emico\RobinHqLib\Queue; -use Emico\RobinHqLib\Service\EventProcessingService; - interface QueueInterface { /** - * @param string $event + * @param string $serializedEvent * @return bool */ - public function pushEvent(string $event): bool; -} \ No newline at end of file + public function pushEvent(string $serializedEvent): bool; +} diff --git a/src/Server/RestApiServer.php b/src/Server/RestApiServer.php index 4d5a3d5..f31d93d 100644 --- a/src/Server/RestApiServer.php +++ b/src/Server/RestApiServer.php @@ -12,9 +12,9 @@ use Emico\RobinHqLib\DataProvider\Exception\DataNotFoundException; use Emico\RobinHqLib\DataProvider\Exception\InvalidRequestException; use Exception; +use Laminas\Diactoros\Response\JsonResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Laminas\Diactoros\Response\JsonResponse; class RestApiServer { @@ -71,7 +71,7 @@ protected function authenticateRequest(ServerRequestInterface $request): bool /* If using PHP in CGI mode. */ if (isset($serverParams['HTTP_AUTHORIZATION'])) { if (preg_match("/Basic\s+(.*)$/i", $serverParams['HTTP_AUTHORIZATION'], $matches)) { - list($user, $password) = explode(':', base64_decode($matches[1]), 2); + [$user, $password] = explode(':', base64_decode($matches[1]), 2); } } else { if (isset($serverParams["PHP_AUTH_USER"])) { @@ -88,4 +88,4 @@ protected function authenticateRequest(ServerRequestInterface $request): bool return true; } -} \ No newline at end of file +} diff --git a/src/Service/CustomerServiceFactory.php b/src/Service/CustomerServiceFactory.php index 33588c5..a16d023 100644 --- a/src/Service/CustomerServiceFactory.php +++ b/src/Service/CustomerServiceFactory.php @@ -7,16 +7,10 @@ namespace Emico\RobinHqLib\Service; -use Emico\RobinHqLib\Client\RobinClient; -use Emico\RobinHqLib\EventProcessor\CustomerEventProcessor; -use Emico\RobinHqLib\EventProcessor\OrderEventProcessor; use Emico\RobinHqLib\Queue\QueueInterface; -use Emico\RobinHqLib\Queue\Serializer\EventSerializer; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; -use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; class CustomerServiceFactory { @@ -30,4 +24,4 @@ public function __invoke(ContainerInterface $container): CustomerService { return new CustomerService($container->get(QueueInterface::class)); } -} \ No newline at end of file +} diff --git a/src/Service/EventProcessingService.php b/src/Service/EventProcessingService.php index 7564be8..263a917 100644 --- a/src/Service/EventProcessingService.php +++ b/src/Service/EventProcessingService.php @@ -7,7 +7,6 @@ namespace Emico\RobinHqLib\Service; -use Emico\RobinHqLib\Client\RobinClient; use Emico\RobinHqLib\Event\EventInterface; use Emico\RobinHqLib\EventProcessor\EventProcessorInterface; use Emico\RobinHqLib\Queue\Serializer\EventSerializer; @@ -75,4 +74,4 @@ public function getEventSerializer(): EventSerializer } return $this->eventSerializer; } -} \ No newline at end of file +} diff --git a/src/Service/OrderService.php b/src/Service/OrderService.php index 0813d9b..23a159c 100644 --- a/src/Service/OrderService.php +++ b/src/Service/OrderService.php @@ -14,17 +14,13 @@ class OrderService { - private EventSerializer $eventSerializer; - /** * CustomerService constructor. - * @param QueueInterface $queue */ - public function __construct(private QueueInterface $queue) - { - $this->queue = $queue; - $this->eventSerializer = new EventSerializer(); - } + public function __construct( + private QueueInterface $queue, + private EventSerializer $eventSerializer, + ) {} /** * @param Order $order @@ -34,4 +30,4 @@ public function postOrder(Order $order): void $event = new OrderEvent($order); $this->queue->pushEvent($this->eventSerializer->serializeEvent($event)); } -} \ No newline at end of file +}