| Conditions | 13 |
| Paths | 35 |
| Total Lines | 73 |
| Code Lines | 43 |
| 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 |
||
| 34 | public function renderLine($row) |
||
| 35 | { |
||
| 36 | $html = ''; |
||
| 37 | $firstCol = true; |
||
| 38 | |||
| 39 | $titleNames = array_keys($this->titles); |
||
| 40 | foreach ($titleNames as $rowkey ) |
||
| 41 | { |
||
| 42 | // Check missing value |
||
| 43 | if (property_exists($row, $rowkey)) |
||
| 44 | { |
||
| 45 | switch ($rowkey) |
||
| 46 | { |
||
| 47 | case 'action_match': // display text levels |
||
| 48 | case 'action_nomatch': |
||
| 49 | $val=$this->status_display[$row->$rowkey]; |
||
| 50 | break; |
||
| 51 | case 'trap_oid': // try to traslate oids. |
||
| 52 | |||
| 53 | if ($this->doTranslate === true) |
||
| 54 | { |
||
| 55 | $oidName = $this->MIB->translateOID($row->$rowkey); |
||
| 56 | if (isset($oidName['name'])) |
||
| 57 | { |
||
| 58 | $val=$oidName['name']; |
||
| 59 | } |
||
| 60 | else |
||
| 61 | { |
||
| 62 | $val = $row->$rowkey; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | else |
||
| 66 | { |
||
| 67 | $val = $row->$rowkey; |
||
| 68 | } |
||
| 69 | break; |
||
| 70 | case 'host_name': // switch to hostgroup if name is null |
||
| 71 | if ($row->$rowkey == null) |
||
| 72 | { |
||
| 73 | $val = $row->host_group_name; |
||
| 74 | } |
||
| 75 | else |
||
| 76 | { |
||
| 77 | $val = $row->$rowkey; |
||
| 78 | } |
||
| 79 | break; |
||
| 80 | default: |
||
| 81 | $val = $row->$rowkey; |
||
| 82 | } |
||
| 83 | if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
||
| 84 | { |
||
| 85 | |||
| 86 | } |
||
| 87 | } else { |
||
| 88 | $val = '-'; |
||
| 89 | } |
||
| 90 | if ($firstCol === true) { // Put link in first column for trap detail. |
||
| 91 | $html .= '<td>' |
||
| 92 | . $this->view->qlink( |
||
| 93 | $this->view->escape($val), |
||
| 94 | Url::fromPath( |
||
| 95 | $this->urlPath . '/handler/add', |
||
| 96 | array('ruleid' => $row->id) |
||
| 97 | ) |
||
| 98 | ) |
||
| 99 | . '</td>'; |
||
| 100 | } else { |
||
| 101 | $html .= '<td>' . $this->view->escape($val) . '</td>'; |
||
| 102 | } |
||
| 103 | $firstCol=false; |
||
| 104 | |||
| 105 | } |
||
| 106 | return $html; |
||
| 107 | } |
||
| 109 | } |