| Conditions | 10 |
| Paths | 11 |
| Total Lines | 39 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 67 | private static function handleDependencies($items) |
||
| 68 | { |
||
| 69 | $items = array_unique($items, SORT_REGULAR); //Strip out duplicate requests |
||
| 70 | $resolutions = []; |
||
| 71 | $dependenciesFound = []; |
||
| 72 | $circularDependencyCounter = 0; |
||
| 73 | |||
| 74 | while (count($items) > count($resolutions) && $circularDependencyCounter < 20) { |
||
| 75 | $circularDependencyCounter++; |
||
| 76 | |||
| 77 | foreach ($items as $itemIndex => $item) { |
||
| 78 | |||
| 79 | //If I'm an existing depdendency - skip me! |
||
| 80 | if (isset($dependenciesFound[$item->id])) { |
||
| 81 | continue; |
||
| 82 | } |
||
| 83 | |||
| 84 | //We assume its found, unless stated below |
||
| 85 | $resolved = true; |
||
| 86 | |||
| 87 | //Check through each depdendency to see if its alrady desolved |
||
| 88 | if (isset($item->deps) && !empty($item->deps)) { |
||
| 89 | foreach ($item->deps as $dep) { |
||
| 90 | if (!isset($dependenciesFound[$dep])) { |
||
| 91 | $resolved = false; |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($resolved) { |
||
| 98 | $dependenciesFound[$item->id] = true; |
||
| 99 | $resolutions[] = $item; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | return $resolutions; |
||
| 105 | } |
||
| 106 | |||
| 117 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.