Conditions | 14 |
Paths | 52 |
Total Lines | 77 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 2 |
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 |
||
64 | public function renderLine($row) |
||
65 | { |
||
66 | $html = ''; |
||
67 | $firstCol = true; |
||
68 | |||
69 | $titleNames = array_keys($this->titles); |
||
70 | foreach ($titleNames as $rowkey ) |
||
71 | { |
||
72 | // Check missing value |
||
73 | if (property_exists($row, $rowkey)) |
||
74 | { |
||
75 | switch ($rowkey) |
||
76 | { |
||
77 | case 'action_match': // display text levels |
||
78 | case 'action_nomatch': |
||
79 | $val=$this->status_display[$row->$rowkey]; |
||
80 | break; |
||
81 | case 'trap_oid': // try to traslate oids. |
||
82 | |||
83 | if ($this->doTranslate === true) |
||
84 | { |
||
85 | $oidName = $this->MIB->translateOID($row->$rowkey); |
||
86 | if (isset($oidName['name'])) |
||
87 | { |
||
88 | $val=$oidName['name']; |
||
89 | } |
||
90 | else |
||
91 | { |
||
92 | $val = $row->$rowkey; |
||
93 | } |
||
94 | } |
||
95 | else |
||
96 | { |
||
97 | $val = $row->$rowkey; |
||
98 | } |
||
99 | break; |
||
100 | case 'host_name': // switch to hostgroup if name is null |
||
101 | if ($row->$rowkey == null) |
||
102 | { |
||
103 | $val = $row->host_group_name; |
||
104 | } |
||
105 | else |
||
106 | { |
||
107 | $val = $row->$rowkey; |
||
108 | } |
||
109 | break; |
||
110 | default: |
||
111 | $val = $row->$rowkey; |
||
112 | } |
||
113 | if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
||
114 | { |
||
115 | |||
116 | } |
||
117 | } else { |
||
118 | $val = '-'; |
||
119 | } |
||
120 | if ($firstCol === true) { // Put link in first column for trap detail. |
||
121 | $html .= '<td class="traphover">' |
||
122 | . $this->view->qlink( |
||
123 | $this->view->escape($val), |
||
124 | Url::fromPath( |
||
125 | $this->urlPath . '/handler/add', |
||
126 | array('ruleid' => $row->id) |
||
127 | ) |
||
128 | ); |
||
129 | if ($row->comment != '') |
||
130 | { |
||
131 | $html.= '<span class="tohover">'. $row->comment .'</span></td>'; |
||
132 | } |
||
133 | $html.= '</td>'; |
||
134 | } else { |
||
135 | $html .= '<td>' . $this->view->escape($val) . '</td>'; |
||
136 | } |
||
137 | $firstCol=false; |
||
138 | |||
139 | } |
||
140 | return $html; |
||
141 | } |
||
143 | } |
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.