| Conditions | 13 |
| Paths | 98 |
| Total Lines | 95 |
| Code Lines | 69 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 84 | $GLOBALS['xoopsDB']->query($sql); |
||
| 85 | $pictureField = $_FILES['photo']['name']; |
||
| 86 | if (empty($pictureField) || '' == $pictureField) { |
||
| 87 | //llalalala |
||
| 88 | } else { |
||
| 89 | $foto = Utility::uploadPicture(0); |
||
| 90 | // $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " SET foto='" . $foto . "' WHERE id='" . $a . "'"; |
||
| 91 | $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " SET foto='" . $GLOBALS['xoopsDB']->escape($foto) . "' WHERE id='" . $a . "'"; |
||
| 92 | } |
||
| 93 | $GLOBALS['xoopsDB']->query($sql); |
||
| 94 | if ('1' == $helper->getConfig('ownerbreeder')) { |
||
| 95 | // $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " SET id_owner = '" . $_POST['id_owner'] . "', id_breeder = '" . $_POST['id_breeder'] . "' WHERE id='" . $a . "'"; |
||
| 96 | $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " SET id_owner = '" . Request::getInt('id_owner', 0, 'post') . "', id_breeder = '" . Request::getInt('id_breeder', 0, 'post') . "' WHERE id='" . $a . "'"; |
||
| 97 | $GLOBALS['xoopsDB']->query($sql); |
||
| 98 | } |
||
| 99 | redirect_header('dog.php?id=' . $a, 2, 'Your changes have been saved'); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param int $id |
||
| 104 | */ |
||
| 105 | function edit($id = 0) |
||
| 106 | { |
||
| 107 | global $xoopsTpl, $xoopsDB, $moduleConfig; |
||
| 108 | if (isset($_GET['id'])) { |
||
| 109 | $id = Request::getInt('id', 0, 'GET); |
||
| 110 | } |
||
| 111 | require XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
|
|
|||
| 112 | |||
| 113 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' WHERE id=' . $id; |
||
| 114 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 115 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 116 | $form = new \XoopsThemeForm('Edit ' . $row['pname'], 'dogname', 'edit.php?f=save', 'post', true); |
||
| 117 | $form->addElement(new \XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360)); |
||
| 118 | $form->addElement(new \XoopsFormHidden('id', $id)); |
||
| 119 | //name |
||
| 120 | $pname = htmlentities(stripslashes($row['pname']), ENT_QUOTES); |
||
| 121 | $form->addElement(new \XoopsFormText('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', 'pname', $size = 50, $maxsize = 255, $value = $pname)); |
||
| 122 | //gender |
||
| 123 | $roft = $row['roft']; |
||
| 124 | $gender_radio = new \XoopsFormRadio('<b>' . _MA_PEDIGREE_FLD_GEND . '</b>', 'roft', $value = $roft); |
||
| 125 | $gender_radio->addOptionArray([ |
||
| 126 | '0' => strtr(_MA_PEDIGREE_FLD_MALE, ['[male]' => $moduleConfig['male']]), |
||
| 127 | '1' => strtr(_MA_PEDIGREE_FLD_FEMA, ['[female]' => $moduleConfig['female']]), |
||
| 128 | ]); |
||
| 129 | $form->addElement($gender_radio); |
||
| 130 | //father |
||
| 131 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id='" . $row['father'] . "'"; |
||
| 132 | $resfather = $GLOBALS['xoopsDB']->query($sql); |
||
| 133 | $numfields = $GLOBALS['xoopsDB']->getRowsNum($resfather); |
||
| 134 | if ('0' == !$numfields) { |
||
| 135 | while (false !== ($rowfetch = $GLOBALS['xoopsDB']->fetchArray($resfather))) { |
||
| 136 | $form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_FATH, ['[father]' => $moduleConfig['father']]) . '</b>', '<img src="assets/images/male.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=0&letter=a">' . $rowfetch['pname'] . '</a>')); |
||
| 137 | } |
||
| 138 | } else { |
||
| 139 | $form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_FATH, ['[father]' => $moduleConfig['father']]) . '</b>', '<img src="assets/images/male.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=0&letter=a">Unknown</a>')); |
||
| 140 | } |
||
| 141 | //mother |
||
| 142 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id='" . $row['mother'] . "'"; |
||
| 143 | $resmother = $GLOBALS['xoopsDB']->query($sql); |
||
| 144 | $numfields = $GLOBALS['xoopsDB']->getRowsNum($resmother); |
||
| 145 | if ('0' == !$numfields) { |
||
| 146 | while (false !== ($rowfetch = $GLOBALS['xoopsDB']->fetchArray($resmother))) { |
||
| 147 | $form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_MOTH, ['[mother]' => $moduleConfig['mother']]) . '</b>', '<img src="assets/images/female.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=1&letter=a">' . $rowfetch['pname'] . '</a>')); |
||
| 148 | } |
||
| 149 | } else { |
||
| 150 | $form->addElement(new \XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_MOTH, ['[mother]' => $moduleConfig['mother']]) . '</b>', '<img src="assets/images/female.gif"><a href="seldog.php?curval=' . $row['id'] . '&gend=1&letter=a">Unknown</a>')); |
||
| 151 | } |
||
| 152 | //owner/breeder |
||
| 153 | if ('1' == $helper->getConfig('ownerbreeder')) { |
||
| 154 | $owner_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_OWNE . '</b>', $name = 'id_owner', $value = $row['id_owner'], $size = 1, $multiple = false); |
||
| 155 | $queryeig = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY "lastname"'; |
||
| 156 | $reseig = $GLOBALS['xoopsDB']->query($queryeig); |
||
| 157 | $owner_select->addOption(0, $name = _MA_PEDIGREE_UNKNOWN); |
||
| 158 | while (false !== ($roweig = $GLOBALS['xoopsDB']->fetchArray($reseig))) { |
||
| 159 | $owner_select->addOption($roweig['id'], $name = $roweig['lastname'] . ', ' . $roweig['firstname']); |
||
| 160 | } |
||
| 161 | $form->addElement($owner_select); |
||
| 162 | //breeder |
||
| 163 | $breeder_select = new \XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_BREE . '</b>', $name = 'id_breeder', $value = $row['id_breeder'], $size = 1, $multiple = false); |
||
| 164 | $queryfok = 'SELECT id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . ' ORDER BY "lastname"'; |
||
| 165 | $resfok = $GLOBALS['xoopsDB']->query($queryfok); |
||
| 166 | $breeder_select->addOption(0, $name = _MA_PEDIGREE_UNKNOWN); |
||
| 167 | while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) { |
||
| 168 | $breeder_select->addOption($rowfok['id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']); |
||
| 169 | } |
||
| 170 | $form->addElement($breeder_select); |
||
| 171 | } |
||
| 172 | //picture |
||
| 173 | if ('' != $row['foto']) { |
||
| 174 | $picture = '<img src=' . PEDIGREE_UPLOAD_URL . '/images/thumbnails/' . $row['foto'] . '_400.jpeg>'; |
||
| 175 | $form->addElement(new \XoopsFormLabel('<b>Picture</b>', $picture)); |
||
| 176 | } else { |
||
| 177 | $picture = ''; |
||
| 178 | } |
||
| 179 | $form->setExtra("enctype='multipart/form-data'"); |
||
| 204 |