Conditions | 10 |
Paths | 6 |
Total Lines | 32 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
9 | public function encode(int ...$symbolList): string |
||
10 | { |
||
11 | $buffer = ''; |
||
12 | foreach ($symbolList as $symbol) { |
||
13 | if (0x00 <= $symbol && $symbol <= 0x7F) { |
||
14 | $buffer .= chr($symbol); |
||
15 | continue; |
||
16 | } |
||
17 | if (0x80 <= $symbol && $symbol <= 0x07FF) { |
||
18 | $buffer .= |
||
19 | chr(0xC0 | ($symbol >> 0x06)) . |
||
20 | chr(0x80 | ($symbol & 0x3F)); |
||
21 | continue; |
||
22 | } |
||
23 | if (0x0800 <= $symbol && $symbol <= 0xFFFF) { |
||
24 | $buffer .= |
||
25 | chr(0xE0 | ($symbol >> 0x0C)) . |
||
26 | chr(0x80 | (($symbol >> 0x06) & 0x3F)) . |
||
27 | chr(0x80 | ($symbol & 0x3F)); |
||
28 | continue; |
||
29 | } |
||
30 | if (0x010000 <= $symbol && $symbol <= 0x10FFFF) { |
||
31 | $buffer .= |
||
32 | chr(0xF0 | ($symbol >> 0x12)) . |
||
33 | chr(0x80 | (($symbol >> 0x0C) & 0x3F)) . |
||
34 | chr(0x80 | (($symbol >> 0x06) & 0x3F)) . |
||
35 | chr(0x80 | ($symbol & 0x3F)); |
||
36 | continue; |
||
37 | } |
||
38 | $buffer .= '�'; |
||
39 | } |
||
40 | return $buffer; |
||
41 | } |
||
43 |