Conditions | 35 |
Paths | > 20000 |
Total Lines | 284 |
Code Lines | 126 |
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 |
||
38 | function pedigree_main($ID) |
||
39 | { |
||
40 | global $moduleConfig; |
||
41 | |||
42 | $queryString = ' |
||
43 | SELECT d.id as d_id, |
||
44 | d.naam as d_naam, |
||
45 | d.roft as d_roft, |
||
46 | f.id as f_id, |
||
47 | f.naam as f_naam, |
||
48 | m.id as m_id, |
||
49 | m.naam as m_naam, |
||
50 | ff.id as ff_id, |
||
51 | ff.naam as ff_naam, |
||
52 | mf.id as mf_id, |
||
53 | mf.naam as mf_naam, |
||
54 | fm.id as fm_id, |
||
55 | fm.naam as fm_naam, |
||
56 | mm.id as mm_id, |
||
57 | mm.naam as mm_naam, |
||
58 | fff.id as fff_id, |
||
59 | fff.naam as fff_naam, |
||
60 | ffm.id as ffm_id, |
||
61 | ffm.naam as ffm_naam, |
||
62 | fmf.id as fmf_id, |
||
63 | fmf.naam as fmf_naam, |
||
64 | fmm.id as fmm_id, |
||
65 | fmm.naam as fmm_naam, |
||
66 | mmf.id as mmf_id, |
||
67 | mmf.naam as mmf_naam, |
||
68 | mff.id as mff_id, |
||
69 | mff.naam as mff_naam, |
||
70 | mfm.id as mfm_id, |
||
71 | mfm.naam as mfm_naam, |
||
72 | mmm.id as mmm_id, |
||
73 | mmm.naam as mmm_naam, |
||
74 | ffff.id as ffff_id, |
||
75 | ffff.naam as ffff_naam, |
||
76 | ffmf.id as ffmf_id, |
||
77 | ffmf.naam as ffmf_naam, |
||
78 | fmff.id as fmff_id, |
||
79 | fmff.naam as fmff_naam, |
||
80 | fmmf.id as fmmf_id, |
||
81 | fmmf.naam as fmmf_naam, |
||
82 | mmff.id as mmff_id, |
||
83 | mmff.naam as mmff_naam, |
||
84 | mfff.id as mfff_id, |
||
85 | mfff.naam as mfff_naam, |
||
86 | mfmf.id as mfmf_id, |
||
87 | mfmf.naam as mfmf_naam, |
||
88 | mmmf.id as mmmf_id, |
||
89 | mmmf.naam as mmmf_naam, |
||
90 | fffm.id as fffm_id, |
||
91 | fffm.naam as fffm_naam, |
||
92 | ffmm.id as ffmm_id, |
||
93 | ffmm.naam as ffmm_naam, |
||
94 | fmfm.id as fmfm_id, |
||
95 | fmfm.naam as fmfm_naam, |
||
96 | fmmm.id as fmmm_id, |
||
97 | fmmm.naam as fmmm_naam, |
||
98 | mmfm.id as mmfm_id, |
||
99 | mmfm.naam as mmfm_naam, |
||
100 | mffm.id as mffm_id, |
||
101 | mffm.naam as mffm_naam, |
||
102 | mfmm.id as mfmm_id, |
||
103 | mfmm.naam as mfmm_naam, |
||
104 | mmmm.id as mmmm_id, |
||
105 | mmmm.naam as mmmm_naam |
||
106 | FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' d |
||
107 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' f ON d.father = f.id |
||
108 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' m ON d.mother = m.id |
||
109 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ff ON f.father = ff.id |
||
110 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fff ON ff.father = fff.id |
||
111 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffm ON ff.mother = ffm.id |
||
112 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mf ON m.father = mf.id |
||
113 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mff ON mf.father = mff.id |
||
114 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfm ON mf.mother = mfm.id |
||
115 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fm ON f.mother = fm.id |
||
116 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmf ON fm.father = fmf.id |
||
117 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmm ON fm.mother = fmm.id |
||
118 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mm ON m.mother = mm.id |
||
119 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmf ON mm.father = mmf.id |
||
120 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmm ON mm.mother = mmm.id |
||
121 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffff ON fff.father = ffff.id |
||
122 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffmf ON ffm.father = ffmf.id |
||
123 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmff ON fmf.father = fmff.id |
||
124 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmmf ON fmm.father = fmmf.id |
||
125 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmff ON mmf.father = mmff.id |
||
126 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfff ON mff.father = mfff.id |
||
127 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfmf ON mfm.father = mfmf.id |
||
128 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmmf ON mmm.father = mmmf.id |
||
129 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fffm ON fff.mother = fffm.id |
||
130 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' ffmm ON ffm.mother = ffmm.id |
||
131 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmfm ON fmf.mother = fmfm.id |
||
132 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' fmmm ON fmm.mother = fmmm.id |
||
133 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mmfm ON mmf.mother = mmfm.id |
||
134 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mffm ON mff.mother = mffm.id |
||
135 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' mfmm ON mfm.mother = mfmm.id |
||
136 | LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " mmmm ON mmm.mother = mmmm.id |
||
137 | where d.id=$ID"; |
||
138 | |||
139 | $result = $GLOBALS['xoopsDB']->query($queryString); |
||
140 | |||
141 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
142 | //crete array to count frequency (to select colour) |
||
143 | count_item($freq, $row['d_id']); |
||
144 | count_item($freq, $row['f_id']); |
||
145 | count_item($freq, $row['m_id']); |
||
146 | count_item($freq, $row['ff_id']); |
||
147 | count_item($freq, $row['fm_id']); |
||
148 | count_item($freq, $row['mf_id']); |
||
149 | count_item($freq, $row['mm_id']); |
||
150 | count_item($freq, $row['fff_id']); |
||
151 | count_item($freq, $row['ffm_id']); |
||
152 | count_item($freq, $row['fmf_id']); |
||
153 | count_item($freq, $row['fmm_id']); |
||
154 | count_item($freq, $row['mff_id']); |
||
155 | count_item($freq, $row['mfm_id']); |
||
156 | count_item($freq, $row['mmf_id']); |
||
157 | count_item($freq, $row['mmm_id']); |
||
158 | count_item($freq, $row['ffff_id']); |
||
159 | count_item($freq, $row['ffmf_id']); |
||
160 | count_item($freq, $row['fmff_id']); |
||
161 | count_item($freq, $row['fmmf_id']); |
||
162 | count_item($freq, $row['mfff_id']); |
||
163 | count_item($freq, $row['mfmf_id']); |
||
164 | count_item($freq, $row['mmff_id']); |
||
165 | count_item($freq, $row['mmmf_id']); |
||
166 | count_item($freq, $row['fffm_id']); |
||
167 | count_item($freq, $row['ffmm_id']); |
||
168 | count_item($freq, $row['fmfm_id']); |
||
169 | count_item($freq, $row['fmmm_id']); |
||
170 | count_item($freq, $row['mffm_id']); |
||
171 | count_item($freq, $row['mfmm_id']); |
||
172 | count_item($freq, $row['mmfm_id']); |
||
173 | count_item($freq, $row['mmmm_id']); |
||
174 | |||
175 | //create array for dog (and all parents) |
||
176 | //selected dog |
||
177 | $d['d']['name'] = stripslashes($row['d_naam']); |
||
178 | $d['d']['id'] = $row['d_id']; |
||
179 | $d['d']['roft'] = $row['d_roft']; |
||
180 | $d['d']['col'] = 'transparant'; |
||
181 | //father |
||
182 | $d['f']['name'] = stripslashes($row['f_naam']); |
||
183 | $d['f']['id'] = $row['f_id']; |
||
184 | $d['f']['col'] = crcolour('f', $freq[$row['f_id']]); |
||
185 | //mother |
||
186 | $d['m']['name'] = stripslashes($row['m_naam']); |
||
187 | $d['m']['id'] = $row['m_id']; |
||
188 | $d['m']['col'] = crcolour('m', $freq[$row['m_id']]); |
||
189 | //grandparents |
||
190 | //father father |
||
191 | $d['ff']['name'] = stripslashes($row['ff_naam']); |
||
192 | $d['ff']['id'] = $row['ff_id']; |
||
193 | $d['ff']['col'] = crcolour('f', $freq[$row['ff_id']]); |
||
194 | //father mother |
||
195 | $d['fm']['name'] = stripslashes($row['fm_naam']); |
||
196 | $d['fm']['id'] = $row['fm_id']; |
||
197 | $d['fm']['col'] = crcolour('m', $freq[$row['fm_id']]); |
||
198 | //mother father |
||
199 | $d['mf']['name'] = stripslashes($row['mf_naam']); |
||
200 | $d['mf']['id'] = $row['mf_id']; |
||
201 | $d['mf']['col'] = crcolour('f', $freq[$row['mf_id']]); |
||
202 | //mother mother |
||
203 | $d['mm']['name'] = stripslashes($row['mm_naam']); |
||
204 | $d['mm']['id'] = $row['mm_id']; |
||
205 | $d['mm']['col'] = crcolour('m', $freq[$row['mm_id']]); |
||
206 | //great-grandparents |
||
207 | //father father father |
||
208 | $d['fff']['name'] = stripslashes($row['fff_naam']); |
||
209 | $d['fff']['id'] = $row['fff_id']; |
||
210 | $d['fff']['col'] = crcolour('f', $freq[$row['fff_id']]); |
||
211 | //father father mother |
||
212 | $d['ffm']['name'] = stripslashes($row['ffm_naam']); |
||
213 | $d['ffm']['id'] = $row['ffm_id']; |
||
214 | $d['ffm']['col'] = crcolour('m', $freq[$row['ffm_id']]); |
||
215 | //father mother father |
||
216 | $d['fmf']['name'] = stripslashes($row['fmf_naam']); |
||
217 | $d['fmf']['id'] = $row['fmf_id']; |
||
218 | $d['fmf']['col'] = crcolour('f', $freq[$row['fmf_id']]); |
||
219 | //father mother mother |
||
220 | $d['fmm']['name'] = stripslashes($row['fmm_naam']); |
||
221 | $d['fmm']['id'] = $row['fmm_id']; |
||
222 | $d['fmm']['col'] = crcolour('m', $freq[$row['fmm_id']]); |
||
223 | //mother father father |
||
224 | $d['mff']['name'] = stripslashes($row['mff_naam']); |
||
225 | $d['mff']['id'] = $row['mff_id']; |
||
226 | $d['mff']['col'] = crcolour('f', $freq[$row['mff_id']]); |
||
227 | //mother father mother |
||
228 | $d['mfm']['name'] = stripslashes($row['mfm_naam']); |
||
229 | $d['mfm']['id'] = $row['mfm_id']; |
||
230 | $d['mfm']['col'] = crcolour('m', $freq[$row['mfm_id']]); |
||
231 | //mother mother father |
||
232 | $d['mmf']['name'] = stripslashes($row['mmf_naam']); |
||
233 | $d['mmf']['id'] = $row['mmf_id']; |
||
234 | $d['mmf']['col'] = crcolour('f', $freq[$row['mmf_id']]); |
||
235 | //mother mother mother |
||
236 | $d['mmm']['name'] = stripslashes($row['mmm_naam']); |
||
237 | $d['mmm']['id'] = $row['mmm_id']; |
||
238 | $d['mmm']['col'] = crcolour('m', $freq[$row['mmm_id']]); |
||
239 | //great-great-grandparents (fathers) |
||
240 | //father father father |
||
241 | $d['ffff']['name'] = stripslashes($row['ffff_naam']); |
||
242 | $d['ffff']['id'] = $row['ffff_id']; |
||
243 | $d['ffff']['col'] = crcolour('f', $freq[$row['ffff_id']]); |
||
244 | //father father mother |
||
245 | $d['ffmf']['name'] = stripslashes($row['ffmf_naam']); |
||
246 | $d['ffmf']['id'] = $row['ffmf_id']; |
||
247 | $d['ffmf']['col'] = crcolour('f', $freq[$row['ffmf_id']]); |
||
248 | //father mother father |
||
249 | $d['fmff']['name'] = stripslashes($row['fmff_naam']); |
||
250 | $d['fmff']['id'] = $row['fmff_id']; |
||
251 | $d['fmff']['col'] = crcolour('f', $freq[$row['fmff_id']]); |
||
252 | //father mother mother |
||
253 | $d['fmmf']['name'] = stripslashes($row['fmmf_naam']); |
||
254 | $d['fmmf']['id'] = $row['fmmf_id']; |
||
255 | $d['fmmf']['col'] = crcolour('f', $freq[$row['fmmf_id']]); |
||
256 | //mother father father |
||
257 | $d['mfff']['name'] = stripslashes($row['mfff_naam']); |
||
258 | $d['mfff']['id'] = $row['mfff_id']; |
||
259 | $d['mfff']['col'] = crcolour('f', $freq[$row['mfff_id']]); |
||
260 | //mother father mother |
||
261 | $d['mfmf']['name'] = stripslashes($row['mfmf_naam']); |
||
262 | $d['mfmf']['id'] = $row['mfmf_id']; |
||
263 | $d['mfmf']['col'] = crcolour('f', $freq[$row['mfmf_id']]); |
||
264 | //mother mother father |
||
265 | $d['mmff']['name'] = stripslashes($row['mmff_naam']); |
||
266 | $d['mmff']['id'] = $row['mmff_id']; |
||
267 | $d['mmff']['col'] = crcolour('f', $freq[$row['mmff_id']]); |
||
268 | //mother mother mother |
||
269 | $d['mmmf']['name'] = stripslashes($row['mmmf_naam']); |
||
270 | $d['mmmf']['id'] = $row['mmmf_id']; |
||
271 | $d['mmmf']['col'] = crcolour('f', $freq[$row['mmmf_id']]); |
||
272 | //great-great-grandparents (mothers) |
||
273 | //father father father |
||
274 | $d['fffm']['name'] = stripslashes($row['fffm_naam']); |
||
275 | $d['fffm']['id'] = $row['fffm_id']; |
||
276 | $d['fffm']['col'] = crcolour('m', $freq[$row['fffm_id']]); |
||
277 | //father father mother |
||
278 | $d['ffmm']['name'] = stripslashes($row['ffmm_naam']); |
||
279 | $d['ffmm']['id'] = $row['ffmm_id']; |
||
280 | $d['ffmm']['col'] = crcolour('m', $freq[$row['ffmm_id']]); |
||
281 | //father mother father |
||
282 | $d['fmfm']['name'] = stripslashes($row['fmfm_naam']); |
||
283 | $d['fmfm']['id'] = $row['fmfm_id']; |
||
284 | $d['fmfm']['col'] = crcolour('m', $freq[$row['fmfm_id']]); |
||
285 | //father mother mother |
||
286 | $d['fmmm']['name'] = stripslashes($row['fmmm_naam']); |
||
287 | $d['fmmm']['id'] = $row['fmmm_id']; |
||
288 | $d['fmmm']['col'] = crcolour('m', $freq[$row['fmmm_id']]); |
||
289 | //mother father father |
||
290 | $d['mffm']['name'] = stripslashes($row['mffm_naam']); |
||
291 | $d['mffm']['id'] = $row['mffm_id']; |
||
292 | $d['mffm']['col'] = crcolour('m', $freq[$row['mffm_id']]); |
||
293 | //mother father mother |
||
294 | $d['mfmm']['name'] = stripslashes($row['mfmm_naam']); |
||
295 | $d['mfmm']['id'] = $row['mfmm_id']; |
||
296 | $d['mfmm']['col'] = crcolour('m', $freq[$row['mfmm_id']]); |
||
297 | //mother mother father |
||
298 | $d['mmfm']['name'] = stripslashes($row['mmfm_naam']); |
||
299 | $d['mmfm']['id'] = $row['mmfm_id']; |
||
300 | $d['mmfm']['col'] = crcolour('m', $freq[$row['mmfm_id']]); |
||
301 | //mother mother mother |
||
302 | $d['mmmm']['name'] = stripslashes($row['mmmm_naam']); |
||
303 | $d['mmmm']['id'] = $row['mmmm_id']; |
||
304 | $d['mmmm']['col'] = crcolour('m', $freq[$row['mmmm_id']]); |
||
305 | } |
||
306 | |||
307 | //add data to smarty template |
||
308 | $GLOBALS['xoopsTpl']->assign('xoops_pagetitle', $d['d']['name'] . ' -- mega pedigree'); |
||
309 | //assign dog(s) |
||
310 | $GLOBALS['xoopsTpl']->assign('d', $d); |
||
311 | $GLOBALS['xoopsTpl']->assign('male', "<img src=\"assets/images/male.gif\">"); |
||
312 | $GLOBALS['xoopsTpl']->assign('female', "<img src=\"assets/images/female.gif\">"); |
||
313 | //assign extra display options |
||
314 | $GLOBALS['xoopsTpl']->assign('unknown', 'Unknown'); |
||
315 | $GLOBALS['xoopsTpl']->assign('f2', strtr(_MA_PEDIGREE_MPED_F2, array('[animalType]' => $moduleConfig['animalType']))); |
||
316 | $GLOBALS['xoopsTpl']->assign('f3', strtr(_MA_PEDIGREE_MPED_F3, array('[animalType]' => $moduleConfig['animalType']))); |
||
317 | $GLOBALS['xoopsTpl']->assign('f4', strtr(_MA_PEDIGREE_MPED_F4, array('[animalType]' => $moduleConfig['animalType']))); |
||
318 | $GLOBALS['xoopsTpl']->assign('m2', strtr(_MA_PEDIGREE_MPED_M2, array('[animalType]' => $moduleConfig['animalType']))); |
||
319 | $GLOBALS['xoopsTpl']->assign('m3', strtr(_MA_PEDIGREE_MPED_M3, array('[animalType]' => $moduleConfig['animalType']))); |
||
320 | $GLOBALS['xoopsTpl']->assign('m4', strtr(_MA_PEDIGREE_MPED_M4, array('[animalType]' => $moduleConfig['animalType']))); |
||
321 | } |
||
322 | |||
368 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.