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