Conditions | 13 |
Paths | 98 |
Total Lines | 93 |
Code Lines | 68 |
Lines | 23 |
Ratio | 24.73 % |
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 |
||
80 | //name |
||
81 | $naam = htmlentities(stripslashes($row['NAAM']), ENT_QUOTES); |
||
82 | $form->addElement(new XoopsFormText('<b>' . _MA_PEDIGREE_FLD_NAME . '</b>', 'NAAM', $size = 50, $maxsize = 255, $value = $naam)); |
||
83 | //gender |
||
84 | $roft = $row['roft']; |
||
85 | $gender_radio = new XoopsFormRadio('<b>' . _MA_PEDIGREE_FLD_GEND . '</b>', 'roft', $value = $roft); |
||
86 | $gender_radio->addOptionArray(array('0' => strtr(_MA_PEDIGREE_FLD_MALE, array('[male]' => $pedigree->getConfig('male'))), '1' => strtr(_MA_PEDIGREE_FLD_FEMA, array('[female]' => $pedigree->getConfig('female'))))); |
||
87 | $form->addElement($gender_radio); |
||
88 | //father |
||
89 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE Id='" . $row['father'] . "'"; |
||
90 | $resfather = $GLOBALS['xoopsDB']->query($sql); |
||
91 | $numfields = mysqli_num_rows($resfather); |
||
92 | View Code Duplication | if (!$numfields == '0') { |
|
93 | while (false !== ($rowfetch = $GLOBALS['xoopsDB']->fetchArray($resfather))) { |
||
94 | $form->addElement(new XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_FATH, array('[father]' => $pedigree->getConfig('father'))) . '</b>', "<img src=\"assets/images/male.gif\"><a href=\"seldog.php?curval=" . $row['Id'] . "&gend=1&letter=a\">" . $rowfetch['NAAM'] . '</a>')); |
||
95 | } |
||
96 | } else { |
||
97 | $form->addElement(new XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_FATH, array('[father]' => $pedigree->getConfig('father'))) . '</b>', "<img src=\"assets/images/male.gif\"><a href=\"seldog.php?curval=" . $row['Id'] . "&gend=1&letter=a\">Unknown</a>")); |
||
98 | } |
||
99 | //mother |
||
100 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE Id='" . $row['mother'] . "'"; |
||
101 | $resmother = $GLOBALS['xoopsDB']->query($sql); |
||
102 | $numfields = mysqli_num_rows($resmother); |
||
103 | View Code Duplication | if (!$numfields == '0') { |
|
104 | while (false !== ($rowfetch = $GLOBALS['xoopsDB']->fetchArray($resmother))) { |
||
105 | $form->addElement(new XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_MOTH, array('[mother]' => $pedigree->getConfig('mother'))) . '</b>', "<img src=\"assets/images/female.gif\"><a href=\"seldog.php?curval=" . $row['Id'] . "&gend=0&letter=a\">" . $rowfetch['NAAM'] . '</a>')); |
||
106 | } |
||
107 | } else { |
||
108 | $form->addElement(new XoopsFormLabel('<b>' . strtr(_MA_PEDIGREE_FLD_MOTH, array('[mother]' => $pedigree->getConfig('mother'))) . '</b>', "<img src=\"assets/images/female.gif\"><a href=\"seldog.php?curval=" . $row['Id'] . "&gend=0&letter=a\">Unknown</a>")); |
||
109 | } |
||
110 | //owner/breeder |
||
111 | if ('1' == $pedigree->getConfig('ownerbreeder')) { |
||
112 | $owner_select = new XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_OWNE . '</b>', $name = 'id_owner', $value = $row['id_owner'], $size = 1, $multiple = false); |
||
113 | $queryeig = 'SELECT Id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . " ORDER BY \"lastname\""; |
||
114 | $reseig = $GLOBALS['xoopsDB']->query($queryeig); |
||
115 | $owner_select->addOption(0, $name = _MA_PEDIGREE_UNKNOWN); |
||
116 | while (false !== ($roweig = $GLOBALS['xoopsDB']->fetchArray($reseig))) { |
||
117 | $owner_select->addOption($roweig['Id'], $name = $roweig['lastname'] . ', ' . $roweig['firstname']); |
||
118 | } |
||
119 | $form->addElement($owner_select); |
||
120 | //breeder |
||
121 | $breeder_select = new XoopsFormSelect('<b>' . _MA_PEDIGREE_FLD_BREE . '</b>', $name = 'id_breeder', $value = $row['id_breeder'], $size = 1, $multiple = false); |
||
122 | $queryfok = 'SELECT Id, lastname, firstname FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . " ORDER BY \"lastname\""; |
||
123 | $resfok = $GLOBALS['xoopsDB']->query($queryfok); |
||
124 | $breeder_select->addOption(0, $name = _MA_PEDIGREE_UNKNOWN); |
||
125 | while (false !== ($rowfok = $GLOBALS['xoopsDB']->fetchArray($resfok))) { |
||
126 | $breeder_select->addOption($rowfok['Id'], $name = $rowfok['lastname'] . ', ' . $rowfok['firstname']); |
||
127 | } |
||
128 | $form->addElement($breeder_select); |
||
129 | } |
||
130 | //picture |
||
131 | if ($row['foto'] != '') { |
||
132 | $picture = '<img src=assets/images/thumbnails/' . $row['foto'] . '_400.jpeg>'; |
||
133 | $form->addElement(new XoopsFormLabel('<b>Picture</b>', $picture)); |
||
134 | } else { |
||
135 | $picture = ''; |
||
136 | } |
||
137 | $form->setExtra("enctype='multipart/form-data'"); |
||
138 | $img_box = new XoopsFormFile('<b>Image</b>', 'photo', 1024000); |
||
139 | $img_box->setExtra("size ='50'"); |
||
140 | $form->addElement($img_box); |
||
141 | //userfields |
||
142 | //create animal object |
||
143 | $animal = new PedigreeAnimal($id); |
||
144 | //test to find out how many user fields there are.. |
||
145 | $fields = $animal->getNumOfFields(); |
||
146 | View Code Duplication | for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
|
147 | $userField = new Field($fields[$i], $animal->getConfig()); |
||
148 | if ($userField->isActive()) { |
||
149 | $fieldType = $userField->getSetting('fieldtype'); |
||
150 | $fieldObject = new $fieldType($userField, $animal); |
||
151 | $edditable[$i] = $fieldObject->editField(); |
||
152 | $form->addElement($edditable[$i]); |
||
153 | } |
||
154 | } |
||
155 | } |
||
156 | $form->addElement(new XoopsFormButton('', 'button_id', _MA_PEDIGREE_BUT_SUB, 'submit')); |
||
157 | $xoopsTpl->assign('form', $form->render()); |
||
158 | } |
||
159 | |||
160 | //comments and footer |
||
161 | include XOOPS_ROOT_PATH . '/footer.php'; |
||
162 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state