| Conditions | 7 |
| Paths | 33 |
| Total Lines | 63 |
| Code Lines | 37 |
| 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 |
||
| 65 | public function overview() { |
||
| 66 | $icons = array( |
||
| 67 | WATCHDOG_DEBUG => '', |
||
| 68 | WATCHDOG_INFO => '', |
||
| 69 | WATCHDOG_NOTICE => '', |
||
| 70 | WATCHDOG_WARNING => ['#theme' => 'image', 'path' => 'misc/watchdog-warning.png', 'alt' => t('warning'), 'title' => t('warning')], |
||
| 71 | WATCHDOG_ERROR => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('error'), 'title' => t('error')], |
||
| 72 | WATCHDOG_CRITICAL => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('critical'), 'title' => t('critical')], |
||
| 73 | WATCHDOG_ALERT => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('alert'), 'title' => t('alert')], |
||
| 74 | WATCHDOG_EMERGENCY => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('emergency'), 'title' => t('emergency')], |
||
| 75 | ); |
||
| 76 | |||
| 77 | $collection = $this->database->selectCollection(Logger::TEMPLATE_COLLECTION); |
||
| 78 | $cursor = $collection->find(); |
||
| 79 | |||
| 80 | $header = array( |
||
| 81 | // Icon column. |
||
| 82 | '', |
||
| 83 | t('#'), |
||
| 84 | array('data' => t('Type')), |
||
| 85 | array('data' => t('Date')), |
||
| 86 | t('Source'), |
||
| 87 | t('Message'), |
||
| 88 | ); |
||
| 89 | |||
| 90 | $rows = array(); |
||
| 91 | foreach ($cursor as $id => $value) { |
||
| 92 | dsm($value, $id); |
||
| 93 | // if ($value['type'] == 'php' && $value['message'] == '%type: %message in %function (line %line of %file).') { |
||
| 94 | // $collection = $this->logger->eventCollection($value['_id']); |
||
| 95 | // $result = $collection->find() |
||
| 96 | // ->sort(array('$natural' => -1)) |
||
| 97 | // ->limit(1) |
||
| 98 | // ->getNext(); |
||
| 99 | // if ($value) { |
||
| 100 | // $value['file'] = basename($result['variables']['%file']); |
||
| 101 | // $value['line'] = $result['variables']['%line']; |
||
| 102 | // $value['message'] = '%type in %function'; |
||
| 103 | // $value['variables'] = $result['variables']; |
||
| 104 | // } |
||
| 105 | // } |
||
| 106 | $message = Unicode::truncate(strip_tags(SafeMarkup::format($value)), 56, TRUE, TRUE); |
||
| 107 | $value['count'] = $this->logger->eventCollection($value['_id'])->count(); |
||
| 108 | $rows[$id] = array( |
||
| 109 | $icons[$value['severity']], |
||
| 110 | isset($value['count']) && $value['count'] > 1 ? intval($value['count']) : 0, |
||
| 111 | t($value['type']), |
||
| 112 | empty($value['timestamp']) ? '' : format_date($value['timestamp'], 'short'), |
||
| 113 | empty($value['file']) ? '' : Unicode::truncate(basename($value['file']), 30) . (empty($value['line']) ? '' : ('+' . $value['line'])), |
||
| 114 | \Drupal::l($message, Url::fromRoute('mongodb_watchdog.detail', ['id' => $id])), |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | |||
| 118 | $build['mongodb_watchdog_table'] = array( |
||
| 119 | '#theme' => 'table', |
||
| 120 | '#header' => $header, |
||
| 121 | '#rows' => $rows, |
||
| 122 | '#attributes' => ['id' => 'admin-mongodb_watchdog'], |
||
| 123 | ); |
||
| 124 | |||
| 125 | |||
| 126 | return $build; |
||
| 127 | } |
||
| 128 | |||
| 230 |