Skip to content

Commit

Permalink
Merge pull request #16 from FlashpointBV/feature/php83-compatibility
Browse files Browse the repository at this point in the history
PHP 8.3 compatibility
  • Loading branch information
bramstroker authored Sep 17, 2024
2 parents 248f684 + 17e4829 commit bf65f08
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 51 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/Client/RobinClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() ],
Expand Down
3 changes: 1 addition & 2 deletions src/Client/RobinClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


use Emico\RobinHqLib\Config\Config;
use GuzzleHttp\Client;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
Expand All @@ -33,4 +32,4 @@ public function __invoke(ContainerInterface $container): RobinClient

return new RobinClient($config, $container->get(LoggerInterface::class));
}
}
}
4 changes: 1 addition & 3 deletions src/EventProcessor/CustomerEventProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -32,4 +30,4 @@ public function processEvent(EventInterface $event): bool
$this->robinClient->postDynamicCustomer($event->getCustomer());
return true;
}
}
}
4 changes: 1 addition & 3 deletions src/EventProcessor/CustomerEventProcessorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -26,4 +24,4 @@ public function __invoke(ContainerInterface $container): CustomerEventProcessor
{
return new CustomerEventProcessor($container->get(RobinClient::class));
}
}
}
3 changes: 1 addition & 2 deletions src/EventProcessor/OrderEventProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -31,4 +30,4 @@ public function processEvent(EventInterface $event): bool
$this->robinClient->postDynamicOrder($event->getOrder());
return true;
}
}
}
2 changes: 1 addition & 1 deletion src/Model/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Emico\RobinHqLib\Model;

use DateTime;
use DateTimeInterface;
use Emico\RobinHqLib\Config\Config;
use JsonSerializable;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 0 additions & 1 deletion src/Model/Order/DetailsView.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace Emico\RobinHqLib\Model\Order;

use DateTimeInterface;
use Emico\RobinHqLib\Config\Config;
use JsonSerializable;

class DetailsView implements JsonSerializable
Expand Down
3 changes: 0 additions & 3 deletions src/Model/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
namespace Emico\RobinHqLib\Model;


use DateTime;
use DateTimeInterface;

class SearchResult implements \JsonSerializable
{
/**
Expand Down
6 changes: 2 additions & 4 deletions src/Queue/FileQueueFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
8 changes: 3 additions & 5 deletions src/Queue/QueueInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
public function pushEvent(string $serializedEvent): bool;
}
6 changes: 3 additions & 3 deletions src/Server/RestApiServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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"])) {
Expand All @@ -88,4 +88,4 @@ protected function authenticateRequest(ServerRequestInterface $request): bool

return true;
}
}
}
8 changes: 1 addition & 7 deletions src/Service/CustomerServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -30,4 +24,4 @@ public function __invoke(ContainerInterface $container): CustomerService
{
return new CustomerService($container->get(QueueInterface::class));
}
}
}
3 changes: 1 addition & 2 deletions src/Service/EventProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,4 +74,4 @@ public function getEventSerializer(): EventSerializer
}
return $this->eventSerializer;
}
}
}
14 changes: 5 additions & 9 deletions src/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,4 +30,4 @@ public function postOrder(Order $order): void
$event = new OrderEvent($order);
$this->queue->pushEvent($this->eventSerializer->serializeEvent($event));
}
}
}

0 comments on commit bf65f08

Please sign in to comment.