| Conditions | 12 |
| Paths | 12 |
| Total Lines | 58 |
| Code Lines | 36 |
| 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 |
||
| 140 | private function parseSizeForJPEG() |
||
| 141 | { |
||
| 142 | $state = null; |
||
| 143 | $i = 0; |
||
| 144 | |||
| 145 | while (true) |
||
| 146 | { |
||
| 147 | switch ($state) |
||
| 148 | { |
||
| 149 | default: |
||
| 150 | $this->getChars(2); |
||
| 151 | $state = 'started'; |
||
| 152 | break; |
||
| 153 | |||
| 154 | case 'started': |
||
| 155 | $b = $this->getByte(); |
||
| 156 | if ($b === false) return false; |
||
| 157 | |||
| 158 | $state = $b == 0xFF ? 'sof' : 'started'; |
||
| 159 | break; |
||
| 160 | |||
| 161 | case 'sof': |
||
| 162 | $b = $this->getByte(); |
||
| 163 | if (in_array($b, range(0xe0, 0xef))) |
||
| 164 | { |
||
| 165 | $state = 'skipframe'; |
||
| 166 | } |
||
| 167 | elseif (in_array($b, array_merge(range(0xC0,0xC3), range(0xC5,0xC7), range(0xC9,0xCB), range(0xCD,0xCF)))) |
||
| 168 | { |
||
| 169 | $state = 'readsize'; |
||
| 170 | } |
||
| 171 | elseif ($b == 0xFF) |
||
| 172 | { |
||
| 173 | $state = 'sof'; |
||
| 174 | } |
||
| 175 | else |
||
| 176 | { |
||
| 177 | $state = 'skipframe'; |
||
| 178 | } |
||
| 179 | break; |
||
| 180 | |||
| 181 | case 'skipframe': |
||
| 182 | $skip = $this->readInt($this->getChars(2)) - 2; |
||
| 183 | $state = 'doskip'; |
||
| 184 | break; |
||
| 185 | |||
| 186 | case 'doskip': |
||
| 187 | $this->getChars($skip); |
||
| 188 | $state = 'started'; |
||
| 189 | break; |
||
| 190 | |||
| 191 | case 'readsize': |
||
| 192 | $c = $this->getChars(7); |
||
| 193 | |||
| 194 | return array($this->readInt(substr($c, 5, 2)), $this->readInt(substr($c, 3, 2))); |
||
| 195 | } |
||
| 196 | } |
||
| 197 | } |
||
| 198 | |||
| 254 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: