Conditions | 12 |
Paths | 10 |
Total Lines | 52 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
122 | public function calculate(array $a, array $b, $compare = null) |
||
123 | { |
||
124 | if ($compare === null) { |
||
125 | $compare = function ($x, $y) { |
||
126 | return $x === $y; |
||
127 | }; |
||
128 | } |
||
129 | |||
130 | // The algorithm uses array keys numbered from zero. |
||
131 | $n = count($a); |
||
132 | $m = count($b); |
||
133 | $a = array_values($a); |
||
134 | $b = array_values($b); |
||
135 | $max = $m + $n; |
||
136 | |||
137 | // Keep a copy of $v after each iteration of $d. |
||
138 | $v_save = array(); |
||
139 | |||
140 | // Find the shortest "D-path". |
||
141 | $v = array(1 => 0); |
||
142 | for ($d = 0; $d <= $max; $d++) { |
||
143 | // Examine all possible "K-lines" for this "D-path". |
||
144 | for ($k = -$d; $k <= $d; $k += 2) { |
||
145 | if ($k === -$d || $k !== $d && $v[$k - 1] < $v[$k + 1]) { |
||
146 | // Move down. |
||
147 | $x = $v[$k + 1]; |
||
148 | } else { |
||
149 | // Move right. |
||
150 | $x = $v[$k - 1] + 1; |
||
151 | } |
||
152 | // Derive Y from X. |
||
153 | $y = $x - $k; |
||
154 | // Follow the diagonal. |
||
155 | while ($x < $n && $y < $m && $compare($a[$x], $b[$y])) { |
||
156 | $x++; |
||
157 | $y++; |
||
158 | } |
||
159 | // Just store X, as we can calculate Y (from X + K). |
||
160 | $v[$k] = $x; |
||
161 | $v_save[$d] = $v; |
||
162 | // Solution found? |
||
163 | if ($x === $n && $y === $m) { |
||
164 | break 2; |
||
165 | } |
||
166 | } |
||
167 | } |
||
168 | |||
169 | // Extract the solution by back-tracking through the saved results. |
||
170 | $snakes = $this->extractSnakes($v_save, $n, $m); |
||
171 | |||
172 | // Format the snakes as a set of instructions. |
||
173 | return $this->formatSolution($snakes, $a, $b); |
||
174 | } |
||
176 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths