| Conditions | 10 |
| Paths | 14 |
| Total Lines | 31 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 175 | public function getChannel() |
||
| 176 | { |
||
| 177 | if (!$this->connection) { |
||
| 178 | try { |
||
| 179 | if (function_exists('socket_create')) { |
||
| 180 | $this->connection = new AMQPSocketConnection($this->host, $this->port, $this->user, $this->password); |
||
|
|
|||
| 181 | } else { |
||
| 182 | $this->connection = new AMQPStreamConnection($this->host, $this->port, $this->user, $this->password); |
||
| 183 | } |
||
| 184 | } catch (\ErrorException $e) { |
||
| 185 | /* We are trying to catch the exception when the connection if refused */ |
||
| 186 | if (preg_match("/.*unable to connect.*Connection refused.*/", $e->__toString())) { |
||
| 187 | throw new ConnectionException("Cannot create the connection", 404, $e); |
||
| 188 | } |
||
| 189 | throw $e; |
||
| 190 | } catch (\AMQPIOException $e) { |
||
| 191 | throw new ConnectionException("Cannot create the connection", 404, $e); |
||
| 192 | } |
||
| 193 | $this->channel = $this->connection->channel(); |
||
| 194 | |||
| 195 | if ($this->prefetchSize !== null || $this->prefetchCount !== null || $this->aGlobal !== null) { |
||
| 196 | $this->channel->basic_qos($this->prefetchSize, $this->prefetchCount, $this->aGlobal); |
||
| 197 | } |
||
| 198 | |||
| 199 | foreach ($this->rabbitMqObjects as $rabbitMqObject) { |
||
| 200 | $rabbitMqObject->init($this->channel); |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | return $this->channel; |
||
| 205 | } |
||
| 206 | |||
| 219 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..