| Conditions | 12 |
| Paths | 32 |
| Total Lines | 66 |
| 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 |
||
| 61 | function xnewsletter_plugin_getdata_xoopsuser( |
||
| 62 | $cat_id, |
||
| 63 | $action_after_read, |
||
| 64 | $limitCheck, |
||
| 65 | $skipCatsubscrExist, |
||
| 66 | $arr_groups) |
||
| 67 | { |
||
| 68 | global $xoopsDB; |
||
| 69 | $helper = Xnewsletter\Helper::getInstance(); |
||
| 70 | |||
| 71 | //$table_import = $xoopsDB->prefix('xnewsletter_import'); |
||
| 72 | $import_status = 0 == $action_after_read ? true : false; |
||
| 73 | $i = 0; |
||
| 74 | $j = 0; |
||
| 75 | |||
| 76 | $sql = "SELECT `email`, `name`,`uname` FROM {$xoopsDB->prefix('groups_users_link')}"; |
||
| 77 | $sql .= " INNER JOIN {$xoopsDB->prefix('users')} ON {$xoopsDB->prefix('groups_users_link')}.uid = {$xoopsDB->prefix('users')}.uid"; |
||
| 78 | $sql .= " WHERE ({$xoopsDB->prefix('groups_users_link')}.groupid IN (" . implode(',', $arr_groups) . '))'; |
||
| 79 | $sql .= ' GROUP BY `email`, `name`, `uname`'; |
||
| 80 | |||
| 81 | if (!$result_users = $xoopsDB->query($sql)) { |
||
| 82 | die('MySQL-Error: ' . $GLOBALS['xoopsDB']->error()); |
||
| 83 | } |
||
| 84 | while (false !== ($lineArray = $xoopsDB->fetchBoth($result_users))) { |
||
| 85 | ++$i; |
||
| 86 | $email = $lineArray[0]; |
||
| 87 | $sex = ''; |
||
| 88 | $firstname = ''; |
||
| 89 | $lastname = ('' == $lineArray[1]) ? $lineArray[2] : $lineArray[1]; |
||
| 90 | |||
| 91 | $subscr_id = xnewsletter_pluginCheckEmail($email); |
||
| 92 | $catsubscr_id = xnewsletter_pluginCheckCatSubscr($subscr_id, $cat_id); |
||
| 93 | |||
| 94 | if (1 == $skipCatsubscrExist && $catsubscr_id > 0) { |
||
| 95 | //skip existing subscriptions |
||
| 96 | } else { |
||
| 97 | $currcatid = $catsubscr_id > 0 ? 0 : $cat_id; |
||
| 98 | $importObj = $helper->getHandler('Import')->create(); |
||
| 99 | $importObj->setVar('import_email', $email); |
||
| 100 | $importObj->setVar('import_sex', $sex); |
||
| 101 | $importObj->setVar('import_firstname', $firstname); |
||
| 102 | $importObj->setVar('import_lastname', $lastname); |
||
| 103 | $importObj->setVar('import_cat_id', $currcatid); |
||
| 104 | $importObj->setVar('import_subscr_id', $subscr_id); |
||
| 105 | $importObj->setVar('import_catsubscr_id', $catsubscr_id); |
||
| 106 | $importObj->setVar('import_status', $import_status); |
||
| 107 | if (!$helper->getHandler('Import')->insert($importObj)) { |
||
| 108 | echo $importObj->getHtmlErrors(); |
||
| 109 | exit(); |
||
| 110 | } |
||
| 111 | // $sql = "INSERT INTO {$table_import} (import_email, import_sex, import_firstname, import_lastname, import_cat_id, import_subscr_id, import_catsubscr_id, import_status)"; |
||
| 112 | // $sql .= " VALUES ('$email', '$sex', '$firstname', '$lastname', $currcatid, $subscr_id, $catsubscr_id, $import_status)"; |
||
| 113 | // $result_insert = $xoopsDB->query($sql) or die ("MySQL-Error: " . $GLOBALS['xoopsDB']->error()); |
||
| 114 | ++$j; |
||
| 115 | } |
||
| 116 | ++$i; |
||
| 117 | if (100000 == $j) { |
||
| 118 | break; |
||
| 119 | } //maximum number of processing to avoid cache overflow |
||
| 120 | if ($limitCheck > 0 && $j == $limitCheck) { |
||
| 121 | $import_status = false; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | return $j; |
||
| 126 | } |
||
| 127 | |||
| 178 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.