Conditions | 15 |
Paths | 72 |
Total Lines | 100 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
53 | public function render() |
||
54 | { |
||
55 | $data=$this->getTable(); |
||
56 | $view = $this->getView(); |
||
57 | $this->columnCount = count($this->getTitles()); |
||
58 | $this->lastDay=null; |
||
59 | // Table start |
||
60 | $htm = '<table class="simple common-table table-row-selectable">'; |
||
61 | |||
62 | // Titles |
||
63 | $htm .= "<thead>\n <tr>\n"; |
||
64 | $titles = $this->getTitles(); |
||
65 | foreach ($titles as $title) |
||
66 | { |
||
67 | $htm .= ' <th>' . $view->escape($view->translate($title)) . "</th>\n"; |
||
68 | } |
||
69 | $htm .= " </tr>\n</thead>\n"; |
||
70 | |||
71 | // Rows |
||
72 | $htm .= "<tbody>\n"; |
||
73 | |||
74 | foreach ($data as $row) |
||
75 | { |
||
76 | $firstCol = true; |
||
77 | // Put date header |
||
78 | //$htm .= $this->renderDayIfNew($row->timestamp); |
||
79 | |||
80 | |||
81 | // Render row |
||
82 | $htm .= '<tr '.' >'; |
||
83 | foreach ( $titles as $rowkey => $title) |
||
84 | { |
||
85 | // Check missing value |
||
86 | if (property_exists($row, $rowkey)) |
||
87 | { |
||
88 | switch ($rowkey) |
||
89 | { |
||
90 | case 'action_match': // display text levels |
||
91 | case 'action_nomatch': |
||
92 | $val=$this->status_display[$row->$rowkey]; |
||
93 | break; |
||
94 | case 'trap_oid': // try to traslate oids. |
||
95 | |||
96 | if ($this->doTranslate===true) |
||
97 | { |
||
98 | $oidName=$this->MIB->translateOID($row->$rowkey); |
||
99 | if (isset($oidName['name'])) |
||
100 | { |
||
101 | $val=$oidName['name']; |
||
102 | } |
||
103 | else |
||
104 | { |
||
105 | $val = $row->$rowkey; |
||
106 | } |
||
107 | } |
||
108 | else |
||
109 | { |
||
110 | $val = $row->$rowkey; |
||
111 | } |
||
112 | break; |
||
113 | case 'host_name': // switch to hostgroup if name is null |
||
114 | if ($row->$rowkey == null) |
||
115 | { |
||
116 | $val = $row->host_group_name; |
||
117 | } |
||
118 | else |
||
119 | { |
||
120 | $val = $row->$rowkey; |
||
121 | } |
||
122 | break; |
||
123 | default: |
||
124 | $val = $row->$rowkey; |
||
125 | } |
||
126 | if ($rowkey == 'trap_oid' && $this->doTranslate===true) |
||
127 | { |
||
128 | |||
129 | } |
||
130 | } else { |
||
131 | $val = '-'; |
||
132 | } |
||
133 | if ($firstCol === true) { // Put link in first column for trap detail. |
||
134 | $htm .= '<td>' |
||
135 | . $view->qlink( |
||
136 | $view->escape($val), |
||
137 | Url::fromPath( |
||
138 | $this->moduleConfig->urlPath() . '/handler/add', |
||
139 | array('ruleid' => $row->id) |
||
140 | ) |
||
141 | ) |
||
142 | . '</td>'; |
||
143 | } else { |
||
144 | $htm .= '<td>' . $view->escape($val) . '</td>'; |
||
145 | } |
||
146 | $firstCol=false; |
||
147 | } |
||
148 | $htm .= "<tr>\n"; |
||
149 | } |
||
150 | $htm .= "</tbody></table>\n"; |
||
151 | //$htm .= "Filter : " . $this->filter."<br>\n"; |
||
152 | return $htm; |
||
153 | |||
264 |