| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | protected $password; | 
| 17 | 17 | protected $vHost; | 
| 18 | 18 | |
| 19 | - public function __construct($host, $port, $user, $password, $vHost='/') | |
| 19 | + public function __construct($host, $port, $user, $password, $vHost = '/') | |
| 20 | 20 |      { | 
| 21 | 21 | $this->host = $host; | 
| 22 | 22 | $this->port = $port; | 
| @@ -41,7 +41,7 @@ | ||
| 41 | 41 | */ | 
| 42 | 42 | public function publish() | 
| 43 | 43 |      { | 
| 44 | -        if(!isset($this->events[0])) { | |
| 44 | +        if (!isset($this->events[0])) { | |
| 45 | 45 |              throw new DomainEventException('You must add at least 1 DomainEvent in order to publish to queue.'); | 
| 46 | 46 | } | 
| 47 | 47 | $this->queueWriter->write($this->events); | 
| @@ -31,7 +31,7 @@ | ||
| 31 | 31 | public function __construct($name, array $body, $delay=0) | 
| 32 | 32 |      { | 
| 33 | 33 | $this->setName($name) | 
| 34 | - ->setDelay($delay) | |
| 34 | + ->setDelay($delay) | |
| 35 | 35 | ; | 
| 36 | 36 | $this->body = $body; | 
| 37 | 37 | } | 
| @@ -28,7 +28,7 @@ discard block | ||
| 28 | 28 | * @param array $body | 
| 29 | 29 | * @param int $delay | 
| 30 | 30 | */ | 
| 31 | - public function __construct($name, array $body, $delay=0) | |
| 31 | + public function __construct($name, array $body, $delay = 0) | |
| 32 | 32 |      { | 
| 33 | 33 | $this->setName($name) | 
| 34 | 34 | ->setDelay($delay) | 
| @@ -67,7 +67,7 @@ discard block | ||
| 67 | 67 | */ | 
| 68 | 68 | protected function setName($name) | 
| 69 | 69 |      { | 
| 70 | -        if(empty($name)) { | |
| 70 | +        if (empty($name)) { | |
| 71 | 71 |              throw new TaskException('Task name cannot be empty'); | 
| 72 | 72 | } | 
| 73 | 73 | $this->name = $name; | 
| @@ -81,7 +81,7 @@ discard block | ||
| 81 | 81 | */ | 
| 82 | 82 | protected function setDelay($delay) | 
| 83 | 83 |      { | 
| 84 | -        if(!is_null($delay) && !preg_match('/^\d+$/', $delay)) { | |
| 84 | +        if (!is_null($delay) && !preg_match('/^\d+$/', $delay)) { | |
| 85 | 85 |              throw new TaskException("Task delay $delay is not a valid delay."); | 
| 86 | 86 | } | 
| 87 | 87 | $this->delay = $delay; | 
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | */ | 
| 41 | 41 | public function produce() | 
| 42 | 42 |      { | 
| 43 | -        if(!isset($this->tasks[0])) { | |
| 43 | +        if (!isset($this->tasks[0])) { | |
| 44 | 44 |              throw new TaskException('You must add at least 1 Task before producing.'); | 
| 45 | 45 | } | 
| 46 | 46 | $this->queueWriter->write($this->tasks); | 
| @@ -26,14 +26,14 @@ | ||
| 26 | 26 | * @param callable $callback Callable that'll be invoked when a message is received | 
| 27 | 27 | * @param int $timeout (optional) If specified, the process will block a max of $timeout seconds. Indefinitely if 0 | 
| 28 | 28 | */ | 
| 29 | - public function consume(callable $callback, $timeout=0) | |
| 29 | + public function consume(callable $callback, $timeout = 0) | |
| 30 | 30 |      { | 
| 31 | -        while(true) { | |
| 31 | +        while (true) { | |
| 32 | 32 |              try { | 
| 33 | 33 | $this->queueReader->read($callback, $timeout); | 
| 34 | -            } catch(TimeoutReaderException $e) { | |
| 34 | +            } catch (TimeoutReaderException $e) { | |
| 35 | 35 | break; | 
| 36 | -            } catch(GracefulStopException $e) { | |
| 36 | +            } catch (GracefulStopException $e) { | |
| 37 | 37 | break; | 
| 38 | 38 | } | 
| 39 | 39 | } | 
| @@ -97,20 +97,20 @@ discard block | ||
| 97 | 97 | * @throws TimeoutReaderException | 
| 98 | 98 | * @throws GracefulStopException | 
| 99 | 99 | */ | 
| 100 | - public function read(callable $callback, $timeout=0) | |
| 100 | + public function read(callable $callback, $timeout = 0) | |
| 101 | 101 |      { | 
| 102 | 102 | $this->initialize(); | 
| 103 | 103 | $this->messageHandler->setCallback($callback); | 
| 104 | 104 | |
| 105 | 105 |          try { | 
| 106 | 106 | $this->consume($timeout); | 
| 107 | -        } catch(GracefulStopException $e) { | |
| 107 | +        } catch (GracefulStopException $e) { | |
| 108 | 108 | $this->stopConsuming(); | 
| 109 | 109 |              throw  new GracefulStopException("Graceful exception", 0, $e); | 
| 110 | -        } catch(AMQPTimeoutException $e) { | |
| 110 | +        } catch (AMQPTimeoutException $e) { | |
| 111 | 111 | $this->stopConsuming(); | 
| 112 | 112 |              throw new TimeoutReaderException("Timed out at $timeout seconds while reading.", 0, $e); | 
| 113 | -        } catch(\Exception $e) { | |
| 113 | +        } catch (\Exception $e) { | |
| 114 | 114 | $this->stopConsuming(); | 
| 115 | 115 |              throw new ReaderException("Error occurred while reading", 0, $e); | 
| 116 | 116 | } | 
| @@ -169,7 +169,7 @@ discard block | ||
| 169 | 169 | protected function consume($timeout) | 
| 170 | 170 |      { | 
| 171 | 171 |          if ($this->consumerTag === '') { | 
| 172 | -            $this->logger->debug('Waiting for messages on queue:'.$this->queueConfig->getName()); | |
| 172 | +            $this->logger->debug('Waiting for messages on queue:' . $this->queueConfig->getName()); | |
| 173 | 173 | $this->consumerTag = $this->channel->basic_consume( | 
| 174 | 174 | $this->queueConfig->getName(), | 
| 175 | 175 | '', | 
| @@ -210,7 +210,7 @@ discard block | ||
| 210 | 210 |          if ($this->consumerTag) { | 
| 211 | 211 |              try { | 
| 212 | 212 | $this->channel->basic_cancel($this->consumerTag); | 
| 213 | -            } catch(\Exception $e) { | |
| 213 | +            } catch (\Exception $e) { | |
| 214 | 214 | } | 
| 215 | 215 | |
| 216 | 216 | $this->consumerTag = ''; | 
| @@ -68,7 +68,7 @@ discard block | ||
| 68 | 68 |      { | 
| 69 | 69 | $this->delay = $delay; | 
| 70 | 70 | $this->exchangeName = $exchangeName; | 
| 71 | - $this->delayedExchangeName = self::DELAY_QUEUE_PREFIX.$this->delay.$this->exchangeName; | |
| 71 | + $this->delayedExchangeName = self::DELAY_QUEUE_PREFIX . $this->delay . $this->exchangeName; | |
| 72 | 72 | $this->logger = $logger; | 
| 73 | 73 | $this->channel = $channel; | 
| 74 | 74 | } | 
| @@ -82,15 +82,15 @@ discard block | ||
| 82 | 82 |      { | 
| 83 | 83 | $this->initialize(); | 
| 84 | 84 |          try { | 
| 85 | -            foreach($messages as $message) { | |
| 85 | +            foreach ($messages as $message) { | |
| 86 | 86 | $encodedMessage = json_encode($message); | 
| 87 | 87 |                  $this->logger->debug('Writing:' . $encodedMessage); | 
| 88 | 88 |                  $msg = new AMQPMessage($encodedMessage, array('delivery_mode' => 2)); | 
| 89 | 89 | $this->channel->batch_basic_publish($msg, $this->delayedExchangeName, $message->getName()); | 
| 90 | 90 | } | 
| 91 | 91 | $this->channel->publish_batch(); | 
| 92 | -        } catch(\Exception $exception) { | |
| 93 | -            $this->logger->error('Error writing delayed messages: '.$exception->getMessage()); | |
| 92 | +        } catch (\Exception $exception) { | |
| 93 | +            $this->logger->error('Error writing delayed messages: ' . $exception->getMessage()); | |
| 94 | 94 | throw new WriterException($exception->getMessage(), $exception->getCode()); | 
| 95 | 95 | } | 
| 96 | 96 | } | 
| @@ -100,13 +100,13 @@ discard block | ||
| 100 | 100 | */ | 
| 101 | 101 | protected function initialize() | 
| 102 | 102 |      { | 
| 103 | -        try{ | |
| 104 | - $delayedQueue = self::DELAY_QUEUE_PREFIX.$this->delay.'Queue'; | |
| 103 | +        try { | |
| 104 | + $delayedQueue = self::DELAY_QUEUE_PREFIX . $this->delay . 'Queue'; | |
| 105 | 105 | |
| 106 | -            $this->logger->debug('Creating delayed exchange '.$this->delayedExchangeName); | |
| 106 | +            $this->logger->debug('Creating delayed exchange ' . $this->delayedExchangeName); | |
| 107 | 107 | // Delay Queue | 
| 108 | 108 | $this->channel->exchange_declare($this->delayedExchangeName, 'fanout', false, true, true); | 
| 109 | -            $this->logger->debug('Creating delayed queue '.$delayedQueue); | |
| 109 | +            $this->logger->debug('Creating delayed queue ' . $delayedQueue); | |
| 110 | 110 | $this->channel->queue_declare( | 
| 111 | 111 | $delayedQueue, | 
| 112 | 112 | false, | 
| @@ -121,8 +121,8 @@ discard block | ||
| 121 | 121 | ] | 
| 122 | 122 | ); | 
| 123 | 123 | $this->channel->queue_bind($delayedQueue, $this->delayedExchangeName); | 
| 124 | -        } catch(\Exception $exception) { | |
| 125 | -            $this->logger->error('Error configuring delayed queues: '.$exception->getMessage()); | |
| 124 | +        } catch (\Exception $exception) { | |
| 125 | +            $this->logger->error('Error configuring delayed queues: ' . $exception->getMessage()); | |
| 126 | 126 | throw new WriterException($exception->getMessage(), $exception->getCode()); | 
| 127 | 127 | } | 
| 128 | 128 | } | 
| @@ -64,8 +64,8 @@ discard block | ||
| 64 | 64 | $this->initialize(); | 
| 65 | 65 |          try { | 
| 66 | 66 | $messagesWithDelay = []; | 
| 67 | -            foreach($messages as $message) { | |
| 68 | -                if($message->getDelay() > 0) { | |
| 67 | +            foreach ($messages as $message) { | |
| 68 | +                if ($message->getDelay() > 0) { | |
| 69 | 69 | $messagesWithDelay[$message->getDelay()][] = $message; | 
| 70 | 70 | continue; | 
| 71 | 71 | } | 
| @@ -75,8 +75,8 @@ discard block | ||
| 75 | 75 | $this->channel->batch_basic_publish($msg, $this->exchangeConfig->getName(), $message->getName()); | 
| 76 | 76 | } | 
| 77 | 77 | $this->channel->publish_batch(); | 
| 78 | -            foreach($messagesWithDelay as $delay => $delayedMessages) { | |
| 79 | -                if(!isset($this->delayedQueueWriterRegistry[$delay])) { | |
| 78 | +            foreach ($messagesWithDelay as $delay => $delayedMessages) { | |
| 79 | +                if (!isset($this->delayedQueueWriterRegistry[$delay])) { | |
| 80 | 80 | $this->delayedQueueWriterRegistry[$delay] = new DelayedQueueWriter( | 
| 81 | 81 | $this->exchangeConfig->getName(), | 
| 82 | 82 | $delay, | 
| @@ -86,8 +86,8 @@ discard block | ||
| 86 | 86 | } | 
| 87 | 87 | $this->delayedQueueWriterRegistry[$delay]->write($delayedMessages); | 
| 88 | 88 | } | 
| 89 | -        } catch(\Exception $exception) { | |
| 90 | -            $this->logger->error('Error writing messages: '.$exception->getMessage()); | |
| 89 | +        } catch (\Exception $exception) { | |
| 90 | +            $this->logger->error('Error writing messages: ' . $exception->getMessage()); | |
| 91 | 91 | throw new WriterException($exception->getMessage(), $exception->getCode()); | 
| 92 | 92 | } | 
| 93 | 93 | } | 
| @@ -97,7 +97,7 @@ discard block | ||
| 97 | 97 | */ | 
| 98 | 98 | protected function initialize() | 
| 99 | 99 |      { | 
| 100 | -        if($this->channel) { | |
| 100 | +        if ($this->channel) { | |
| 101 | 101 | return; | 
| 102 | 102 | } | 
| 103 | 103 |          $this->logger->debug('Connecting to RabbitMQ'); | 
| @@ -106,7 +106,7 @@ discard block | ||
| 106 | 106 | */ | 
| 107 | 107 | protected function setOrigin($origin) | 
| 108 | 108 |      { | 
| 109 | -        if(empty($origin)) { | |
| 109 | +        if (empty($origin)) { | |
| 110 | 110 |              throw new DomainEventException('DomainEvent origin cannot be empty'); | 
| 111 | 111 | } | 
| 112 | 112 | $this->origin = $origin; | 
| @@ -120,7 +120,7 @@ discard block | ||
| 120 | 120 | */ | 
| 121 | 121 | protected function setName($name) | 
| 122 | 122 |      { | 
| 123 | -        if(empty($name)) { | |
| 123 | +        if (empty($name)) { | |
| 124 | 124 |              throw new DomainEventException('DomainEvent name cannot be empty'); | 
| 125 | 125 | } | 
| 126 | 126 | $this->name = $name; | 
| @@ -134,7 +134,7 @@ discard block | ||
| 134 | 134 | */ | 
| 135 | 135 | protected function setVersion($version) | 
| 136 | 136 |      { | 
| 137 | -        if(empty($version)) { | |
| 137 | +        if (empty($version)) { | |
| 138 | 138 |              throw new DomainEventException('DomainEvent version cannot be empty'); | 
| 139 | 139 | } | 
| 140 | 140 | $this->version = $version; | 
| @@ -148,7 +148,7 @@ discard block | ||
| 148 | 148 | */ | 
| 149 | 149 | protected function setOccurredOn($occurredOn) | 
| 150 | 150 |      { | 
| 151 | -        if(!is_null($occurredOn) && !preg_match('/^\d+(\.\d{1,4})?$/', $occurredOn)) { // accepts also microseconds | |
| 151 | +        if (!is_null($occurredOn) && !preg_match('/^\d+(\.\d{1,4})?$/', $occurredOn)) { // accepts also microseconds | |
| 152 | 152 |              throw new DomainEventException("$occurredOn is not a valid unix timestamp."); | 
| 153 | 153 | } | 
| 154 | 154 | |