Conditions | 10 |
Paths | 40 |
Total Lines | 39 |
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 |
||
33 | */ |
||
34 | public function __construct(string $encoding = 'UTF-8') |
||
35 | { |
||
36 | $this->encoding = $encoding; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Generate and return a token. |
||
41 | * |
||
42 | * @param string $source Source language |
||
43 | * @param string $target Target language |
||
44 | * @param string $text Text to translate |
||
45 | * @return string Token |
||
46 | */ |
||
47 | public function generateToken(string $source, string $target, string $text): string |
||
48 | { |
||
49 | $hash = md5($text); |
||
50 | if (isset($this->tokens[$hash])) { |
||
51 | return $this->tokens[$hash]; |
||
52 | } |
||
53 | |||
54 | $b = static::TKK[0]; |
||
55 | for ($d = [], $e = 0, $f = 0; $f < $this->length($text); $f++) { |
||
56 | $g = $this->charCodeAt($text, $f); |
||
57 | if (128 > $g) { |
||
58 | $d[$e++] = $g; |
||
59 | } else { |
||
60 | if (2048 > $g) { |
||
61 | $d[$e++] = $g >> 6 | 192; |
||
62 | } else { |
||
63 | if (55296 === ($g & 64512) && $f + 1 < $this->length($text) && 56320 === ($this->charCodeAt($text, $f + 1) & 64512)) { |
||
64 | $g = 65536 + (($g & 1023) << 10) + ($this->charCodeAt($text, ++$f) & 1023); |
||
65 | $d[$e++] = $g >> 18 | 240; |
||
66 | $d[$e++] = $g >> 12 & 63 | 128; |
||
67 | } else { |
||
68 | $d[$e++] = $g >> 12 | 224; |
||
69 | } |
||
70 | $d[$e++] = $g >> 6 & 63 | 128; |
||
71 | } |
||
72 | $d[$e++] = $g & 63 | 128; |
||
167 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.