| Conditions | 11 |
| Paths | 22 |
| Total Lines | 50 |
| Code Lines | 34 |
| 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 displayPathAsString($path, $route) |
||
| 86 | { |
||
| 87 | $prefix = ''; |
||
| 88 | $translationPrefix = $route->getTranslationPrefix(); |
||
| 89 | if (!empty($translationPrefix)) { |
||
| 90 | $prefix = '/' . $translationPrefix; |
||
| 91 | } |
||
| 92 | |||
| 93 | if ($route->getTranslatable()) { |
||
| 94 | $languages = ZLanguage::getInstalledLanguages(); |
||
| 95 | $isRequiredLangParam = ZLanguage::isRequiredLangParam(); |
||
| 96 | if (!$isRequiredLangParam) { |
||
| 97 | $defaultLanguage = $this->variableApi->getSystemVar('language_i18n'); |
||
| 98 | unset($languages[array_search($defaultLanguage, $languages)]); |
||
| 99 | } |
||
| 100 | if (count($languages) > 0) { |
||
| 101 | $prefix = ($isRequiredLangParam ? '/' : '{/') . implode('|', $languages) . ($isRequiredLangParam ? '' : '}'); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | $prefix = htmlspecialchars($prefix); |
||
| 106 | $path = htmlspecialchars($route->getPathWithBundlePrefix()); |
||
| 107 | $container = $this->container; |
||
| 108 | |||
| 109 | $path = preg_replace_callback('#%(.*?)%#', function ($matches) use ($container) { |
||
| 110 | return '<abbr title="' . htmlspecialchars($matches[0]) . '">' . htmlspecialchars($container->getParameter($matches[1])) . '</abbr>'; |
||
| 111 | }, $path); |
||
| 112 | |||
| 113 | $defaults = $route->getDefaults(); |
||
| 114 | $requirements = $route->getRequirements(); |
||
| 115 | $path = preg_replace_callback('#{(.*?)}#', function ($matches) use ($defaults, $requirements) { |
||
| 116 | $title = ''; |
||
| 117 | if (isset($defaults[$matches[1]])) { |
||
| 118 | $title .= $this->__f('Default: %s', ['%s' => htmlspecialchars($defaults[$matches[1]])]); |
||
| 119 | } |
||
| 120 | if (isset($requirements[$matches[1]])) { |
||
| 121 | if ($title != '') { |
||
| 122 | $title .= ' | '; |
||
| 123 | } |
||
| 124 | $title .= $this->__f('Requirement: %s', ['%s' => htmlspecialchars($requirements[$matches[1]])]); |
||
| 125 | } |
||
| 126 | if ($title == '') { |
||
| 127 | return $matches[0]; |
||
| 128 | } |
||
| 129 | |||
| 130 | return '<abbr title="' . $title . '">' . $matches[0] . '</abbr>'; |
||
| 131 | }, $path); |
||
| 132 | |||
| 133 | return $prefix . '<strong>' . $path . '</strong>'; |
||
| 134 | } |
||
| 135 | } |
||
| 136 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.