| Conditions | 14 |
| Paths | 18 |
| Total Lines | 47 |
| Lines | 22 |
| Ratio | 46.81 % |
| 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 |
||
| 55 | public function current(): string { |
||
| 56 | switch($this->i) { |
||
| 57 | /** @noinspection PhpMissingBreakStatementInspection */ |
||
| 58 | case 0: |
||
|
|
|||
| 59 | $forcedLang = $this->config->getSystemValue('force_language', false); |
||
| 60 | if(is_string($forcedLang)) { |
||
| 61 | return $forcedLang; |
||
| 62 | } |
||
| 63 | $this->next(); |
||
| 64 | /** @noinspection PhpMissingBreakStatementInspection */ |
||
| 65 | View Code Duplication | case 1: |
|
| 66 | $forcedLang = $this->config->getSystemValue('force_language', false); |
||
| 67 | if(is_string($forcedLang) |
||
| 68 | && ($truncated = $this->getTruncatedLanguage($forcedLang)) !== $forcedLang |
||
| 69 | ) { |
||
| 70 | return $truncated; |
||
| 71 | } |
||
| 72 | $this->next(); |
||
| 73 | /** @noinspection PhpMissingBreakStatementInspection */ |
||
| 74 | case 2: |
||
| 75 | $userLang = $this->config->getUserValue($this->user->getUID(), 'core', 'lang', null); |
||
| 76 | if(is_string($userLang)) { |
||
| 77 | return $userLang; |
||
| 78 | } |
||
| 79 | $this->next(); |
||
| 80 | /** @noinspection PhpMissingBreakStatementInspection */ |
||
| 81 | View Code Duplication | case 3: |
|
| 82 | $userLang = $this->config->getUserValue($this->user->getUID(), 'core', 'lang', null); |
||
| 83 | if(is_string($userLang) |
||
| 84 | && ($truncated = $this->getTruncatedLanguage($userLang)) !== $userLang |
||
| 85 | ) { |
||
| 86 | return $truncated; |
||
| 87 | } |
||
| 88 | $this->next(); |
||
| 89 | case 4: |
||
| 90 | return $this->config->getSystemValue('default_language', 'en'); |
||
| 91 | /** @noinspection PhpMissingBreakStatementInspection */ |
||
| 92 | View Code Duplication | case 5: |
|
| 93 | $defaultLang = $this->config->getSystemValue('default_language', 'en'); |
||
| 94 | if(($truncated = $this->getTruncatedLanguage($defaultLang)) !== $defaultLang) { |
||
| 95 | return $truncated; |
||
| 96 | } |
||
| 97 | $this->next(); |
||
| 98 | default: |
||
| 99 | return 'en'; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 138 |