| Conditions | 8 |
| Paths | 34 |
| Total Lines | 71 |
| Code Lines | 41 |
| 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 |
||
| 191 | public function overview7() { |
||
| 192 | $icons = array( |
||
| 193 | RfcLogLevel::DEBUG => '', |
||
| 194 | RfcLogLevel::INFO => '', |
||
| 195 | RfcLogLevel::NOTICE => '', |
||
| 196 | RfcLogLevel::WARNING => ['#theme' => 'image', 'path' => 'misc/watchdog-warning.png', 'alt' => t('warning'), 'title' => t('warning')], |
||
| 197 | RfcLogLevel::ERROR => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('error'), 'title' => t('error')], |
||
| 198 | RfcLogLevel::CRITICAL => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('critical'), 'title' => t('critical')], |
||
| 199 | RfcLogLevel::ALERT => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('alert'), 'title' => t('alert')], |
||
| 200 | RfcLogLevel::EMERGENCY => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('emergency'), 'title' => t('emergency')], |
||
| 201 | ); |
||
| 202 | |||
| 203 | $collection = $this->watchdog->templateCollection(); |
||
| 204 | $templates = $collection->find([], Logger::LEGACY_TYPE_MAP)->toArray(); |
||
| 205 | $this->moduleHandler->loadInclude('mongodb_watchdog', 'admin.inc'); |
||
| 206 | |||
| 207 | |||
| 208 | $header = array( |
||
| 209 | // Icon column. |
||
| 210 | '', |
||
| 211 | t('#'), |
||
| 212 | array('data' => t('Type')), |
||
| 213 | array('data' => t('Date')), |
||
| 214 | t('Source'), |
||
| 215 | t('Message'), |
||
| 216 | ); |
||
| 217 | |||
| 218 | $rows = array(); |
||
| 219 | foreach ($templates as $id => $value) { |
||
| 220 | if ($id < 5) { |
||
| 221 | // if ($value['type'] == 'php' && $value['message'] == '%type: %message in %function (line %line of %file).') { |
||
| 222 | // $collection = $this->logger->eventCollection($value['_id']); |
||
| 223 | // $result = $collection->find() |
||
| 224 | // ->sort(['$natural' => -1]) |
||
| 225 | // ->limit(1) |
||
| 226 | // ->getNext(); |
||
| 227 | // if ($value) { |
||
| 228 | // $value['file'] = basename($result['variables']['%file']); |
||
| 229 | // $value['line'] = $result['variables']['%line']; |
||
| 230 | // $value['message'] = '%type in %function'; |
||
| 231 | // $value['variables'] = $result['variables']; |
||
| 232 | // } |
||
| 233 | // } |
||
| 234 | $message = Unicode::truncate(strip_tags(SafeMarkup::format($value['message'], [])), 56, TRUE, TRUE); |
||
| 235 | $value['count'] = $this->watchdog->eventCollection($value['_id'])->count(); |
||
| 236 | $rows[$id] = [ |
||
| 237 | $icons[$value['severity']], |
||
| 238 | isset($value['count']) && $value['count'] > 1 ? intval($value['count']) : 0, |
||
| 239 | t($value['type']), |
||
| 240 | empty($value['timestamp']) ? '' : format_date($value['timestamp'], 'short'), |
||
| 241 | empty($value['file']) ? '' : Unicode::truncate(basename($value['file']), 30) . (empty($value['line']) ? '' : ('+' . $value['line'])), |
||
| 242 | \Drupal::l($message, Url::fromRoute('mongodb_watchdog.reports.detail', ['event_template' => $id])), |
||
| 243 | ]; |
||
| 244 | } |
||
| 245 | |||
| 246 | } |
||
| 247 | |||
| 248 | $build['mongodb_watchdog_table'] = array( |
||
| 249 | '#theme' => 'table', |
||
| 250 | '#header' => $header, |
||
| 251 | '#rows' => $rows, |
||
| 252 | '#attributes' => ['id' => 'admin-mongodb_watchdog'], |
||
| 253 | '#attached' => array( |
||
| 254 | 'library' => array('mongodb_watchdog/drupal.mongodb_watchdog'), |
||
| 255 | ), |
||
| 256 | ); |
||
| 257 | |||
| 258 | $build['mongodb_watchdog_pager'] = array('#type' => 'pager'); |
||
| 259 | |||
| 260 | return $build; |
||
| 261 | } |
||
| 262 | |||
| 264 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..