for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace OldSound\RabbitMqBundle\EventListener;
use OldSound\RabbitMqBundle\Event\AfterProcessingMessagesEvent;
use OldSound\RabbitMqBundle\Event\OnConsumeEvent;
use OldSound\RabbitMqBundle\RabbitMq\Consumer;
use PhpAmqpLib\Exception\AMQPTimeoutException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PcntlSignalDispatchSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
return [
OnConsumeEvent::NAME => 'onConsume',
AfterProcessingMessagesEvent::NAME => 'afterProcessingMessages'
];
}
public function __construct(Consumer $consumer)
$stopConsumer = function () use ($consumer) {
// Process current message, then halt consumer
$consumer->forceStopConsumer();
// Halt consumer if waiting for a new message from the queue
try {
$consumer->stopConsuming(true);
} catch (AMQPTimeoutException $e) {}
};
pcntl_signal(SIGTERM, $stopConsumer);
pcntl_signal(SIGINT, $stopConsumer);
// TODO pcntl_signal(SIGHUP, $restartConsumer);
public function onConsume(OnConsumeEvent $event)
$event
If this is a false-positive, you can also ignore this issue in your code via the ignore-unused annotation
ignore-unused
public function onConsume(/** @scrutinizer ignore-unused */ OnConsumeEvent $event)
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
pcntl_signal_dispatch();
public function afterProcessingMessages(AfterProcessingMessagesEvent $event)
public function afterProcessingMessages(/** @scrutinizer ignore-unused */ AfterProcessingMessagesEvent $event)