| Conditions | 5 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 79 | public function consume( |
||
| 80 | string $queueName, |
||
| 81 | int $sleepSeconds = 3 |
||
| 82 | ) |
||
| 83 | { |
||
| 84 | |||
| 85 | $this->loopConnection(function () use ($sleepSeconds, $queueName) { |
||
| 86 | |||
| 87 | /** como no pubsub ao perder a conexão, a fila exclusiva é excluida, é necessário configurar |
||
| 88 | * fila e etc novamente |
||
| 89 | */ |
||
| 90 | $this->createPubSubConsumer($queueName); |
||
| 91 | |||
| 92 | $this->channel->basic_qos(null, 1, null); |
||
| 93 | |||
| 94 | $this->channel->basic_consume( |
||
| 95 | $this->queueName, |
||
| 96 | '', |
||
| 97 | false, |
||
| 98 | true, |
||
| 99 | false, |
||
| 100 | false, |
||
| 101 | function (AMQPMessage $message) { |
||
| 102 | $statusBoolean = $this->executeStatusCallback($message); |
||
|
|
|||
| 103 | |||
| 104 | if (!$statusBoolean) { |
||
| 105 | return false; |
||
| 106 | } |
||
| 107 | |||
| 108 | $incomeData = json_decode($message->getBody(), true); |
||
| 109 | |||
| 110 | $statusBoolean = $this->executeReceiveCallback($message, $incomeData); |
||
| 111 | |||
| 112 | if (!$statusBoolean) { |
||
| 113 | return false; |
||
| 114 | } |
||
| 115 | |||
| 116 | |||
| 117 | try { |
||
| 118 | $executingCallback = $this->onExecutingCallback; |
||
| 119 | $executingCallback($message, $incomeData); |
||
| 120 | } catch (Exception $e) { |
||
| 121 | print_r("[ERROR]" . PHP_EOL); |
||
| 122 | $this->executeErrorCallback($e, $incomeData); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | ); |
||
| 126 | |||
| 127 | // Loop as long as the channel has callbacks registered |
||
| 128 | while ($this->channel->is_open()) { |
||
| 129 | $this->channel->wait(null, false); |
||
| 130 | sleep($sleepSeconds); |
||
| 131 | } |
||
| 226 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.