Skip to content

Commit

Permalink
Merge pull request #15 from EmicoEcommerce/fix/php82
Browse files Browse the repository at this point in the history
Add typing, up php constraint to 8.2 and update alle dependencies
  • Loading branch information
bramstroker authored Mar 13, 2024
2 parents 7284008 + 474588f commit 248f684
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 130 deletions.
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
"license": "OSL-3.0",
"description": "Robin HQ library",
"require": {
"php": ">=7.4 <=8.2",
"php": ">=8.0 <=8.3",
"guzzlehttp/guzzle": "^7.4",
"psr/log": "~1.0",
"psr/container": "~1.0",
"symfony/serializer": "^4.3",
"psr/log": "*",
"psr/container": "^1.0|^2.0",
"laminas/laminas-diactoros": "*"
},
"type": "library",
Expand Down
6 changes: 5 additions & 1 deletion src/Client/RobinClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@

use Emico\RobinHqLib\Config\Config;
use GuzzleHttp\Client;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;

class RobinClientFactory
{
/**
* @param ContainerInterface $container
* @return RobinClient
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container): RobinClient
{
/** @var Config $config */
$config = $container->get(Config::class);
Expand Down
8 changes: 4 additions & 4 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ class Config implements ConfigInterface
/**
* @var bool
*/
protected $apiEnabled = true;
protected bool $apiEnabled = true;

/**
* @var string
*/
protected $apiKey;
protected string $apiKey;

/**
* @var string
*/
protected $apiSecret;
protected string $apiSecret;

/**
* @var string
*/
protected $apiUri = 'https://api.robinhq.com/';
protected string $apiUri = 'https://api.robinhq.com/';

/**
* @var string
Expand Down
12 changes: 6 additions & 6 deletions src/Di/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Container implements ContainerInterface
/**
* @var array
*/
private $factories = [
private array $factories = [
FileQueue::class => FileQueueFactory::class,
QueueInterface::class => FileQueueFactory::class,
LoggerInterface::class => LoggerFactory::class,
Expand All @@ -51,7 +51,7 @@ class Container implements ContainerInterface
/**
* @var array
*/
private $instances = [];
private array $instances = [];

/**
* @param Config $config
Expand All @@ -67,7 +67,7 @@ public function __construct(Config $config)
* @throws InvalidFactoryException
* @throws ServiceNotFoundException
*/
public function get($id)
public function get(string $id)
{
if (isset($this->instances[$id])) {
return $this->instances[$id];
Expand All @@ -93,7 +93,7 @@ public function get($id)
* @param string $id
* @return bool
*/
public function has($id)
public function has(string $id): bool
{
return isset($this->factories[$id]);
}
Expand All @@ -103,7 +103,7 @@ public function has($id)
* @param callable $factory
* @return $this
*/
public function setFactory(string $id, callable $factory)
public function setFactory(string $id, callable $factory): self
{
$this->factories[$id] = $factory;
return $this;
Expand All @@ -114,7 +114,7 @@ public function setFactory(string $id, callable $factory)
* @param mixed $instance
* @return $this
*/
public function setInstance(string $id, $instance)
public function setInstance(string $id, mixed $instance): self
{
$this->instances[$id] = $instance;
return $this;
Expand Down
8 changes: 1 addition & 7 deletions src/Event/CustomerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@

final class CustomerEvent implements EventInterface
{
/**
* @var Customer
*/
protected $customer;

/**
* @param Customer $customer
*/
public function __construct(Customer $customer)
public function __construct(protected Customer $customer)
{
$this->customer = $customer;
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Event/OrderEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@

class OrderEvent implements EventInterface
{
/**
* @var Order
*/
protected $order;

/**
* @param Order $order
*/
public function __construct(Order $order)
public function __construct(protected Order $order)
{
$this->order = $order;
}

/**
Expand Down
15 changes: 0 additions & 15 deletions src/EventProcessor/AbstractEventProcessor.php

This file was deleted.

10 changes: 2 additions & 8 deletions src/EventProcessor/CustomerEventProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,19 @@

class CustomerEventProcessor implements EventProcessorInterface
{
/**
* @var RobinClient
*/
private $robinClient;

/**
* CustomerEventProcessor constructor.
* @param RobinClient $robinClient
*/
public function __construct(RobinClient $robinClient)
public function __construct(protected RobinClient $robinClient)
{
$this->robinClient = $robinClient;
}

/**
* @param EventInterface|CustomerEvent $event
* @return bool
*/
public function processEvent(EventInterface $event)
public function processEvent(EventInterface $event): bool
{
$this->robinClient->postDynamicCustomer($event->getCustomer());
return true;
Expand Down
6 changes: 5 additions & 1 deletion src/EventProcessor/CustomerEventProcessorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@

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
{
/**
* @param ContainerInterface $container
* @return CustomerEventProcessor
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container): CustomerEventProcessor
{
return new CustomerEventProcessor($container->get(RobinClient::class));
}
Expand Down
2 changes: 1 addition & 1 deletion src/EventProcessor/EventProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ interface EventProcessorInterface
* @param EventInterface $event
* @return bool
*/
public function processEvent(EventInterface $event);
public function processEvent(EventInterface $event): bool;
}
10 changes: 2 additions & 8 deletions src/EventProcessor/OrderEventProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,19 @@

class OrderEventProcessor implements EventProcessorInterface
{
/**
* @var RobinClient
*/
private $robinClient;

/**
* OrderEventProcessor constructor.
* @param RobinClient $robinClient
*/
public function __construct(RobinClient $robinClient)
public function __construct(private RobinClient $robinClient)
{
$this->robinClient = $robinClient;
}

/**
* @param EventInterface|OrderEvent $event
* @return bool
*/
public function processEvent(EventInterface $event)
public function processEvent(EventInterface $event): bool
{
$this->robinClient->postDynamicOrder($event->getOrder());
return true;
Expand Down
7 changes: 5 additions & 2 deletions src/EventProcessor/OrderEventProcessorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@


use Emico\RobinHqLib\Client\RobinClient;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Psr\Container\NotFoundExceptionInterface;

class OrderEventProcessorFactory
{
/**
* @param ContainerInterface $container
* @return OrderEventProcessor
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container): OrderEventProcessor
{
return new OrderEventProcessor($container->get(RobinClient::class));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Logger/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LoggerFactory
* @param ContainerInterface $container
* @return NullLogger
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container): NullLogger
{
return new NullLogger();
}
Expand Down
10 changes: 5 additions & 5 deletions src/Queue/FileQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ class FileQueue implements QueueInterface
/**
* @var string
*/
private $directory;
private string $directory;

/**
* @var EventProcessingService
*/
private $eventProcessingService;
private EventProcessingService $eventProcessingService;

/**
* @var LoggerInterface
*/
private $logger;
private LoggerInterface $logger;

/**
* @param string $directory
Expand All @@ -44,7 +44,7 @@ public function __construct(string $directory, EventProcessingService $eventProc
/**
* @param string $directory
*/
protected function ensureDirectoryExists(string $directory)
protected function ensureDirectoryExists(string $directory): void
{
if (!is_dir($directory)) {
mkdir($directory, 0777, true);
Expand All @@ -64,7 +64,7 @@ public function pushEvent(string $serializedEvent): bool
/**
* @param int $maxItems
*/
public function processQueue($maxItems = 100)
public function processQueue(int $maxItems = 100): void
{
$count = 0;

Expand Down
6 changes: 5 additions & 1 deletion src/Queue/FileQueueFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
namespace Emico\RobinHqLib\Queue;

use Emico\RobinHqLib\Service\EventProcessingService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;

class FileQueueFactory
{
/**
* @param ContainerInterface $container
* @return FileQueue
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container): FileQueue
{
$queue = new FileQueue(
__DIR__ . '/../../var/queue',
Expand Down
8 changes: 1 addition & 7 deletions src/Server/RestApiServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,14 @@

class RestApiServer
{
/**
* @var ConfigInterface
*/
private $config;

/**
* RestApiServer constructor.
* @param ConfigInterface $config
* @internal param string $apiKey
* @internal param string $apiSecret
*/
public function __construct(ConfigInterface $config)
public function __construct(protected ConfigInterface $config)
{
$this->config = $config;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Server/RestApiServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
namespace Emico\RobinHqLib\Server;

use Emico\RobinHqLib\Config\Config;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

class RestApiServerFactory
{
/**
* @param ContainerInterface $container
* @return RestApiServer
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container)
public function __invoke(ContainerInterface $container): RestApiServer
{
/** @var Config $config */
$config = $container->get(Config::class);
Expand Down
Loading

0 comments on commit 248f684

Please sign in to comment.