| Conditions | 1 |
| Paths | 1 |
| Total Lines | 67 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 125 | private function getIncludeUpdateVersion($moduleDirname, $moduleVersion) |
||
| 126 | { |
||
| 127 | $ret = <<<EOT |
||
| 128 | // irmtfan bug fix: solve templates duplicate issue |
||
| 129 | /** |
||
| 130 | * @param \$module |
||
| 131 | * |
||
| 132 | * @return bool |
||
| 133 | */ |
||
| 134 | function update_{$moduleDirname}_v{$moduleVersion}(&\$module) |
||
| 135 | { |
||
| 136 | global \$xoopsDB; |
||
| 137 | \$result = \$xoopsDB->query( |
||
| 138 | "SELECT t1.tpl_id FROM " . \$xoopsDB->prefix('tplfile') . " t1, " . \$xoopsDB->prefix('tplfile') |
||
| 139 | . " t2 WHERE t1.tpl_refid = t2.tpl_refid AND t1.tpl_module = t2.tpl_module AND t1.tpl_tplset=t2.tpl_tplset AND t1.tpl_file = t2.tpl_file AND t1.tpl_type = t2.tpl_type AND t1.tpl_id > t2.tpl_id" |
||
| 140 | ); |
||
| 141 | \$tplids = array(); |
||
| 142 | while (list(\$tplid) = \$xoopsDB->fetchRow(\$result)) { |
||
| 143 | \$tplids[] = \$tplid; |
||
| 144 | } |
||
| 145 | if (count(\$tplids) > 0) { |
||
| 146 | \$tplfile_handler = xoops_getHandler('tplfile'); |
||
| 147 | \$duplicate_files = \$tplfile_handler->getObjects( |
||
| 148 | new Criteria('tpl_id', "(" . implode(',', \$tplids) . ")", "IN") |
||
| 149 | ); |
||
| 150 | |||
| 151 | if (count(\$duplicate_files) > 0) { |
||
| 152 | foreach (array_keys(\$duplicate_files) as \$i) { |
||
| 153 | \$tplfile_handler->delete(\$duplicate_files[\$i]); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | \$sql = "SHOW INDEX FROM " . \$xoopsDB->prefix('tplfile') . " WHERE KEY_NAME = 'tpl_refid_module_set_file_type'"; |
||
| 158 | if (!\$result = \$xoopsDB->queryF(\$sql)) { |
||
| 159 | xoops_error(\$this->db->error() . '<br />' . \$sql); |
||
| 160 | |||
| 161 | return false; |
||
| 162 | } |
||
| 163 | \$ret = array(); |
||
| 164 | while (\$myrow = \$xoopsDB->fetchArray(\$result)) { |
||
| 165 | \$ret[] = \$myrow; |
||
| 166 | } |
||
| 167 | if (!empty(\$ret)) { |
||
| 168 | \$module->setErrors( |
||
| 169 | "'tpl_refid_module_set_file_type' unique index is exist. Note: check 'tplfile' table to be sure this index is UNIQUE because XOOPS CORE need it." |
||
| 170 | ); |
||
| 171 | |||
| 172 | return true; |
||
| 173 | } |
||
| 174 | \$sql = "ALTER TABLE " . \$xoopsDB->prefix('tplfile') |
||
| 175 | . " ADD UNIQUE tpl_refid_module_set_file_type ( tpl_refid, tpl_module, tpl_tplset, tpl_file, tpl_type )"; |
||
| 176 | if (!\$result = \$xoopsDB->queryF(\$sql)) { |
||
| 177 | xoops_error(\$xoopsDB->error() . '<br />' . \$sql); |
||
| 178 | \$module->setErrors( |
||
| 179 | "'tpl_refid_module_set_file_type' unique index is not added to 'tplfile' table. Warning: do not use XOOPS until you add this unique index." |
||
| 180 | ); |
||
| 181 | |||
| 182 | return false; |
||
| 183 | } |
||
| 184 | |||
| 185 | return true; |
||
| 186 | } |
||
| 187 | // irmtfan bug fix: solve templates duplicate issue |
||
| 188 | EOT; |
||
| 189 | |||
| 190 | return $ret; |
||
| 191 | } |
||
| 192 | |||
| 215 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.