| Conditions | 21 |
| Paths | 111 |
| Total Lines | 65 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 50 | private function checkAndNudgePoints(BitMatrix $matrix, array $points):void{ |
||
| 51 | $dimension = $matrix->getSize(); |
||
| 52 | $nudged = true; |
||
| 53 | $max = count($points); |
||
| 54 | |||
| 55 | // Check and nudge points from start until we see some that are OK: |
||
| 56 | for($offset = 0; $offset < $max && $nudged; $offset += 2){ |
||
| 57 | $x = (int)$points[$offset]; |
||
| 58 | $y = (int)$points[($offset + 1)]; |
||
| 59 | |||
| 60 | if($x < -1 || $x > $dimension || $y < -1 || $y > $dimension){ |
||
| 61 | throw new QRCodeDetectorException(sprintf('checkAndNudgePoints 1, x: %s, y: %s, d: %s', $x, $y, $dimension)); |
||
| 62 | } |
||
| 63 | |||
| 64 | $nudged = false; |
||
| 65 | |||
| 66 | if($x === -1){ |
||
| 67 | $points[$offset] = 0.0; |
||
| 68 | $nudged = true; |
||
| 69 | } |
||
| 70 | elseif($x === $dimension){ |
||
| 71 | $points[$offset] = ($dimension - 1); |
||
| 72 | $nudged = true; |
||
| 73 | } |
||
| 74 | |||
| 75 | if($y === -1){ |
||
| 76 | $points[($offset + 1)] = 0.0; |
||
| 77 | $nudged = true; |
||
| 78 | } |
||
| 79 | elseif($y === $dimension){ |
||
| 80 | $points[($offset + 1)] = ($dimension - 1); |
||
| 81 | $nudged = true; |
||
| 82 | } |
||
| 83 | |||
| 84 | } |
||
| 85 | // Check and nudge points from end: |
||
| 86 | $nudged = true; |
||
| 87 | $offset = (count($points) - 2); |
||
| 88 | |||
| 89 | for(; $offset >= 0 && $nudged; $offset -= 2){ |
||
| 90 | $x = (int)$points[$offset]; |
||
| 91 | $y = (int)$points[($offset + 1)]; |
||
| 92 | |||
| 93 | if($x < -1 || $x > $dimension || $y < -1 || $y > $dimension){ |
||
| 94 | throw new QRCodeDetectorException(sprintf('checkAndNudgePoints 2, x: %s, y: %s, d: %s', $x, $y, $dimension)); |
||
| 95 | } |
||
| 96 | |||
| 97 | $nudged = false; |
||
| 98 | |||
| 99 | if($x === -1){ |
||
| 100 | $points[$offset] = 0.0; |
||
| 101 | $nudged = true; |
||
| 102 | } |
||
| 103 | elseif($x === $dimension){ |
||
| 104 | $points[$offset] = ($dimension - 1); |
||
| 105 | $nudged = true; |
||
| 106 | } |
||
| 107 | |||
| 108 | if($y === -1){ |
||
| 109 | $points[($offset + 1)] = 0.0; |
||
| 110 | $nudged = true; |
||
| 111 | } |
||
| 112 | elseif($y === $dimension){ |
||
| 113 | $points[($offset + 1)] = ($dimension - 1); |
||
| 114 | $nudged = true; |
||
| 115 | } |
||
| 178 |