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