| Conditions | 8 |
| Paths | 34 |
| Total Lines | 73 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 92 | public function overview() { |
||
| 93 | $icons = array( |
||
| 94 | RfcLogLevel::DEBUG => '', |
||
| 95 | RfcLogLevel::INFO => '', |
||
| 96 | RfcLogLevel::NOTICE => '', |
||
| 97 | RfcLogLevel::WARNING => ['#theme' => 'image', 'path' => 'misc/watchdog-warning.png', 'alt' => t('warning'), 'title' => t('warning')], |
||
| 98 | RfcLogLevel::ERROR => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('error'), 'title' => t('error')], |
||
| 99 | RfcLogLevel::CRITICAL => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('critical'), 'title' => t('critical')], |
||
| 100 | RfcLogLevel::ALERT => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('alert'), 'title' => t('alert')], |
||
| 101 | RfcLogLevel::EMERGENCY => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('emergency'), 'title' => t('emergency')], |
||
| 102 | ); |
||
| 103 | |||
| 104 | $collection = $this->watchdog->templateCollection(); |
||
| 105 | $templates = $collection->find([], TopController::LEGACY_TYPE_MAP)->toArray(); |
||
| 106 | ksm($templates); |
||
| 107 | $this->moduleHandler->loadInclude('mongodb_watchdog', 'admin.inc'); |
||
| 108 | |||
| 109 | $build['dblog_filter_form'] = $this->formBuilder->getForm('Drupal\mongodb_watchdog\Form\MongodbWatchdogFilterForm'); |
||
| 110 | |||
| 111 | $header = array( |
||
| 112 | // Icon column. |
||
| 113 | '', |
||
| 114 | t('#'), |
||
| 115 | array('data' => t('Type')), |
||
| 116 | array('data' => t('Date')), |
||
| 117 | t('Source'), |
||
| 118 | t('Message'), |
||
| 119 | ); |
||
| 120 | |||
| 121 | $rows = array(); |
||
| 122 | foreach ($templates as $id => $value) { |
||
| 123 | if ($id < 5) { |
||
| 124 | // if ($value['type'] == 'php' && $value['message'] == '%type: %message in %function (line %line of %file).') { |
||
| 125 | // $collection = $this->logger->eventCollection($value['_id']); |
||
| 126 | // $result = $collection->find() |
||
| 127 | // ->sort(['$natural' => -1]) |
||
| 128 | // ->limit(1) |
||
| 129 | // ->getNext(); |
||
| 130 | // if ($value) { |
||
| 131 | // $value['file'] = basename($result['variables']['%file']); |
||
| 132 | // $value['line'] = $result['variables']['%line']; |
||
| 133 | // $value['message'] = '%type in %function'; |
||
| 134 | // $value['variables'] = $result['variables']; |
||
| 135 | // } |
||
| 136 | // } |
||
| 137 | $message = Unicode::truncate(strip_tags(SafeMarkup::format($value['message'], [])), 56, TRUE, TRUE); |
||
| 138 | $value['count'] = $this->watchdog->eventCollection($value['_id'])->count(); |
||
| 139 | $rows[$id] = [ |
||
| 140 | $icons[$value['severity']], |
||
| 141 | isset($value['count']) && $value['count'] > 1 ? intval($value['count']) : 0, |
||
| 142 | t($value['type']), |
||
| 143 | empty($value['timestamp']) ? '' : format_date($value['timestamp'], 'short'), |
||
| 144 | empty($value['file']) ? '' : Unicode::truncate(basename($value['file']), 30) . (empty($value['line']) ? '' : ('+' . $value['line'])), |
||
| 145 | \Drupal::l($message, Url::fromRoute('mongodb_watchdog.reports.detail', ['id' => $id])), |
||
| 146 | ]; |
||
| 147 | } |
||
| 148 | |||
| 149 | } |
||
| 150 | kint($rows); |
||
| 151 | $build['mongodb_watchdog_table'] = array( |
||
| 152 | '#theme' => 'table', |
||
| 153 | '#header' => $header, |
||
| 154 | '#rows' => $rows, |
||
| 155 | '#attributes' => ['id' => 'admin-mongodb_watchdog'], |
||
| 156 | '#attached' => array( |
||
| 157 | 'library' => array('mongodb_watchdog/drupal.mongodb_watchdog'), |
||
| 158 | ), |
||
| 159 | ); |
||
| 160 | |||
| 161 | $build['mongodb_watchdog_pager'] = array('#type' => 'pager'); |
||
| 162 | |||
| 163 | return $build; |
||
| 164 | } |
||
| 165 | |||
| 195 |