Conditions | 10 |
Paths | 48 |
Total Lines | 45 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
33 | public function consume(array $options = []): void |
||
34 | { |
||
35 | $queueName = $this->messageProvider->getQueueName(); |
||
36 | |||
37 | $this->logger->debug('Start consuming queue.', [ |
||
38 | 'queue' => $queueName, |
||
39 | ]); |
||
40 | |||
41 | $this->optionsResolver->setDefaults([ |
||
42 | 'poll_interval' => 50000, |
||
43 | 'queue' => $queueName, |
||
44 | ]); |
||
45 | |||
46 | if ($this->processor instanceof ConfigurableInterface) { |
||
47 | $this->processor->setDefaultOptions($this->optionsResolver); |
||
48 | } |
||
49 | |||
50 | $options = $this->optionsResolver->resolve($options); |
||
51 | |||
52 | if ($this->processor instanceof InitializableInterface) { |
||
53 | $this->processor->initialize($options); |
||
54 | } |
||
55 | |||
56 | while (true) { |
||
57 | while (null !== $message = $this->messageProvider->get()) { |
||
58 | $result = $this->processor->process($message, $options); |
||
59 | if (!\is_bool($result)) { |
||
60 | @trigger_error('Processors must return a bool since Swarrot 3.7', E_USER_DEPRECATED); |
||
61 | } |
||
62 | if (false === $result) { |
||
63 | break 2; |
||
64 | } |
||
65 | } |
||
66 | |||
67 | if ($this->processor instanceof SleepyInterface) { |
||
68 | if (false === $this->processor->sleep($options)) { |
||
69 | break; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | usleep($options['poll_interval']); |
||
74 | } |
||
75 | |||
76 | if ($this->processor instanceof TerminableInterface) { |
||
77 | $this->processor->terminate($options); |
||
78 | } |
||
117 |