| Conditions | 12 |
| Paths | 36 |
| Total Lines | 79 |
| Code Lines | 53 |
| 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 |
||
| 112 | public function render(): string |
||
| 113 | { |
||
| 114 | $str = ''; |
||
| 115 | |||
| 116 | /** @var RouteCollectionInterface $routes */ |
||
| 117 | $routes = $this->router->routes(); |
||
| 118 | $actionCount = 0; |
||
| 119 | $color = $this->config->get('platform.sidebar_color_scheme', 'primary'); |
||
| 120 | |||
| 121 | foreach ($this->data as $group => $sidebar) { |
||
| 122 | $str .= sprintf( |
||
| 123 | '<div class="list-group page-sidebar">' |
||
| 124 | . '<a href="#" class="sidebar-action list-group-item list-group-item-%s"><b>%s</b></a>', |
||
| 125 | $color, |
||
| 126 | $group |
||
| 127 | ); |
||
| 128 | |||
| 129 | foreach ($sidebar as $data) { |
||
| 130 | $name = $data['name']; |
||
| 131 | $route = $routes->get($name); |
||
| 132 | $permission = $route->getAttribute('permission'); |
||
| 133 | if ($permission !== null && $this->authorization->isGranted($permission) === false) { |
||
| 134 | continue; |
||
| 135 | } |
||
| 136 | |||
| 137 | $actionCount++; |
||
| 138 | |||
| 139 | $attributes = ''; |
||
| 140 | $query = ''; |
||
| 141 | $title = Str::ucfirst($data['title']); |
||
| 142 | $csrf = (bool) $route->getAttribute('csrf'); |
||
| 143 | if ($csrf) { |
||
| 144 | if (!isset($data['extras']['query'])) { |
||
| 145 | $data['extras']['query'] = []; |
||
| 146 | } |
||
| 147 | $data['extras']['query'] = array_merge( |
||
| 148 | $data['extras']['query'], |
||
| 149 | $this->csrfManager->getTokenQuery() |
||
| 150 | ); |
||
| 151 | } |
||
| 152 | |||
| 153 | if (count($data['extras']) > 0) { |
||
| 154 | $extras = $data['extras']; |
||
| 155 | if (isset($extras['confirm'])) { |
||
| 156 | $confirmMessage = $extras['confirm_message'] ?? |
||
| 157 | $this->lang->tr('Do you want to proceed with this operation? [%s] ?', $title); |
||
| 158 | unset($extras['confirm'], $extras['confirm_message']); |
||
| 159 | $extras['data-text-confirm'] = $confirmMessage; |
||
| 160 | } |
||
| 161 | if (isset($extras['query'])) { |
||
| 162 | $query = Arr::query($extras['query']); |
||
| 163 | unset($extras['query']); |
||
| 164 | } |
||
| 165 | $attributes = Str::toAttribute($extras); |
||
| 166 | } |
||
| 167 | $url = sprintf( |
||
| 168 | '%s%s', |
||
| 169 | $this->router->getUri( |
||
| 170 | $data['name'], |
||
| 171 | $data['params'] |
||
| 172 | ), |
||
| 173 | (!empty($query) ? '?' . $query : '') |
||
| 174 | ); |
||
| 175 | |||
| 176 | $str .= sprintf( |
||
| 177 | '<a %s class="list-group-item list-group-item-action" href="%s">%s</a>', |
||
| 178 | $attributes, |
||
| 179 | $url, |
||
| 180 | $title |
||
| 181 | ); |
||
| 182 | } |
||
| 183 | $str .= '</div>'; |
||
| 184 | } |
||
| 185 | |||
| 186 | if ($actionCount === 0) { |
||
| 187 | return ''; |
||
| 188 | } |
||
| 189 | |||
| 190 | return $str; |
||
| 191 | } |
||
| 193 |