| 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 |
||
| 44 | public function renderLine($row) |
||
| 45 | { |
||
| 46 | $html = ''; |
||
| 47 | $firstCol = true; |
||
| 48 | |||
| 49 | $titleNames = array_keys($this->titles); |
||
| 50 | foreach ($titleNames as $rowkey ) |
||
| 51 | { |
||
| 52 | // Check missing value |
||
| 53 | if (property_exists($row, $rowkey)) |
||
| 54 | { |
||
| 55 | switch ($rowkey) |
||
| 56 | { |
||
| 57 | case 'action_match': // display text levels |
||
| 58 | case 'action_nomatch': |
||
| 59 | $val=$this->status_display[$row->$rowkey]; |
||
| 60 | break; |
||
| 61 | case 'trap_oid': // try to traslate oids. |
||
| 62 | |||
| 63 | if ($this->doTranslate === true) |
||
| 64 | { |
||
| 65 | $oidName = $this->MIB->translateOID($row->$rowkey); |
||
| 66 | if (isset($oidName['name'])) |
||
| 67 | { |
||
| 68 | $val=$oidName['name']; |
||
| 69 | } |
||
| 70 | else |
||
| 71 | { |
||
| 72 | $val = $row->$rowkey; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | else |
||
| 76 | { |
||
| 77 | $val = $row->$rowkey; |
||
| 78 | } |
||
| 79 | break; |
||
| 80 | case 'host_name': // switch to hostgroup if name is null |
||
| 81 | if ($row->$rowkey == null) |
||
| 82 | { |
||
| 83 | $val = $row->host_group_name; |
||
| 84 | } |
||
| 85 | else |
||
| 86 | { |
||
| 87 | $val = $row->$rowkey; |
||
| 88 | } |
||
| 89 | break; |
||
| 90 | default: |
||
| 91 | $val = $row->$rowkey; |
||
| 92 | } |
||
| 93 | if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
||
| 94 | { |
||
| 95 | |||
| 96 | } |
||
| 97 | } else { |
||
| 98 | $val = '-'; |
||
| 99 | } |
||
| 100 | if ($firstCol === true) { // Put link in first column for trap detail. |
||
| 101 | $html .= '<td>' |
||
| 102 | . $this->view->qlink( |
||
| 103 | $this->view->escape($val), |
||
| 104 | Url::fromPath( |
||
| 105 | $this->urlPath . '/handler/add', |
||
| 106 | array('ruleid' => $row->id) |
||
| 107 | ) |
||
| 108 | ) |
||
| 109 | . '</td>'; |
||
| 110 | } else { |
||
| 111 | $html .= '<td>' . $this->view->escape($val) . '</td>'; |
||
| 112 | } |
||
| 113 | $firstCol=false; |
||
| 114 | |||
| 115 | } |
||
| 116 | return $html; |
||
| 117 | } |
||
| 119 | } |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.