Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AsyncQueueProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
$this->queueName = StringNormalizer::normalize($queueName);
$this->dispatcher = new PushMiddlewareDispatcher(
middlewareFactory: $middlewareConfig->middlewareFactory,
middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions],

Check warning on line 37 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ $this->queueName = StringNormalizer::normalize($queueName); $this->dispatcher = new PushMiddlewareDispatcher( middlewareFactory: $middlewareConfig->middlewareFactory, - middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions], + middlewareDefinitions: [...$middlewareDefinitions], finalHandler: new AdapterPushHandler($adapter), ); }
finishHandler: new AdapterPushHandler($adapter),
finalHandler: new AdapterPushHandler($adapter),
);
}

Expand All @@ -46,17 +46,17 @@

public function push(MessageInterface $message): MessageInterface
{
$this->logger->debug(

Check warning on line 49 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ public function push(MessageInterface $message): MessageInterface { - $this->logger->debug( - 'Preparing to push message with message type "{messageType}".', - ['messageType' => $message->getType()], - ); + $message = $this->dispatcher->dispatch($message); $id = IdEnvelope::fromMessage($message)->getId(); $this->logger->info(
'Preparing to push message with message type "{messageType}".',
['messageType' => $message->getType()],

Check warning on line 51 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ { $this->logger->debug( 'Preparing to push message with message type "{messageType}".', - ['messageType' => $message->getType()], + [], ); $message = $this->dispatcher->dispatch($message); $id = IdEnvelope::fromMessage($message)->getId();

Check warning on line 51 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItem": @@ @@ { $this->logger->debug( 'Preparing to push message with message type "{messageType}".', - ['messageType' => $message->getType()], + ['messageType' > $message->getType()], ); $message = $this->dispatcher->dispatch($message); $id = IdEnvelope::fromMessage($message)->getId();
);
$message = $this->dispatcher->dispatch($message);
$id = IdEnvelope::fromMessage($message)->getId();
$this->logger->info(

Check warning on line 55 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ ); $message = $this->dispatcher->dispatch($message); $id = IdEnvelope::fromMessage($message)->getId(); - $this->logger->info( - $id === null - ? 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.' - : 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.', - ['messageType' => $message->getType(), 'id' => $id], - ); + return $message; }
$id === null

Check warning on line 56 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Ternary": @@ @@ $message = $this->dispatcher->dispatch($message); $id = IdEnvelope::fromMessage($message)->getId(); $this->logger->info( - $id === null - ? 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.' - : 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.', + $id === null ? 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.' : 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.', ['messageType' => $message->getType(), 'id' => $id], ); return $message;
? 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.'
: 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.',
['messageType' => $message->getType(), 'id' => $id],

Check warning on line 59 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ $id === null ? 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.' : 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.', - ['messageType' => $message->getType(), 'id' => $id], + ['id' => $id], ); return $message; }

Check warning on line 59 in src/AsyncQueueProducer.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItem": @@ @@ $id === null ? 'Pushed message with message type "{messageType}" to the queue. ID doesn\'t assigned.' : 'Pushed message with message type "{messageType}" to the queue. Assigned ID #{id}.', - ['messageType' => $message->getType(), 'id' => $id], + ['messageType' > $message->getType(), 'id' => $id], ); return $message; }
);
return $message;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Middleware/Consume/ConsumeMiddlewareDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public function __construct(
* Dispatch request through middleware to get response.
*
* @param ConsumeRequest $request Request to pass to middleware.
* @param ConsumeHandlerInterface $finishHandler Handler to use in case no middleware produced a response.
* @param ConsumeHandlerInterface $finalHandler Handler to use in case no middleware produced a response.
*/
public function dispatch(
ConsumeRequest $request,
ConsumeHandlerInterface $finishHandler,
ConsumeHandlerInterface $finalHandler,
): ConsumeRequest {
$type = $request->getMessage()->getType();
if (!array_key_exists($type, $this->stack)) {
$this->stack[$type] = new ConsumeMiddlewareStack($this->buildMiddlewares(), $finishHandler);
$this->stack[$type] = new ConsumeMiddlewareStack($this->buildMiddlewares(), $finalHandler);
}

return $this->stack[$type]->handleConsume($request);
Expand Down
7 changes: 3 additions & 4 deletions src/Middleware/Consume/ConsumeMiddlewareStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ final class ConsumeMiddlewareStack implements ConsumeHandlerInterface

/**
* @param Closure[] $middlewares Middlewares.
* @param ConsumeHandlerInterface $finishHandler Fallback handler
* events.
* @param ConsumeHandlerInterface $finalHandler Handler invoked after all middlewares are processed.
*
* @psalm-param list<Closure():ConsumeMiddlewareInterface> $middlewares
*/
public function __construct(
private readonly array $middlewares,
private readonly ConsumeHandlerInterface $finishHandler,
private readonly ConsumeHandlerInterface $finalHandler,
) {}

public function handleConsume(ConsumeRequest $request): ConsumeRequest
Expand All @@ -36,7 +35,7 @@ public function handleConsume(ConsumeRequest $request): ConsumeRequest

private function build(): ConsumeHandlerInterface
{
$handler = $this->finishHandler;
$handler = $this->finalHandler;

foreach ($this->middlewares as $middleware) {
$handler = $this->wrap($middleware, $handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public function __construct(
* Dispatch request through middleware to get response.
*
* @param FailureHandlingRequest $request Request to pass to middleware.
* @param FailureHandlerInterface $finishHandler Handler to use in case no middleware produced a response.
* @param FailureHandlerInterface $finalHandler Handler to use in case no middleware produced a response.
*/
public function dispatch(
FailureHandlingRequest $request,
FailureHandlerInterface $finishHandler,
FailureHandlerInterface $finalHandler,
): FailureHandlingRequest {
$queueName = $request->getQueueName();
if (!isset($this->middlewareDefinitions[$queueName]) || $this->middlewareDefinitions[$queueName] === []) {
$queueName = self::DEFAULT_PIPELINE;
}
$definitions = array_reverse($this->middlewareDefinitions[$queueName]);

$this->stack[$queueName] ??= new FailureMiddlewareStack($this->buildMiddlewares(...$definitions), $finishHandler);
$this->stack[$queueName] ??= new FailureMiddlewareStack($this->buildMiddlewares(...$definitions), $finalHandler);

return $this->stack[$queueName]->handleFailure($request);
}
Expand Down
7 changes: 3 additions & 4 deletions src/Middleware/FailureHandling/FailureMiddlewareStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ final class FailureMiddlewareStack implements FailureHandlerInterface

/**
* @param Closure[] $middlewares Middlewares.
* @param FailureHandlerInterface $finishHandler Fallback handler
* events.
* @param FailureHandlerInterface $finalHandler Handler invoked after all middlewares are processed.
*
* @psalm-param list<Closure():FailureMiddlewareInterface> $middlewares
*/
public function __construct(
private readonly array $middlewares,
private readonly FailureHandlerInterface $finishHandler,
private readonly FailureHandlerInterface $finalHandler,
) {}

public function handleFailure(FailureHandlingRequest $request): FailureHandlingRequest
Expand All @@ -36,7 +35,7 @@ public function handleFailure(FailureHandlingRequest $request): FailureHandlingR

private function build(): FailureHandlerInterface
{
$handler = $this->finishHandler;
$handler = $this->finalHandler;

foreach ($this->middlewares as $middleware) {
$handler = $this->wrap($middleware, $handler);
Expand Down
10 changes: 5 additions & 5 deletions src/Middleware/Push/PushMiddlewareDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ final class PushMiddlewareDispatcher
/**
* @param PushMiddlewareFactoryInterface $middlewareFactory Factory used to instantiate middleware.
* @param mixed[] $middlewareDefinitions Middleware definitions.
* @param PushHandlerInterface $finishHandler Finish message handler.
* @param PushHandlerInterface $finalHandler Handler invoked after all middlewares are processed.
*/
public function __construct(
private readonly PushMiddlewareFactoryInterface $middlewareFactory,
private array $middlewareDefinitions,
private PushHandlerInterface $finishHandler,
private PushHandlerInterface $finalHandler,
) {}

/**
Expand All @@ -37,15 +37,15 @@ public function __construct(
*/
public function dispatch(MessageInterface $message): MessageInterface
{
$this->stack ??= new PushMiddlewareStack($this->buildMiddlewares(), $this->finishHandler);
$this->stack ??= new PushMiddlewareStack($this->buildMiddlewares(), $this->finalHandler);

return $this->stack->handlePush($message);
}

public function withFinishHandler(PushHandlerInterface $finishHandler): self
public function withFinalHandler(PushHandlerInterface $finalHandler): self
{
$instance = clone $this;
$instance->finishHandler = $finishHandler;
$instance->finalHandler = $finalHandler;

// Fixes a memory leak.
unset($instance->stack);
Expand Down
6 changes: 3 additions & 3 deletions src/Middleware/Push/PushMiddlewareStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ final class PushMiddlewareStack implements PushHandlerInterface

/**
* @param Closure[] $middlewares Middlewares.
* @param PushHandlerInterface $finishHandler Final handler invoked after all middlewares are processed.
* @param PushHandlerInterface $finalHandler Handler invoked after all middlewares are processed.
*
* @psalm-param list<Closure():PushMiddlewareInterface> $middlewares
*/
public function __construct(
private readonly array $middlewares,
private readonly PushHandlerInterface $finishHandler,
private readonly PushHandlerInterface $finalHandler,
) {}

public function handlePush(MessageInterface $message): MessageInterface
Expand All @@ -39,7 +39,7 @@ public function handlePush(MessageInterface $message): MessageInterface

private function build(): PushHandlerInterface
{
$handler = $this->finishHandler;
$handler = $this->finalHandler;

foreach (array_reverse($this->middlewares) as $middleware) {
$handler = $this->wrap($middleware, $handler);
Expand Down
2 changes: 1 addition & 1 deletion src/SyncQueueProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
$this->dispatcher = new PushMiddlewareDispatcher(
middlewareFactory: $middlewareConfig->middlewareFactory,
middlewareDefinitions: [...$middlewareConfig->commonMiddlewareDefinitions, ...$middlewareDefinitions],
finishHandler: new SynchronousPushHandler($worker, $this),
finalHandler: new SynchronousPushHandler($worker, $this),
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Worker/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function process(
$request = new ConsumeRequest($message, $queueName);
try {
$handler = $this->handlerResolver->resolve($message->getType());
$finishHandler = new ConsumeFinalHandler($handler->handle(...));
$this->consumeMiddlewareDispatcher->dispatch($request, $finishHandler);
$finalHandler = new ConsumeFinalHandler($handler->handle(...));
$this->consumeMiddlewareDispatcher->dispatch($request, $finalHandler);
} catch (Throwable $exception) {
$request = new FailureHandlingRequest($request->getMessage(), $exception, $request->getQueueName(), $retryProducer);

Expand Down
Loading