| Conditions | 8 |
| Paths | 34 |
| Total Lines | 73 |
| Code Lines | 44 |
| 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 |
||
| 87 | public function overview() { |
||
| 88 | $icons = array( |
||
| 89 | RfcLogLevel::DEBUG => '', |
||
| 90 | RfcLogLevel::INFO => '', |
||
| 91 | RfcLogLevel::NOTICE => '', |
||
| 92 | RfcLogLevel::WARNING => ['#theme' => 'image', 'path' => 'misc/watchdog-warning.png', 'alt' => t('warning'), 'title' => t('warning')], |
||
| 93 | RfcLogLevel::ERROR => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('error'), 'title' => t('error')], |
||
| 94 | RfcLogLevel::CRITICAL => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('critical'), 'title' => t('critical')], |
||
| 95 | RfcLogLevel::ALERT => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('alert'), 'title' => t('alert')], |
||
| 96 | RfcLogLevel::EMERGENCY => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('emergency'), 'title' => t('emergency')], |
||
| 97 | ); |
||
| 98 | |||
| 99 | $collection = $this->watchdog->templateCollection(); |
||
| 100 | $templates = $collection->find([], Logger::LEGACY_TYPE_MAP)->toArray(); |
||
| 101 | ksm($templates); |
||
| 102 | $this->moduleHandler->loadInclude('mongodb_watchdog', 'admin.inc'); |
||
| 103 | |||
| 104 | $build['dblog_filter_form'] = $this->formBuilder->getForm('Drupal\mongodb_watchdog\Form\MongodbWatchdogFilterForm'); |
||
| 105 | |||
| 106 | $header = array( |
||
| 107 | // Icon column. |
||
| 108 | '', |
||
| 109 | t('#'), |
||
| 110 | array('data' => t('Type')), |
||
| 111 | array('data' => t('Date')), |
||
| 112 | t('Source'), |
||
| 113 | t('Message'), |
||
| 114 | ); |
||
| 115 | |||
| 116 | $rows = array(); |
||
| 117 | foreach ($templates as $id => $value) { |
||
| 118 | if ($id < 5) { |
||
| 119 | // if ($value['type'] == 'php' && $value['message'] == '%type: %message in %function (line %line of %file).') { |
||
| 120 | // $collection = $this->logger->eventCollection($value['_id']); |
||
| 121 | // $result = $collection->find() |
||
| 122 | // ->sort(['$natural' => -1]) |
||
| 123 | // ->limit(1) |
||
| 124 | // ->getNext(); |
||
| 125 | // if ($value) { |
||
| 126 | // $value['file'] = basename($result['variables']['%file']); |
||
| 127 | // $value['line'] = $result['variables']['%line']; |
||
| 128 | // $value['message'] = '%type in %function'; |
||
| 129 | // $value['variables'] = $result['variables']; |
||
| 130 | // } |
||
| 131 | // } |
||
| 132 | $message = Unicode::truncate(strip_tags(SafeMarkup::format($value['message'], [])), 56, TRUE, TRUE); |
||
| 133 | $value['count'] = $this->watchdog->eventCollection($value['_id'])->count(); |
||
| 134 | $rows[$id] = [ |
||
| 135 | $icons[$value['severity']], |
||
| 136 | isset($value['count']) && $value['count'] > 1 ? intval($value['count']) : 0, |
||
| 137 | t($value['type']), |
||
| 138 | empty($value['timestamp']) ? '' : format_date($value['timestamp'], 'short'), |
||
| 139 | empty($value['file']) ? '' : Unicode::truncate(basename($value['file']), 30) . (empty($value['line']) ? '' : ('+' . $value['line'])), |
||
| 140 | \Drupal::l($message, Url::fromRoute('mongodb_watchdog.reports.detail', ['event_template' => $id])), |
||
| 141 | ]; |
||
| 142 | } |
||
| 143 | |||
| 144 | } |
||
| 145 | kint($rows); |
||
| 146 | $build['mongodb_watchdog_table'] = array( |
||
| 147 | '#theme' => 'table', |
||
| 148 | '#header' => $header, |
||
| 149 | '#rows' => $rows, |
||
| 150 | '#attributes' => ['id' => 'admin-mongodb_watchdog'], |
||
| 151 | '#attached' => array( |
||
| 152 | 'library' => array('mongodb_watchdog/drupal.mongodb_watchdog'), |
||
| 153 | ), |
||
| 154 | ); |
||
| 155 | |||
| 156 | $build['mongodb_watchdog_pager'] = array('#type' => 'pager'); |
||
| 157 | |||
| 158 | return $build; |
||
| 159 | } |
||
| 160 | |||
| 187 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.