| Conditions | 12 |
| Paths | 50 |
| Total Lines | 42 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 |
||
| 94 | public function getSupportedLocales(bool $includeRegions = true): array |
||
| 95 | { |
||
| 96 | $this->sectionKey = $includeRegions ? 'withRegions' : 'withoutRegions'; |
||
| 97 | |||
| 98 | if (!empty($this->supportedLocales[$this->sectionKey])) { |
||
| 99 | return $this->supportedLocales[$this->sectionKey]; |
||
| 100 | } |
||
| 101 | |||
| 102 | $this->supportedLocales[$this->sectionKey][] = $this->defaultLocale; |
||
| 103 | if (!$this->installed) { |
||
| 104 | return $this->supportedLocales[$this->sectionKey]; |
||
| 105 | } |
||
| 106 | |||
| 107 | if (!is_dir($this->translationPath)) { |
||
| 108 | return $this->supportedLocales[$this->sectionKey]; |
||
| 109 | } |
||
| 110 | |||
| 111 | $multiLingualEnabled = (bool) $this->variableApi->get(VariableApi::CONFIG, 'multilingual', 1); |
||
| 112 | if ($multiLingualEnabled) { |
||
| 113 | // read in locales from translation path |
||
| 114 | $this->collectLocales($includeRegions); |
||
| 115 | } |
||
| 116 | |||
| 117 | // ensure config file is still in sync |
||
| 118 | if (true === $includeRegions) { |
||
| 119 | $syncConfig = true; |
||
| 120 | if (null !== $this->requestStack) { |
||
| 121 | $request = $this->requestStack->getCurrentRequest(); |
||
| 122 | if (null === $request) { |
||
| 123 | $syncConfig = false; |
||
| 124 | } elseif ($request->isXmlHttpRequest()) { |
||
| 125 | $syncConfig = false; |
||
| 126 | } elseif ($request !== $this->requestStack->getMasterRequest()) { |
||
| 127 | $syncConfig = false; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | if ($syncConfig) { |
||
| 131 | $this->localeConfigHelper->updateConfiguration($this->supportedLocales[$this->sectionKey]); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | return $this->supportedLocales[$this->sectionKey]; |
||
| 136 | } |
||
| 193 |