| Conditions | 11 |
| Paths | 22 |
| Total Lines | 54 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 73 | public function displayPathAsString(string $path, RouteEntity $route): string |
||
| 74 | { |
||
| 75 | $prefix = ''; |
||
| 76 | $translationPrefix = $route->getTranslationPrefix(); |
||
| 77 | if (!empty($translationPrefix)) { |
||
| 78 | $prefix = '/' . $translationPrefix; |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($route->getTranslatable()) { |
||
| 82 | $languages = $this->localeApi->getSupportedLocales(); |
||
| 83 | $isRequiredLangParameter = $this->variableApi->getSystemVar('languageurl', 0); |
||
| 84 | if (!$isRequiredLangParameter) { |
||
| 85 | $defaultLanguage = $this->variableApi->getSystemVar('locale'); |
||
| 86 | unset($languages[array_search($defaultLanguage, $languages, true)]); |
||
| 87 | } |
||
| 88 | if (count($languages) > 0) { |
||
| 89 | $prefix = ($isRequiredLangParameter ? '/' : '{/') . implode('|', $languages) . ($isRequiredLangParameter ? '' : '}'); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | $prefix = htmlspecialchars($prefix); |
||
| 94 | $path = htmlspecialchars( |
||
| 95 | $this->pathBuilderHelper->getPathWithBundlePrefix($route) |
||
| 96 | ); |
||
| 97 | |||
| 98 | $container = $this->container; |
||
| 99 | $path = preg_replace_callback('#%(.*?)%#', static function ($matches) use ($container) { |
||
| 100 | return '<abbr title="' . htmlspecialchars($matches[0]) . '">' |
||
| 101 | . htmlspecialchars($container->getParameter($matches[1])) |
||
| 102 | . '</abbr>' |
||
| 103 | ; |
||
| 104 | }, $path); |
||
| 105 | |||
| 106 | $defaults = $route->getDefaults(); |
||
| 107 | $requirements = $route->getRequirements(); |
||
| 108 | $path = preg_replace_callback('#{(.*?)}#', function ($matches) use ($defaults, $requirements) { |
||
| 109 | $title = ''; |
||
| 110 | if (isset($defaults[$matches[1]])) { |
||
| 111 | $title .= $this->trans('Default: %value%', ['%value%' => htmlspecialchars($defaults[$matches[1]])]); |
||
| 112 | } |
||
| 113 | if (isset($requirements[$matches[1]])) { |
||
| 114 | if ('' !== $title) { |
||
| 115 | $title .= ' | '; |
||
| 116 | } |
||
| 117 | $title .= $this->trans('Requirement: %value%', ['%value%' => htmlspecialchars($requirements[$matches[1]])]); |
||
| 118 | } |
||
| 119 | if ('' === $title) { |
||
| 120 | return $matches[0]; |
||
| 121 | } |
||
| 122 | |||
| 123 | return '<abbr title="' . $title . '">' . $matches[0] . '</abbr>'; |
||
| 124 | }, $path); |
||
| 125 | |||
| 126 | return $prefix . '<strong>' . $path . '</strong>'; |
||
| 127 | } |
||
| 142 |