Conditions | 5 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
107 | public function consume( |
||
108 | string $queueName, |
||
109 | int $sleepSeconds = 3 |
||
110 | ) { |
||
111 | |||
112 | $this->loopConnection(function () use ($sleepSeconds, $queueName) { |
||
113 | |||
114 | /** como no pubsub ao perder a conexão, a fila exclusiva é excluida, é necessário configurar |
||
115 | * fila e etc novamente |
||
116 | */ |
||
117 | $this->createPubSubConsumer($queueName); |
||
118 | |||
119 | $this->channel->basic_qos(null, 1, null); |
||
120 | |||
121 | $this->channel->basic_consume( |
||
122 | $this->queueName, |
||
123 | '', |
||
124 | false, |
||
125 | true, |
||
126 | false, |
||
127 | false, |
||
128 | function (AMQPMessage $message) { |
||
129 | $statusBoolean = $this->executeStatusCallback($message); |
||
|
|||
130 | |||
131 | if (!$statusBoolean) { |
||
132 | return false; |
||
133 | } |
||
134 | |||
135 | $incomeData = json_decode($message->getBody(), true); |
||
136 | |||
137 | $statusBoolean = $this->executeReceiveCallback($message, $incomeData); |
||
138 | |||
139 | if (!$statusBoolean) { |
||
140 | return false; |
||
141 | } |
||
142 | |||
143 | |||
144 | try { |
||
145 | $executingCallback = $this->onExecutingCallback; |
||
146 | $executingCallback($message, $incomeData); |
||
147 | } catch (Exception $e) { |
||
148 | print_r("[ERROR]" . PHP_EOL); |
||
149 | $this->executeErrorCallback($e, $incomeData); |
||
150 | } |
||
151 | } |
||
152 | ); |
||
153 | |||
154 | // Loop as long as the channel has callbacks registered |
||
155 | while ($this->channel->is_open()) { |
||
156 | $this->channel->wait(null, false); |
||
157 | sleep($sleepSeconds); |
||
158 | } |
||
227 |
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.