Conditions | 11 |
Paths | 3 |
Total Lines | 44 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
60 | public function addRange(Range ...$rangeList): void |
||
61 | { |
||
62 | $rangeList = $this->getSortedRangeList(...$rangeList); |
||
63 | $existingIndex = 0; |
||
64 | $addedIndex = 0; |
||
65 | $newRangeList = []; |
||
66 | /** @var Range $rangeBuffer */ |
||
67 | $rangeBuffer = null; |
||
68 | while (true) { |
||
69 | $existingRange = $this->rangeList[$existingIndex] ?? null; |
||
70 | $addedRange = $rangeList[$addedIndex] ?? null; |
||
71 | |||
72 | if (isset($existingRange)) { |
||
73 | if (isset($addedRange) && $existingRange->getStart() > $addedRange->getStart()) { |
||
74 | $pickedRange = $addedRange; |
||
75 | $addedIndex++; |
||
76 | } else { |
||
77 | $pickedRange = $existingRange; |
||
78 | $existingIndex++; |
||
79 | } |
||
80 | } elseif (isset($addedRange)) { |
||
81 | $pickedRange = $addedRange; |
||
82 | $addedIndex++; |
||
83 | } else { |
||
84 | if (isset($rangeBuffer)) { |
||
85 | $newRangeList[] = $rangeBuffer; |
||
86 | } |
||
87 | break; |
||
88 | } |
||
89 | |||
90 | if (isset($rangeBuffer)) { |
||
91 | if ($rangeBuffer->containsFinishOf($pickedRange)) { |
||
92 | continue; |
||
93 | } |
||
94 | if ($rangeBuffer->containsStartOf($pickedRange) || $pickedRange->follows($rangeBuffer)) { |
||
95 | $rangeBuffer = $pickedRange->copyAfterStartOf($rangeBuffer); |
||
96 | continue; |
||
97 | } |
||
98 | $newRangeList[] = $rangeBuffer; |
||
99 | } |
||
100 | $rangeBuffer = $pickedRange; |
||
101 | } |
||
102 | |||
103 | $this->rangeList = $newRangeList; |
||
104 | } |
||
131 |