| Conditions | 13 |
| Paths | 36 |
| Total Lines | 38 |
| 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 |
||
| 54 | public function updatedWorkers() |
||
| 55 | { |
||
| 56 | $perWorker = 1; |
||
| 57 | $instancesCount = []; |
||
| 58 | foreach (Daemon::$config as $name => $section) { |
||
| 59 | if ((!$section instanceof Config\Section) || !isset($section->limitinstances)) { |
||
| 60 | continue; |
||
| 61 | } |
||
| 62 | $instancesCount[$name] = 0; |
||
| 63 | } |
||
| 64 | foreach ($this->pool->workers as $worker) { |
||
| 65 | foreach ($worker->instancesCount as $k => $v) { |
||
| 66 | if (!isset($instancesCount[$k])) { |
||
| 67 | unset($worker->instancesCount[$k]); |
||
| 68 | continue; |
||
| 69 | } |
||
| 70 | $instancesCount[$k] += $v; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | foreach ($instancesCount as $name => $num) { |
||
| 74 | $v = Daemon::$config->{$name}->limitinstances->value - $num; |
||
| 75 | foreach ($this->pool->workers as $worker) { |
||
| 76 | if ($v <= 0) { |
||
| 77 | break; |
||
| 78 | } |
||
| 79 | if ((isset($worker->instancesCount[$name])) && ($worker->instancesCount[$name] < $perWorker)) { |
||
| 80 | continue; |
||
| 81 | } |
||
| 82 | if (!isset($worker->instancesCount[$name])) { |
||
| 83 | $worker->instancesCount[$name] = 1; |
||
| 84 | } else { |
||
| 85 | ++$worker->instancesCount[$name]; |
||
| 86 | } |
||
| 87 | $worker->sendPacket(['op' => 'spawnInstance', 'appfullname' => $name]); |
||
| 88 | --$v; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 204 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: