| Conditions | 14 |
| Paths | 12 |
| Total Lines | 44 |
| Code Lines | 31 |
| 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 |
||
| 58 | public static function characterValue(string $string): int |
||
| 59 | { |
||
| 60 | $n = 0; |
||
| 61 | $length = \mb_strlen($string); |
||
| 62 | |||
| 63 | if ($length === 0) { |
||
| 64 | return 0; |
||
| 65 | } |
||
| 66 | |||
| 67 | $c = $string[$n++]; |
||
| 68 | |||
| 69 | if ($c !== '\\') { |
||
| 70 | return \ord($c); |
||
| 71 | } |
||
| 72 | |||
| 73 | $c = $string[$n++]; |
||
| 74 | if (self::isOctal($c)) { |
||
| 75 | $value = (int) $c; |
||
| 76 | for ($i = 0; $n < $length && self::isOctal($string[$n]) && $i < 3; $i++) { |
||
| 77 | $value = $value * 8 + $string[$n++]; |
||
| 78 | } |
||
| 79 | |||
| 80 | return $value; |
||
| 81 | } |
||
| 82 | |||
| 83 | switch ($c) { |
||
| 84 | case 'n': |
||
| 85 | return \ord("\n"); |
||
| 86 | case 't': |
||
| 87 | return \ord("\t"); |
||
| 88 | case 'b': |
||
| 89 | return \ord("\x08"); |
||
| 90 | case 'r': |
||
| 91 | return \ord("\r"); |
||
| 92 | case 'f': |
||
| 93 | return \ord("\x0C"); |
||
| 94 | case 'v': |
||
| 95 | return \ord("\x0B"); |
||
| 96 | case 'a': |
||
| 97 | return \ord("\x07"); |
||
| 98 | default: |
||
| 99 | return \ord($c); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 212 |