Conditions | 24 |
Paths | > 20000 |
Total Lines | 162 |
Code Lines | 95 |
Lines | 62 |
Ratio | 38.27 % |
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 |
||
34 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
35 | */ |
||
36 | // if (isset($_GET['st'])) { |
||
37 | // $st = $_GET['st']; |
||
38 | // } else { |
||
39 | // $st = 0; |
||
40 | // } |
||
41 | // if (isset($_GET['l'])) { |
||
42 | // $l = $_GET['l']; |
||
43 | // } else { |
||
44 | // $l = 'A'; |
||
45 | // } |
||
46 | $st = XoopsRequest::getInt('st', 0, 'get'); |
||
47 | $l = XoopsRequest::getString('l', 'a', 'get'); |
||
48 | |||
49 | $xoopsTpl->assign('sire', '1'); |
||
50 | //create list of males dog to select from |
||
51 | $perp = $pedigree->getConfig('perpage'); |
||
52 | //count total number of dogs |
||
53 | $numdog = 'SELECT COUNT(d.Id) FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON m.Id = d.mother LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') // . " f ON f.id = d.father WHERE d.roft = '0' and d.mother != '0' and d.father != '0' and m.mother != '0' and m.father != '0' and f.mother != '0' and f.father != '0' and d.NAAM LIKE '" . $l . "%'"; |
||
54 | . " f ON f.Id = d.father WHERE d.roft = '0' AND d.mother != '0' AND d.father != '0' AND m.mother != '0' AND m.father != '0' AND f.mother != '0' AND f.father != '0' AND d.NAAM LIKE '" . $GLOBALS['xoopsDB']->escape($l) . "%'"; |
||
55 | $numres = $GLOBALS['xoopsDB']->query($numdog); |
||
56 | //total number of dogs the query will find |
||
57 | list($numresults) = $GLOBALS['xoopsDB']->fetchRow($numres); |
||
58 | //total number of pages |
||
59 | $numpages = floor($numresults / $perp) + 1; |
||
60 | if (($numpages * $perp) == ($numresults + $perp)) { |
||
61 | --$numpages; |
||
62 | } |
||
63 | //find current page |
||
64 | $cpage = floor($st / $perp) + 1; |
||
65 | //create alphabet |
||
66 | $pages = ''; |
||
67 | for ($i = 65; $i <= 90; ++$i) { |
||
68 | if ($l == chr($i)) { |
||
69 | $pages .= "<b><a href=\"virtual.php?r=1&st=0&l=" . chr($i) . "\">" . chr($i) . '</a></b> '; |
||
70 | View Code Duplication | } else { |
|
71 | $pages .= "<a href=\"virtual.php?r=1&st=0&l=" . chr($i) . "\">" . chr($i) . '</a> '; |
||
72 | } |
||
73 | } |
||
74 | $pages .= '- '; |
||
75 | $pages .= "<a href=\"virtual.php?r=1&st=0&l=Ã…\">Ã…</a> "; |
||
76 | $pages .= "<a href=\"virtual.php?r=1&st=0&l=Ö\">Ö</a> "; |
||
77 | $pages .= '<br />'; |
||
78 | //create previous button |
||
79 | View Code Duplication | if (($numpages > 1) && ($cpage > 1)) { |
|
80 | $pages .= "<a href=\"virtual.php?r=1&&l=" . $l . 'st=' . ($st - $perp) . "\">" . _MA_PEDIGREE_PREVIOUS . '</a>  '; |
||
81 | } |
||
82 | //create numbers |
||
83 | $xLimit = $numpages + 1; |
||
84 | View Code Duplication | for ($x = 1; $x < $xLimit; ++$x) { |
|
85 | //create line break after 20 number |
||
86 | if (($x % 20) == 0) { |
||
87 | $pages .= '<br />'; |
||
88 | } |
||
89 | if ($x != $cpage) { |
||
90 | $pages .= "<a href=\"virtual.php?r=1&l=" . $l . '&st=' . ($perp * ($x - 1)) . "\">" . $x . '</a> '; |
||
91 | } else { |
||
92 | $pages .= $x . '  '; |
||
93 | } |
||
94 | } |
||
95 | //create next button |
||
96 | if ($numpages > 1) { |
||
97 | if ($cpage < $numpages) { |
||
98 | $pages .= "<a href=\"virtual.php?r=1&l=" . $l . '&st=' . ($st + $perp) . "\">" . _MA_PEDIGREE_NEXT . '</a>  '; |
||
99 | } |
||
100 | } |
||
101 | |||
102 | //query |
||
103 | $queryString = 'SELECT d.*, d.Id AS d_id, d.NAAM AS d_naam FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON m.Id = d.mother LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " f ON f.Id = d.father WHERE d.roft = '0' AND d.mother != '0' AND d.father != '0' AND m.mother != '0' AND m.father != '0' AND f.mother != '0' AND f.father != '0' AND d.NAAM LIKE '" . $l . "%' ORDER BY d.NAAM LIMIT " . $st . ', ' . $perp; |
||
104 | $result = $GLOBALS['xoopsDB']->query($queryString); |
||
105 | |||
106 | $animal = new PedigreeAnimal(); |
||
107 | //test to find out how many user fields there are... |
||
108 | $fields = $animal->getNumOfFields(); |
||
109 | $numofcolumns = 1; |
||
110 | $columns[] = array('columnname' => 'Name'); |
||
111 | View Code Duplication | for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
|
112 | $userField = new Field($fields[$i], $animal->getConfig()); |
||
113 | $fieldType = $userField->getSetting('fieldtype'); |
||
114 | $fieldObject = new $fieldType($userField, $animal); |
||
115 | //create empty string |
||
116 | $lookupvalues = ''; |
||
117 | if ($userField->isActive() && $userField->inList()) { |
||
118 | if ($userField->hasLookup()) { |
||
119 | $lookupvalues = $userField->lookupField($fields[$i]); |
||
120 | //debug information |
||
121 | //print_r($lookupvalues); |
||
122 | } |
||
123 | $columns[] = array('columnname' => $fieldObject->fieldname, 'columnnumber' => $userField->getId(), 'lookupval' => $lookupvalues); |
||
124 | ++$numofcolumns; |
||
125 | unset($lookupvalues); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | View Code Duplication | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
|
130 | //create picture information |
||
131 | if ($row['foto'] != '') { |
||
132 | $camera = " <img src=\"assets/images/dog-icon25.png\">"; |
||
133 | } else { |
||
134 | $camera = ''; |
||
135 | } |
||
136 | $name = stripslashes($row['d_naam']) . $camera; |
||
137 | //empty array |
||
138 | unset($columnvalue); |
||
139 | //fill array |
||
140 | for ($i = 1; $i < $numofcolumns; ++$i) { |
||
141 | $x = $columns[$i]['columnnumber']; |
||
142 | //echo $x."columnnumber"; |
||
143 | if (is_array($columns[$i]['lookupval'])) { |
||
144 | foreach ($columns[$i]['lookupval'] as $key => $keyvalue) { |
||
145 | if ($keyvalue['id'] == $row['user' . $x]) { |
||
146 | //echo "key:".$row['user5']."<br />"; |
||
147 | $value = $keyvalue['value']; |
||
148 | } |
||
149 | } |
||
150 | //debug information |
||
151 | ///echo $columns[$i]['columnname']."is an array !"; |
||
152 | } //format value - cant use object because of query count |
||
153 | elseif (0 === strpos($row['user' . $x], 'http://')) { |
||
154 | $value = "<a href=\"" . $row['user' . $x] . "\">" . $row['user' . $x] . '</a>'; |
||
155 | } else { |
||
156 | $value = $row['user' . $x]; |
||
157 | } |
||
158 | $columnvalue[] = array('value' => $value); |
||
159 | unset($value); |
||
160 | } |
||
161 | $dogs[] = array( |
||
162 | 'id' => $row['d_id'], |
||
163 | 'name' => $name, |
||
164 | 'gender' => "<img src=\"assets/images/male.gif\" alt=\"" . _MA_PEDIGREE_FEMALE . "\">", |
||
165 | 'link' => "<a href=\"virtual.php?f=dam&selsire=" . $row['d_id'] . "\">" . $name . '</a>', |
||
166 | 'colour' => '', |
||
167 | 'number' => '', |
||
168 | 'usercolumns' => isset($columnvalue) ? $columnvalue : 0 |
||
169 | ); |
||
170 | } |
||
171 | |||
172 | //add data to smarty template |
||
173 | //assign dog |
||
174 | if (isset($dogs)) { |
||
175 | $xoopsTpl->assign('dogs', $dogs); |
||
176 | } |
||
177 | $xoopsTpl->assign('columns', $columns); |
||
178 | $xoopsTpl->assign('numofcolumns', $numofcolumns); |
||
179 | $xoopsTpl->assign('tsarray', PedigreeUtilities::sortTable($numofcolumns)); |
||
180 | $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELSIRE, array('[father]' => $pedigree->getConfig('father')))); |
||
181 | $xoopsTpl->assign('pages', $pages); |
||
182 | |||
183 | $xoopsTpl->assign('virtualtitle', strtr(_MA_PEDIGREE_VIRUTALTIT, array('[mother]' => $pedigree->getConfig('mother')))); |
||
184 | $xoopsTpl->assign('virtualstory', strtr(_MA_PEDIGREE_VIRUTALSTO, array('[mother]' => $pedigree->getConfig('mother'), '[father]' => $pedigree->getConfig('father'), '[children]' => $pedigree->getConfig('children')))); |
||
185 | $xoopsTpl->assign('nextaction', '<b>' . strtr(_MA_PEDIGREE_VIRT_SIRE, array('[father]' => $pedigree->getConfig('father'))) . '</b>'); |
||
186 | break; |
||
187 | |||
188 | case 'dam': |
||
189 | global $xoopsTpl; |
||
190 | $pedigree = PedigreePedigree::getInstance(false); |
||
191 | $pages = ''; |
||
192 | /* |
||
193 | //get module configuration |
||
194 | $moduleHandler = xoops_getHandler('module'); |
||
195 | $module = $moduleHandler->getByDirname('pedigree'); |
||
196 | $configHandler = xoops_getHandler('config'); |
||
426 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.