| Conditions | 10 |
| Paths | 42 |
| Total Lines | 46 |
| Code Lines | 26 |
| 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 |
||
| 140 | protected function createDashboardConfig() |
||
| 141 | { |
||
| 142 | $adminMetadata = $this->objAdminMetadata(); |
||
| 143 | $dashboardIdent = $this->dashboardIdent(); |
||
| 144 | |||
| 145 | if (empty($dashboardIdent)) { |
||
| 146 | $dashboardIdent = filter_input(INPUT_GET, 'dashboard_ident', FILTER_SANITIZE_STRING); |
||
| 147 | } |
||
| 148 | |||
| 149 | if (empty($dashboardIdent)) { |
||
| 150 | if (isset($adminMetadata['default_doc_dashboard'])) { |
||
| 151 | $dashboardIdent = $adminMetadata['default_doc_dashboard']; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | $overrideType = false; |
||
| 156 | |||
| 157 | if (empty($dashboardIdent)) { |
||
| 158 | if (!isset($adminMetadata['default_edit_dashboard'])) { |
||
| 159 | throw new Exception(sprintf( |
||
| 160 | 'No default doc dashboard defined in admin metadata for %s', |
||
| 161 | get_class($this->obj()) |
||
| 162 | )); |
||
| 163 | } |
||
| 164 | $overrideType = true; |
||
| 165 | $dashboardIdent = $adminMetadata['default_edit_dashboard']; |
||
| 166 | } |
||
| 167 | |||
| 168 | if (!isset($adminMetadata['dashboards']) || !isset($adminMetadata['dashboards'][$dashboardIdent])) { |
||
| 169 | throw new Exception( |
||
| 170 | 'Dashboard config is not defined.' |
||
| 171 | ); |
||
| 172 | } |
||
| 173 | |||
| 174 | $dashboardConfig = $adminMetadata['dashboards'][$dashboardIdent]; |
||
| 175 | |||
| 176 | if ($overrideType) { |
||
| 177 | $widgets = $dashboardConfig['widgets']; |
||
| 178 | foreach ($widgets as $ident => $widget) { |
||
| 179 | $dashboardConfig['widgets'][$ident]['type'] = 'charcoal/admin/widget/doc'; |
||
| 180 | $dashboardConfig['widgets'][$ident]['show_header'] = true; |
||
| 181 | $dashboardConfig['widgets'][$ident]['show_title'] = true; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | return $dashboardConfig; |
||
| 186 | } |
||
| 209 |