| Conditions | 14 |
| Paths | 49 |
| Total Lines | 55 |
| Code Lines | 27 |
| 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 |
||
| 85 | public function generateI18nPatterns($routeName, Route $route) |
||
| 86 | { |
||
| 87 | $patterns = []; |
||
| 88 | foreach ($route->getOption('i18n_locales') ?: $this->locales as $locale) { |
||
| 89 | // Check if translation exists in the translation catalogue |
||
| 90 | if ($this->translator instanceof TranslatorBagInterface) { |
||
| 91 | // Check if route is translated. |
||
| 92 | if (!$this->translator->getCatalogue($locale)->has($routeName, $this->translationDomain)) { |
||
| 93 | // No translation found. |
||
| 94 | $i18nPattern = $route->getPath(); |
||
| 95 | } else { |
||
| 96 | // Get translation. |
||
| 97 | $i18nPattern = $this->translator->trans(/** @Ignore */$routeName, [], $this->translationDomain, $locale); |
||
| 98 | } |
||
| 99 | } else { |
||
| 100 | // if no translation exists, we use the current pattern |
||
| 101 | if ($routeName === $i18nPattern = $this->translator->trans(/** @Ignore */$routeName, [], $this->translationDomain, $locale)) { |
||
| 102 | $i18nPattern = $route->getPath(); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | /////////////////////////////////////// |
||
| 107 | // Begin customizations |
||
| 108 | |||
| 109 | // prefix with zikula module url if requested |
||
| 110 | if ($route->hasDefault('_zkModule')) { |
||
| 111 | $module = $route->getDefault('_zkModule'); |
||
| 112 | $zkNoBundlePrefix = $route->getOption('zkNoBundlePrefix'); |
||
| 113 | if (!isset($zkNoBundlePrefix) || !$zkNoBundlePrefix) { |
||
| 114 | $untranslatedPrefix = $this->getUrlString($module); |
||
| 115 | if ($this->translator->getCatalogue($locale)->has($untranslatedPrefix, strtolower($module))) { |
||
|
|
|||
| 116 | $prefix = $this->translator->trans(/** @Ignore */$untranslatedPrefix, [], strtolower($module), $locale); |
||
| 117 | } else { |
||
| 118 | $prefix = $untranslatedPrefix; |
||
| 119 | } |
||
| 120 | $i18nPattern = '/' . $prefix . $i18nPattern; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | // End customizations |
||
| 125 | /////////////////////////////////////// |
||
| 126 | |||
| 127 | // prefix with locale if requested |
||
| 128 | if (self::STRATEGY_PREFIX === $this->strategy |
||
| 129 | || (self::STRATEGY_PREFIX_EXCEPT_DEFAULT === $this->strategy && $this->defaultLocale !== $locale)) { |
||
| 130 | $i18nPattern = '/' . $locale . $i18nPattern; |
||
| 131 | if (null !== $route->getOption('i18n_prefix')) { |
||
| 132 | $i18nPattern = $route->getOption('i18n_prefix') . $i18nPattern; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | $patterns[$i18nPattern][] = $locale; |
||
| 137 | } |
||
| 138 | |||
| 139 | return $patterns; |
||
| 140 | } |
||
| 171 |