| Conditions | 7 |
| Paths | 33 |
| Total Lines | 65 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| 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 |
||
| 69 | * @param \Psr\Log\LoggerInterface $logger |
||
| 70 | * The logger service, to log intervening events. |
||
| 71 | * @param \Drupal\mongodb_watchdog\Logger $watchdog |
||
| 72 | * The MongoDB logger, to load stored events. |
||
| 73 | * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler |
||
| 74 | * A module handler. |
||
| 75 | * @param \Drupal\Core\Form\FormBuilderInterface $form_builder |
||
| 76 | * The form builder service. |
||
| 77 | */ |
||
| 78 | public function __construct(Database $database, LoggerInterface $logger, Logger $watchdog, ModuleHandlerInterface $module_handler, FormBuilderInterface $form_builder) { |
||
| 79 | $this->database = $database; |
||
| 80 | $this->logger = $logger; |
||
| 81 | $this->moduleHandler = $module_handler; |
||
| 82 | $this->formBuilder = $form_builder; |
||
| 83 | $this->watchdog = $watchdog; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Controller for mongodb_watchdog.overview. |
||
| 88 | * |
||
| 89 | * @return array |
||
| 90 | * A render array. |
||
| 91 | */ |
||
| 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']; |
||
| 192 |