Skip to content

Commit

Permalink
DocBlock removed; CS fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zloyuser committed Aug 13, 2024
1 parent 0772d37 commit 23e661a
Show file tree
Hide file tree
Showing 47 changed files with 135 additions and 619 deletions.
19 changes: 0 additions & 19 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,27 @@ final class Builder
*/
private array $extensions = [];

/**
* @param string $command
* @param callable $handler
*
* @return self
*/
public function handle(string $command, callable $handler): self
{
$this->handlers[$command] = $handler;

return $this;
}

/**
* @param Middleware $middleware
*
* @return self
*/
public function middleware(Middleware $middleware): self
{
$this->middleware[get_class($middleware)] = $middleware;

return $this;
}

/**
* @param Extension $extension
*
* @return self
*/
public function use(Extension $extension): self
{
$this->extensions[get_class($extension)] = $extension;

return $this;
}

/**
* @return Dispatcher
*/
public function build(): Dispatcher
{
foreach ($this->extensions as $extension) {
Expand Down
40 changes: 2 additions & 38 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,24 @@ final class Context
private const OPTION_LOCAL = 'local';

/**
* @param Dispatcher $dispatcher
* @param DeferredIterator $deferred
* @param array<string, mixed> $options
*/
public function __construct(
private Dispatcher $dispatcher,
private DeferredIterator $deferred,
private array $options = []
) {
}
private array $options = [],
) {}

/**
* @param object $message
* @param array<string, mixed> $options
*
* @return void
*/
public function dispatch(object $message, array $options = []): void
{
$this->dispatcher->dispatch($message, $options);
}

/**
* @param object $message
* @param array<string, mixed> $options
* @return void
*/
public function execute(object $message, array $options = []): void
{
Expand All @@ -46,10 +38,7 @@ public function execute(object $message, array $options = []): void
}

/**
* @param object $message
* @param array<string, mixed> $options
*
* @return self
*/
public function defer(object $message, array $options = []): self
{
Expand All @@ -66,55 +55,30 @@ public function all(): array
return $this->options;
}

/**
* @param string $option
*
* @return bool
*/
public function has(string $option): bool
{
return array_key_exists($option, $this->options);
}

/**
* @param string $option
* @param mixed $default
*
* @return mixed
*/
public function get(string $option, mixed $default = null): mixed
{
return $this->options[$option] ?? $default;
}

/**
* @param string $option
* @param mixed $value
*
* @return self
*/
public function set(string $option, mixed $value): self
{
$this->options[$option] = $value;

return $this;
}

/**
* @param string $option
*
* @return self
*/
public function del(string $option): self
{
unset($this->options[$option]);

return $this;
}

/**
* @return bool
*/
public function isLocal(): bool
{
return $this->has(self::OPTION_LOCAL);
Expand Down
14 changes: 4 additions & 10 deletions src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,19 @@

final class Dispatcher
{
/**
* @param Resolver $resolver
*/
public function __construct(private Resolver $resolver)
{
}
public function __construct(
private Resolver $resolver,
) {}

/**
* @param object $message
* @param array<string, mixed> $options
*
* @return void
*/
public function dispatch(object $message, array $options = []): void
{
$handler = $this->resolver->resolve($message);
$iterator = new DeferredIterator();
$context = new Context($this, $iterator, $options);

$handler = $this->resolver->resolve($message);
$handler($message, $context);

foreach ($iterator as $deferred) {
Expand Down
4 changes: 1 addition & 3 deletions src/Exception/CommandBusException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use LogicException;

class CommandBusException extends LogicException
{
}
class CommandBusException extends LogicException {}
3 changes: 0 additions & 3 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

interface Extension
{
/**
* @param Builder $builder
*/
public function setup(Builder $builder): void;
}
6 changes: 2 additions & 4 deletions src/Message/Deferred.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

namespace Onliner\CommandBus\Message;

class Deferred
final class Deferred
{
/**
* @param object $message
* @param array<string, mixed> $options
*/
public function __construct(
public object $message,
public array $options,
) {
}
) {}
}
2 changes: 1 addition & 1 deletion src/Message/DeferredIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* @implements IteratorAggregate<Deferred>
*/
class DeferredIterator implements IteratorAggregate
final class DeferredIterator implements IteratorAggregate
{
/**
* @var array<Deferred>
Expand Down
7 changes: 0 additions & 7 deletions src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,5 @@

interface Middleware
{
/**
* @param object $message
* @param Context $context
* @param callable $next
*
* @return void
*/
public function call(object $message, Context $context, callable $next): void;
}
16 changes: 4 additions & 12 deletions src/Middleware/LoggerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@

final class LoggerMiddleware implements Middleware
{
/**
* @param LoggerInterface $logger
* @param string $level
*/
public function __construct(private LoggerInterface $logger, private string $level = LogLevel::ERROR)
{
}
public function __construct(
private LoggerInterface $logger,
private string $level = LogLevel::ERROR,
) {}

/**
* {@inheritDoc}
*
* @throws Throwable
*/
public function call(object $message, Context $context, callable $next): void
{
try {
Expand Down
4 changes: 0 additions & 4 deletions src/Middleware/YieldMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

final class YieldMiddleware implements Middleware
{
/**
* {@inheritDoc}
*/
public function call(object $message, Context $context, callable $next): void
{
$result = $next($message, $context);
Expand All @@ -30,7 +27,6 @@ public function call(object $message, Context $context, callable $next): void

/**
* @param Generator<object> $generator
* @param Context $context
*/
private function tick(Generator $generator, Context $context): void
{
Expand Down
42 changes: 5 additions & 37 deletions src/Remote/AMQP/AMQPConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,24 @@ final class AMQPConsumer implements Consumer
*/
private array $queues = [];

/**
* @param Connector $connector
* @param Exchange $exchange
* @param LoggerInterface|null $logger
*/
public function __construct(
private Connector $connector,
private Exchange $exchange,
LoggerInterface $logger = null
LoggerInterface $logger = null,
) {
$this->logger = $logger ?? new NullLogger();
}

/**
* @param string $pattern
*
* @return void
*/
public function listen(string $pattern): void
{
$this->consume(new Queue($pattern, $pattern, $this->exchange->flags()));
$this->consume(new Queue($pattern, $pattern, $this->exchange->flags));
}

/**
* @param Queue $queue
*/
public function consume(Queue $queue): void
{
$this->queues[] = $queue;
}

/**
* {@inheritDoc}
*/
public function run(Dispatcher $dispatcher, array $options = []): void
{
$this->running = true;
Expand All @@ -96,20 +80,13 @@ public function run(Dispatcher $dispatcher, array $options = []): void
$channel->close();
}

/**
* {@inheritDoc}
*/
public function stop(): void
{
$this->running = false;
}

/**
* @param Dispatcher $dispatcher
* @param array<string, mixed> $options
*
* @return AMQPChannel
* @throws AMQPIOException
*/
private function channel(Dispatcher $dispatcher, array $options): AMQPChannel
{
Expand All @@ -135,9 +112,6 @@ private function channel(Dispatcher $dispatcher, array $options): AMQPChannel

/**
* @param array<string, mixed> $options
*
* @return AMQPChannel
* @throws AMQPIOException
*/
private function connect(array $options): AMQPChannel
{
Expand Down Expand Up @@ -170,12 +144,6 @@ private function connect(array $options): AMQPChannel
throw new AMQPIOException();
}

/**
* @param AMQPMessage $message
* @param Dispatcher $dispatcher
*
* @return void
*/
private function handle(AMQPMessage $message, Dispatcher $dispatcher): void
{
$headers = $message->get('application_headers');
Expand All @@ -187,11 +155,11 @@ private function handle(AMQPMessage $message, Dispatcher $dispatcher): void
}

$headers = array_replace($headers->getNativeData(), [
Exchange::HEADER_EXCHANGE => $message->getExchange(),
Exchange::HEADER_ROUTING_KEY => $message->getRoutingKey(),
Exchange::HEADER_EXCHANGE => $message->getExchange(),
Exchange::HEADER_REDELIVERED => $message->isRedelivered(),
Exchange::HEADER_ROUTING_KEY => $message->getRoutingKey(),
Exchange::HEADER_CONSUMER_TAG => $message->getConsumerTag(),
Exchange::HEADER_DELIVERY_TAG => $message->getDeliveryTag(),
Exchange::HEADER_REDELIVERED => $message->isRedelivered(),
]);

if (!isset($headers[Exchange::HEADER_MESSAGE_TYPE])) {
Expand Down
Loading

0 comments on commit 23e661a

Please sign in to comment.