| Conditions | 24 |
| Paths | > 20000 |
| Total Lines | 116 |
| Code Lines | 91 |
| Lines | 24 |
| Ratio | 20.69 % |
| 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 |
||
| 153 | public function printTimeFact(Fact $event) { |
||
| 154 | global $factcount, $placements; |
||
| 155 | |||
| 156 | $desc = $event->getValue(); |
||
| 157 | // check if this is a family fact |
||
| 158 | $gdate = $event->getDate(); |
||
| 159 | $date = $gdate->minimumDate(); |
||
| 160 | $date = $date->convertToCalendar('gregorian'); |
||
| 161 | $year = $date->y; |
||
| 162 | $month = max(1, $date->m); |
||
| 163 | $day = max(1, $date->d); |
||
| 164 | $xoffset = 0 + 22; |
||
| 165 | $yoffset = 0 + (($year - $this->baseyear) * $this->scale) - ($this->scale); |
||
| 166 | $yoffset = $yoffset + (($month / 12) * $this->scale); |
||
| 167 | $yoffset = $yoffset + (($day / 30) * ($this->scale / 12)); |
||
| 168 | $yoffset = (int) ($yoffset); |
||
| 169 | $place = (int) ($yoffset / $this->bheight); |
||
| 170 | $i = 1; |
||
| 171 | $j = 0; |
||
| 172 | $tyoffset = 0; |
||
| 173 | while (isset($placements[$place])) { |
||
| 174 | if ($i === $j) { |
||
| 175 | $tyoffset = $this->bheight * $i; |
||
| 176 | $i++; |
||
| 177 | } else { |
||
| 178 | $tyoffset = -1 * $this->bheight * $j; |
||
| 179 | $j++; |
||
| 180 | } |
||
| 181 | $place = (int) (($yoffset + $tyoffset) / ($this->bheight)); |
||
| 182 | } |
||
| 183 | $yoffset += $tyoffset; |
||
| 184 | $xoffset += abs($tyoffset); |
||
| 185 | $placements[$place] = $yoffset; |
||
| 186 | |||
| 187 | echo "<div id=\"fact$factcount\" style=\"position:absolute; " . (I18N::direction() === 'ltr' ? 'left: ' . ($xoffset) : 'right: ' . ($xoffset)) . 'px; top:' . ($yoffset) . 'px; font-size: 8pt; height: ' . ($this->bheight) . "px;\" onmousedown=\"factMouseDown(this, '" . $factcount . "', " . ($yoffset - $tyoffset) . ');">'; |
||
| 188 | echo '<table cellspacing="0" cellpadding="0" border="0" style="cursor: hand;"><tr><td>'; |
||
| 189 | echo '<img src="' . Theme::theme()->parameter('image-hline') . '" name="boxline' . $factcount . '" id="boxline' . $factcount . '" height="3" width="10" style="padding-'; |
||
| 190 | if (I18N::direction() === 'ltr') { |
||
| 191 | echo 'left: 3px;">'; |
||
| 192 | } else { |
||
| 193 | echo 'right: 3px;">'; |
||
| 194 | } |
||
| 195 | |||
| 196 | $col = array_search($event->getParent(), $this->people); |
||
| 197 | if ($col === false) { |
||
| 198 | // Marriage event - use the color of the husband |
||
| 199 | $col = array_search($event->getParent()->getHusband(), $this->people); |
||
| 200 | } |
||
| 201 | if ($col === false) { |
||
| 202 | // Marriage event - use the color of the wife |
||
| 203 | $col = array_search($event->getParent()->getWife(), $this->people); |
||
| 204 | } |
||
| 205 | $col = $col % 6; |
||
| 206 | echo '</td><td class="person' . $col . '">'; |
||
| 207 | if (count($this->people) > 6) { |
||
| 208 | // We only have six colours, so show naes if more than this number |
||
| 209 | echo $event->getParent()->getFullName() . ' — '; |
||
| 210 | } |
||
| 211 | $record = $event->getParent(); |
||
| 212 | echo $event->getLabel(); |
||
| 213 | echo ' — '; |
||
| 214 | if ($record instanceof Individual) { |
||
| 215 | echo FunctionsPrint::formatFactDate($event, $record, false, false); |
||
| 216 | } elseif ($record instanceof Family) { |
||
| 217 | echo $gdate->display(); |
||
| 218 | View Code Duplication | if ($record->getHusband() && $record->getHusband()->getBirthDate()->isOK()) { |
|
| 219 | $ageh = FunctionsDate::getAgeAtEvent(Date::getAgeGedcom($record->getHusband()->getBirthDate(), $gdate)); |
||
| 220 | } else { |
||
| 221 | $ageh = null; |
||
| 222 | } |
||
| 223 | View Code Duplication | if ($record->getWife() && $record->getWife()->getBirthDate()->isOK()) { |
|
| 224 | $agew = FunctionsDate::getAgeAtEvent(Date::getAgeGedcom($record->getWife()->getBirthDate(), $gdate)); |
||
| 225 | } else { |
||
| 226 | $agew = null; |
||
| 227 | } |
||
| 228 | if ($ageh && $agew) { |
||
| 229 | echo '<span class="age"> ', I18N::translate('Husband’s age'), ' ', $ageh, ' ', I18N::translate('Wife’s age'), ' ', $agew, '</span>'; |
||
| 230 | } elseif ($ageh) { |
||
| 231 | echo '<span class="age"> ', I18N::translate('Age'), ' ', $ageh, '</span>'; |
||
| 232 | } elseif ($agew) { |
||
| 233 | echo '<span class="age"> ', I18N::translate('Age'), ' ', $ageh, '</span>'; |
||
| 234 | } |
||
| 235 | } |
||
| 236 | echo ' ' . Html::escape($desc); |
||
| 237 | if (!$event->getPlace()->isEmpty()) { |
||
| 238 | echo ' — ' . $event->getPlace()->getShortName(); |
||
| 239 | } |
||
| 240 | // Print spouses names for family events |
||
| 241 | if ($event->getParent() instanceof Family) { |
||
| 242 | echo ' — <a href="', $event->getParent()->getHtmlUrl(), '">', $event->getParent()->getFullName(), '</a>'; |
||
| 243 | } |
||
| 244 | echo '</td></tr></table>'; |
||
| 245 | echo '</div>'; |
||
| 246 | View Code Duplication | if (I18N::direction() === 'ltr') { |
|
| 247 | $img = 'image-dline2'; |
||
| 248 | $ypos = '0%'; |
||
| 249 | } else { |
||
| 250 | $img = 'image-dline'; |
||
| 251 | $ypos = '100%'; |
||
| 252 | } |
||
| 253 | $dyoffset = ($yoffset - $tyoffset) + $this->bheight / 3; |
||
| 254 | if ($tyoffset < 0) { |
||
| 255 | $dyoffset = $yoffset + $this->bheight / 3; |
||
| 256 | View Code Duplication | if (I18N::direction() === 'ltr') { |
|
| 257 | $img = 'image-dline'; |
||
| 258 | $ypos = '100%'; |
||
| 259 | } else { |
||
| 260 | $img = 'image-dline2'; |
||
| 261 | $ypos = '0%'; |
||
| 262 | } |
||
| 263 | } |
||
| 264 | // Print the diagonal line |
||
| 265 | echo '<div id="dbox' . $factcount . '" style="position:absolute; ' . (I18N::direction() === 'ltr' ? 'left: ' . (0 + 25) : 'right: ' . (0 + 25)) . 'px; top:' . ($dyoffset) . 'px; font-size: 8pt; height: ' . abs($tyoffset) . 'px; width: ' . abs($tyoffset) . 'px;'; |
||
| 266 | echo ' background-image: url(\'' . Theme::theme()->parameter($img) . '\');'; |
||
| 267 | echo ' background-position: 0% ' . $ypos . ';">'; |
||
| 268 | echo '</div>'; |
||
| 269 | } |
||
| 285 |