Conditions | 21 |
Paths | 111 |
Total Lines | 61 |
Code Lines | 40 |
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->size(); |
||
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 | if($y === -1){ |
||
75 | $points[$offset + 1] = 0.0; |
||
76 | $nudged = true; |
||
77 | } |
||
78 | elseif($y === $dimension){ |
||
79 | $points[$offset + 1] = $dimension - 1; |
||
80 | $nudged = true; |
||
81 | } |
||
82 | } |
||
83 | // Check and nudge points from end: |
||
84 | $nudged = true; |
||
85 | |||
86 | for($offset = count($points) - 2; $offset >= 0 && $nudged; $offset -= 2){ |
||
87 | $x = (int)$points[$offset]; |
||
88 | $y = (int)$points[$offset + 1]; |
||
89 | |||
90 | if($x < -1 || $x > $dimension || $y < -1 || $y > $dimension){ |
||
91 | throw new QRCodeDetectorException(sprintf('checkAndNudgePoints 2, x: %s, y: %s, d: %s', $x, $y, $dimension)); |
||
92 | } |
||
93 | |||
94 | $nudged = false; |
||
95 | |||
96 | if($x === -1){ |
||
97 | $points[$offset] = 0.0; |
||
98 | $nudged = true; |
||
99 | } |
||
100 | elseif($x === $dimension){ |
||
101 | $points[$offset] = $dimension - 1; |
||
102 | $nudged = true; |
||
103 | } |
||
104 | if($y === -1){ |
||
105 | $points[$offset + 1] = 0.0; |
||
106 | $nudged = true; |
||
107 | } |
||
108 | elseif($y === $dimension){ |
||
109 | $points[$offset + 1] = $dimension - 1; |
||
110 | $nudged = true; |
||
111 | } |
||
173 |