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 | public function overview() { |
||
70 | $icons = array( |
||
71 | LogLevel::DEBUG => '', |
||
72 | LogLevel::INFO => '', |
||
73 | LogLevel::NOTICE => '', |
||
74 | LogLevel::WARNING => ['#theme' => 'image', 'path' => 'misc/watchdog-warning.png', 'alt' => t('warning'), 'title' => t('warning')], |
||
75 | LogLevel::ERROR => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('error'), 'title' => t('error')], |
||
76 | LogLevel::CRITICAL => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('critical'), 'title' => t('critical')], |
||
77 | LogLevel::ALERT => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('alert'), 'title' => t('alert')], |
||
78 | LogLevel::EMERGENCY => ['#theme' => 'image', 'path' => 'misc/watchdog-error.png', 'alt' => t('emergency'), 'title' => t('emergency')], |
||
79 | ); |
||
80 | |||
81 | $collection = $this->database->selectCollection(Logger::TEMPLATE_COLLECTION); |
||
82 | $cursor = $collection->find(); |
||
83 | |||
84 | $header = array( |
||
85 | // Icon column. |
||
86 | '', |
||
87 | t('#'), |
||
88 | array('data' => t('Type')), |
||
89 | array('data' => t('Date')), |
||
90 | t('Source'), |
||
91 | t('Message'), |
||
92 | ); |
||
93 | |||
94 | $rows = array(); |
||
95 | foreach ($cursor as $id => $value) { |
||
96 | // dsm($value, $id); |
||
97 | /* |
||
98 | if ($value['type'] == 'php' && $value['message'] == '%type: %message in %function (line %line of %file).') { |
||
99 | $collection = $this->logger->eventCollection($value['_id']); |
||
100 | $result = $collection->find() |
||
101 | ->sort(array('$natural' => -1)) |
||
102 | ->limit(1) |
||
103 | ->getNext(); |
||
104 | if ($value) { |
||
105 | $value['file'] = basename($result['variables']['%file']); |
||
106 | $value['line'] = $result['variables']['%line']; |
||
107 | $value['message'] = '%type in %function'; |
||
108 | $value['variables'] = $result['variables']; |
||
109 | } |
||
110 | } |
||
111 | */ |
||
112 | $message = ''; //Unicode::truncate(strip_tags(SafeMarkup::format($value)), 56, TRUE, TRUE); |
||
113 | //$value['count'] = $this->logger->eventCollection($value['_id'])->count(); |
||
114 | $rows[$id] = array( |
||
115 | //$icons[$value['severity']], |
||
116 | isset($value['count']) && $value['count'] > 1 ? intval($value['count']) : 0, |
||
117 | t($value['type']), |
||
118 | empty($value['timestamp']) ? '' : format_date($value['timestamp'], 'short'), |
||
119 | empty($value['file']) ? '' : Unicode::truncate(basename($value['file']), 30) . (empty($value['line']) ? '' : ('+' . $value['line'])), |
||
120 | \Drupal::l($message, Url::fromRoute('mongodb_watchdog.reports.detail', ['event_template' => $id])), |
||
121 | ); |
||
122 | } |
||
123 | |||
124 | $build['mongodb_watchdog_table'] = array( |
||
125 | '#theme' => 'table', |
||
126 | '#header' => $header, |
||
127 | '#rows' => $rows, |
||
128 | '#attributes' => ['id' => 'admin-mongodb_watchdog'], |
||
129 | ); |
||
130 | |||
131 | |||
132 | return $build; |
||
133 | } |
||
134 | |||
157 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..