| Conditions | 13 |
| Paths | 388 |
| Total Lines | 92 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 16 | * elements: |
||
| 17 | * - title: Title of the filter. |
||
| 18 | * - where: The filter condition. |
||
| 19 | * - options: Array of options for the select list for the filter. |
||
| 20 | */ |
||
| 21 | function mongodb_watchdog_filters() { |
||
| 22 | $filters = array(); |
||
| 23 | |||
| 24 | foreach (_dblog_get_message_types() as $type) { |
||
| 25 | $types[$type] = t($type); |
||
| 26 | } |
||
| 27 | |||
| 28 | if (!empty($types)) { |
||
| 29 | $filters['type'] = array( |
||
| 30 | 'title' => t('Type'), |
||
| 31 | 'where' => "w.type = ?", |
||
| 32 | 'options' => $types, |
||
| 33 | ); |
||
| 34 | } |
||
| 35 | |||
| 36 | $filters['severity'] = array( |
||
| 37 | 'title' => t('Severity'), |
||
| 38 | 'where' => 'w.severity = ?', |
||
| 39 | 'options' => RfcLogLevel::getLevels(), |
||
| 40 | ); |
||
| 41 | |||
| 42 | return $filters; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Build the filter form. |
||
| 47 | * |
||
| 48 | * @return array |
||
| 49 | * A form array |
||
| 50 | */ |
||
| 51 | function mongodb_watchdog_filter_form($form) { |
||
| 52 | $filters = mongodb_watchdog_filters(); |
||
| 53 | |||
| 54 | $form['filters'] = array( |
||
| 55 | '#type' => 'fieldset', |
||
| 56 | '#title' => t('Filter log messages'), |
||
| 57 | '#collapsible' => TRUE, |
||
| 58 | '#collapsed' => empty($_SESSION), |
||
| 59 | '#attached' => array( |
||
| 60 | 'css' => array( |
||
| 61 | drupal_get_path('module', 'mongodb_watchdog') . '/mongodb_watchdog.css', |
||
| 62 | )), |
||
| 63 | ); |
||
| 64 | |||
| 65 | View Code Duplication | foreach ($filters as $key => $filter) { |
|
| 66 | $form['filters']['status'][$key] = array( |
||
| 67 | '#title' => check_plain($filter['title']), |
||
| 68 | '#type' => 'select', |
||
| 69 | '#multiple' => TRUE, |
||
| 70 | '#size' => 8, |
||
| 71 | '#options' => $filter['options'], |
||
| 72 | ); |
||
| 73 | if (!empty($_SESSION['mongodb_watchdog_overview_filter'][$key])) { |
||
| 74 | $form['filters']['status'][$key]['#default_value'] = $_SESSION['mongodb_watchdog_overview_filter'][$key]; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | $form['filters']['buttons']['submit'] = array( |
||
| 79 | '#type' => 'submit', |
||
| 80 | '#value' => t('Filter'), |
||
| 81 | ); |
||
| 82 | if (!empty($_SESSION['mongodb_watchdog_overview_filter'])) { |
||
| 83 | $form['filters']['buttons']['reset'] = array( |
||
| 84 | '#type' => 'submit', |
||
| 85 | '#value' => t('Reset') |
||
| 86 | ); |
||
| 87 | } |
||
| 88 | |||
| 89 | return $form; |
||
| 90 | } |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Validate result from mongodb_watchdog administration filter form. |
||
| 94 | */ |
||
| 95 | function mongodb_watchdog_filter_form_validate($form, &$form_state) { |
||
| 96 | if ($form_state['values']['op'] == t('Filter') && empty($form_state['values']['type']) && empty($form_state['values']['severity'])) { |
||
| 97 | form_set_error('type', t('You must select something to filter by.')); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Process result from mongodb_watchdog administration filter form. |
||
| 103 | */ |
||
| 104 | function mongodb_watchdog_filter_form_submit($form, &$form_state) { |
||
| 105 | $op = $form_state['values']['op']; |
||
| 106 | $filters = mongodb_watchdog_filters(); |
||
| 107 | switch ($op) { |
||
| 108 | case t('Filter'): |
||
| 219 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.