| Conditions | 10 |
| Paths | 21 |
| Total Lines | 43 |
| 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 |
||
| 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; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | $text = $b; |
||
| 76 | for ($e = 0; $e < count($d); $e++) { |
||
| 77 | $text = $this->rl($text + $d[$e], '+-a^+6'); |
||
| 78 | } |
||
| 79 | $text = $this->rl($text, '+-3^+b+-f'); |
||
| 80 | $text ^= static::TKK[1]; |
||
| 81 | if (0 > $text) { |
||
| 82 | $text = ($text & 2147483647) + 2147483648; |
||
| 83 | } |
||
| 84 | $text = fmod($text, pow(10, 6)); |
||
| 85 | |||
| 86 | $this->tokens[$hash] = $text . '.' . ($text ^ $b); |
||
| 87 | |||
| 88 | return $this->tokens[$hash]; |
||
| 89 | } |
||
| 90 | |||
| 167 |
Adding a
@returnannotation 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.