Conditions | 11 |
Paths | 25 |
Total Lines | 51 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
43 | public function next() |
||
44 | { |
||
45 | do { |
||
46 | |||
47 | if($this->bit == -1) { |
||
48 | $this->bit = 0; |
||
49 | return array('x'=>$this->x, 'y'=>$this->y); |
||
50 | } |
||
51 | |||
52 | $x = $this->x; |
||
53 | $y = $this->y; |
||
54 | $w = $this->width; |
||
55 | |||
56 | if($this->bit == 0) { |
||
57 | $x--; |
||
58 | $this->bit++; |
||
59 | } else { |
||
60 | $x++; |
||
61 | $y += $this->dir; |
||
62 | $this->bit--; |
||
63 | } |
||
64 | |||
65 | if($this->dir < 0) { |
||
66 | if($y < 0) { |
||
67 | $y = 0; |
||
68 | $x -= 2; |
||
69 | $this->dir = 1; |
||
70 | if($x == 6) { |
||
71 | $x--; |
||
72 | $y = 9; |
||
73 | } |
||
74 | } |
||
75 | } else { |
||
76 | if($y == $w) { |
||
77 | $y = $w - 1; |
||
78 | $x -= 2; |
||
79 | $this->dir = -1; |
||
80 | if($x == 6) { |
||
81 | $x--; |
||
82 | $y -= 8; |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | if($x < 0 || $y < 0) return null; |
||
87 | |||
88 | $this->x = $x; |
||
89 | $this->y = $y; |
||
90 | |||
91 | } while(ord($this->frame[$y][$x]) & 0x80); |
||
92 | |||
93 | return array('x'=>$x, 'y'=>$y); |
||
94 | } |
||
96 | } |