Conditions | 7 |
Paths | 16 |
Total Lines | 59 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
36 | public function render() |
||
37 | { |
||
38 | $data=$this->getTable(); |
||
39 | $view = $this->getView(); |
||
40 | $this->columnCount = count($this->getTitles()); |
||
41 | $this->lastDay=null; |
||
42 | // Table start |
||
43 | $htm = '<table class="simple common-table table-row-selectable">'; |
||
44 | |||
45 | // Titles |
||
46 | $htm .= "<thead>\n <tr>\n"; |
||
47 | $titles = $this->getTitles(); |
||
48 | foreach ($titles as $title) |
||
49 | { |
||
50 | $htm .= ' <th>' . $view->escape($view->translate($title)) . "</th>\n"; |
||
51 | } |
||
52 | $htm .= " </tr>\n</thead>\n"; |
||
53 | |||
54 | // Rows |
||
55 | $htm .= "<tbody>\n"; |
||
56 | |||
57 | foreach ($data as $row) |
||
58 | { |
||
59 | $firstCol = true; |
||
60 | // Put date header |
||
61 | $htm .= $this->renderDayIfNew($row->timestamp); |
||
62 | |||
63 | |||
64 | // Render row |
||
65 | $htm .= '<tr>'; |
||
66 | foreach ( $titles as $rowkey => $title) |
||
67 | { |
||
68 | // Check missing value |
||
69 | if (property_exists($row, $rowkey)) |
||
70 | { |
||
71 | $val = ($rowkey=='timestamp') ? strftime('%T',$row->$rowkey) : $row->$rowkey; |
||
72 | } else { |
||
73 | $val = '-'; |
||
74 | } |
||
75 | if ($firstCol == true) { // Put link in first column for trap detail. |
||
|
|||
76 | $htm .= '<td>' |
||
77 | . $view->qlink( |
||
78 | $view->escape($val), |
||
79 | Url::fromPath( |
||
80 | $this->moduleConfig->urlPath() . '/received/trapdetail', |
||
81 | array('id' => $row->id) |
||
82 | ) |
||
83 | ) |
||
84 | . '</td>'; |
||
85 | } else { |
||
86 | $htm .= '<td>' . $view->escape($val) . '</td>'; |
||
87 | } |
||
88 | $firstCol=false; |
||
89 | } |
||
90 | $htm .= "<tr>\n"; |
||
91 | } |
||
92 | $htm .= "</tbody></table>\n"; |
||
93 | //$htm .= "Filter : " . $this->filter."<br>\n"; |
||
94 | return $htm; |
||
95 | |||
230 | } |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.