Conditions | 4 |
Paths | 2 |
Total Lines | 52 |
Code Lines | 29 |
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 |
||
84 | public function grabEntries(&$obj) |
||
|
|||
85 | { |
||
86 | global $xoopsDB; |
||
87 | $myts = \MyTextSanitizer::getInstance(); |
||
88 | $ret = false; |
||
89 | $i = 0; |
||
90 | // The following example code grabs the latest entries from the module |
||
91 | $sql = 'SELECT t.tra_id, t.tra_datecreated, t.tra_year, t.tra_nb, t.tra_desc, a1.acc_key, a1.acc_name, a2.all_name, a3.as_name, c.cli_name '; |
||
92 | $sql .= 'FROM (((' . $xoopsDB->prefix('wgsimpleacc_transactions') . ' t INNER JOIN ' . $xoopsDB->prefix('wgsimpleacc_accounts') . ' a1 '; |
||
93 | $sql .= 'ON t.tra_accid = a1.acc_id) INNER JOIN ' . $xoopsDB->prefix('wgsimpleacc_allocations') . ' a2 ON t.tra_allid = a2.all_id) '; |
||
94 | $sql .= 'INNER JOIN ' . $xoopsDB->prefix('wgsimpleacc_assets') . ' a3 ON t.tra_asid = a3.as_id) '; |
||
95 | $sql .= 'LEFT JOIN ' . $xoopsDB->prefix('wgsimpleacc_clients') . ' c ON t.tra_cliid = c.cli_id '; |
||
96 | $sql .= 'ORDER BY t.tra_datecreated DESC'; |
||
97 | |||
98 | $result = $xoopsDB->query($sql, $this->grab, 0); |
||
99 | if ($result instanceof \mysqli_result) { |
||
100 | $ret = []; |
||
101 | while (false !== ($row = $xoopsDB->fetchArray($result))) { |
||
102 | $link = XOOPS_URL . '/modules/' . $this->dirname . '/transactions.php?op=show&tra_id=' . $row['tra_id']; |
||
103 | /* |
||
104 | * Required elements of an RSS item |
||
105 | */ |
||
106 | // 1. Title of an item |
||
107 | $ret[$i]['title'] = $row['tra_year'] . '/' . $row['tra_nb']; |
||
108 | // 2. URL of an item |
||
109 | $ret[$i]['link'] = $link; |
||
110 | // 3. Item modification date, must be in Unix time format |
||
111 | $ret[$i]['timestamp'] = $row['tra_datecreated']; |
||
112 | // 4. The item synopsis, or description, whatever |
||
113 | $ret[$i]['description'] = \strip_tags($row['tra_desc']); |
||
114 | /* |
||
115 | * Optional elements of an RSS item |
||
116 | */ |
||
117 | // 5. The item synopsis, or description, whatever |
||
118 | $ret[$i]['guid'] = $link; |
||
119 | // 6. A string + domain that identifies a categorization taxonomy |
||
120 | $ret[$i]['category'] = $this->modname; |
||
121 | $ret[$i]['domain'] = XOOPS_URL . '/modules/' . $this->dirname . '/'; |
||
122 | // 7. extra tags examples |
||
123 | $ret[$i]['extras'] = []; |
||
124 | // 7a. without attribute |
||
125 | $ret[$i]['extras']['account'] = ['content' => $row['acc_name']]; |
||
126 | $ret[$i]['extras']['allocation'] = ['content' => $row['all_name']]; |
||
127 | if (\strlen(\strip_tags($row['cli_name'])) > 0) { |
||
128 | $ret[$i]['extras']['client'] = ['content' => \strip_tags($row['cli_name'])]; |
||
129 | } |
||
130 | // 7b. with attributes |
||
131 | //$ret[$i]['extras']['enclosure']['attributes'] = ['url' => 'url-to-any-file', 'length' => 1024000, 'type' => 'audio/mpeg']; |
||
132 | $i++; |
||
133 | } |
||
134 | } |
||
135 | return $ret; |
||
136 | } |
||
138 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.