| Conditions | 10 |
| Paths | 97 |
| Total Lines | 64 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 158 | public function buildForm(array $form, FormStateInterface $form_state) { |
||
| 159 | |||
| 160 | $form = array(); |
||
| 161 | $icons = array( |
||
| 162 | WATCHDOG_DEBUG => '', |
||
| 163 | WATCHDOG_INFO => '', |
||
| 164 | WATCHDOG_NOTICE => '', |
||
| 165 | WATCHDOG_WARNING => ['#theme' => 'image', 'path' => 'misc/watchdog-warning.png', 'alt' => t('warning'), 'title' => t('warning')], |
||
| 166 | WATCHDOG_ERROR => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('error'), 'title' => t('error')], |
||
| 167 | WATCHDOG_CRITICAL => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('critical'), 'title' => t('critical')], |
||
| 168 | WATCHDOG_ALERT => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('alert'), 'title' => t('alert')], |
||
| 169 | WATCHDOG_EMERGENCY => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('emergency'), 'title' => t('emergency')], |
||
| 170 | ); |
||
| 171 | |||
| 172 | $collection = $this->database->selectCollection(Logger::TEMPLATE_COLLECTION); |
||
| 173 | $cursor = $collection->find(); |
||
| 174 | |||
| 175 | $header = array( |
||
| 176 | // Icon column. |
||
| 177 | '', |
||
| 178 | t('#'), |
||
| 179 | array('data' => t('Type')), |
||
| 180 | array('data' => t('Date')), |
||
| 181 | t('Source'), |
||
| 182 | t('Message'), |
||
| 183 | ); |
||
| 184 | |||
| 185 | $rows = array(); |
||
| 186 | foreach ($cursor as $id => $value) { |
||
| 187 | dsm($value, $id); |
||
| 188 | if ($value['type'] == 'php' && $value['message'] == '%type: %message in %function (line %line of %file).') { |
||
| 189 | $collection = $this->logger->eventCollection($value['_id']); |
||
| 190 | $result = $collection->find() |
||
| 191 | ->sort(array('$natural' => -1)) |
||
| 192 | ->limit(1) |
||
| 193 | ->getNext(); |
||
| 194 | if ($value) { |
||
| 195 | $value['file'] = basename($result['variables']['%file']); |
||
| 196 | $value['line'] = $result['variables']['%line']; |
||
| 197 | $value['message'] = '%type in %function'; |
||
| 198 | $value['variables'] = $result['variables']; |
||
| 199 | } |
||
| 200 | } |
||
| 201 | $message = Unicode::truncate(strip_tags(SafeMarkup::format($value['message'], array())), 56, TRUE, TRUE); |
||
| 202 | $value['count'] = $this->logger->eventCollection($value['_id'])->count(); |
||
| 203 | $rows[$id] = array( |
||
| 204 | $icons[$value['severity']], |
||
| 205 | isset($value['count']) && $value['count'] > 1 ? intval($value['count']) : 0, |
||
| 206 | t($value['type']), |
||
| 207 | empty($value['timestamp']) ? '' : format_date($value['timestamp'], 'short'), |
||
| 208 | empty($value['file']) ? '' : Unicode::truncate(basename($value['file']), 30) . (empty($value['line']) ? '' : ('+' . $value['line'])), |
||
| 209 | \Drupal::l($message, Url::fromRoute('mongodb_watchdog.detail', ['id' => $id])), |
||
| 210 | ); |
||
| 211 | } |
||
| 212 | |||
| 213 | $form['mongodb_watchdog_table'] = array( |
||
| 214 | '#theme' => 'table', |
||
| 215 | '#header' => $header, |
||
| 216 | '#rows' => $rows, |
||
| 217 | '#attributes' => ['id' => 'admin-mongodb_watchdog'], |
||
| 218 | ); |
||
| 219 | |||
| 220 | return $form; |
||
| 221 | } |
||
| 222 | |||
| 230 |