| Conditions | 54 |
| Paths | > 20000 |
| Total Lines | 275 |
| Code Lines | 166 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 41 | public function render($renderer): void |
||
| 42 | { |
||
| 43 | static $lastBoxYfinal; |
||
| 44 | // checkFootnote |
||
| 45 | $newelements = []; |
||
| 46 | $lastelement = null; |
||
| 47 | $footnote_element = []; |
||
| 48 | // Element counter |
||
| 49 | $cE = count($this->elements); |
||
| 50 | //-- collapse duplicate elements |
||
| 51 | for ($i = 0; $i < $cE; $i++) { |
||
| 52 | $element = $this->elements[$i]; |
||
| 53 | if ($element instanceof ReportBaseElement) { |
||
| 54 | if ($element instanceof ReportBaseText) { |
||
| 55 | if (!empty($footnote_element)) { |
||
| 56 | ksort($footnote_element); |
||
| 57 | foreach ($footnote_element as $links) { |
||
| 58 | $newelements[] = $links; |
||
| 59 | } |
||
| 60 | $footnote_element = []; |
||
| 61 | } |
||
| 62 | if (empty($lastelement)) { |
||
| 63 | $lastelement = $element; |
||
| 64 | } elseif ($element->getStyleName() === $lastelement->getStyleName()) { |
||
| 65 | // Checking if the Text has the same style |
||
| 66 | $lastelement->addText(str_replace("\n", '<br>', $element->getValue())); |
||
| 67 | } else { |
||
| 68 | $newelements[] = $lastelement; |
||
| 69 | $lastelement = $element; |
||
| 70 | } |
||
| 71 | } elseif ($element instanceof ReportHtmlImage) { |
||
| 72 | $lastelement = $element; |
||
| 73 | } elseif ($element instanceof ReportHtmlFootnote) { |
||
| 74 | // Check if the Footnote has been set with it’s link number |
||
| 75 | $renderer->checkFootnote($element); |
||
| 76 | // Save first the last element if any |
||
| 77 | if (isset($lastelement)) { |
||
| 78 | $newelements[] = $lastelement; |
||
| 79 | $lastelement = null; |
||
| 80 | } |
||
| 81 | // Save the Footnote with it’s link number as key for sorting later |
||
| 82 | $footnote_element[$element->num] = $element; |
||
| 83 | } elseif (trim($element->getValue()) !== '') { |
||
| 84 | // Do not keep empty footnotes |
||
| 85 | if (!empty($footnote_element)) { |
||
| 86 | ksort($footnote_element); |
||
| 87 | foreach ($footnote_element as $links) { |
||
| 88 | $newelements[] = $links; |
||
| 89 | } |
||
| 90 | $footnote_element = []; |
||
| 91 | } |
||
| 92 | if (isset($lastelement)) { |
||
| 93 | $newelements[] = $lastelement; |
||
| 94 | $lastelement = null; |
||
| 95 | } |
||
| 96 | $newelements[] = $element; |
||
| 97 | } |
||
| 98 | } else { |
||
| 99 | if (isset($lastelement)) { |
||
| 100 | $newelements[] = $lastelement; |
||
| 101 | $lastelement = null; |
||
| 102 | } |
||
| 103 | if (!empty($footnote_element)) { |
||
| 104 | ksort($footnote_element); |
||
| 105 | foreach ($footnote_element as $links) { |
||
| 106 | $newelements[] = $links; |
||
| 107 | } |
||
| 108 | $footnote_element = []; |
||
| 109 | } |
||
| 110 | $newelements[] = $element; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | if (isset($lastelement)) { |
||
| 114 | $newelements[] = $lastelement; |
||
| 115 | } |
||
| 116 | if (!empty($footnote_element)) { |
||
| 117 | ksort($footnote_element); |
||
| 118 | foreach ($footnote_element as $links) { |
||
| 119 | $newelements[] = $links; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | $this->elements = $newelements; |
||
| 123 | unset($footnote_element, $lastelement, $newelements); |
||
| 124 | |||
| 125 | $cP = 0; // Class Padding |
||
| 126 | |||
| 127 | // Used with line breaks and cell height calculation within this box only |
||
| 128 | $renderer->largestFontHeight = 0; |
||
| 129 | |||
| 130 | // If current position (left) |
||
| 131 | if ($this->left === ReportBaseElement::CURRENT_POSITION) { |
||
| 132 | $cX = $renderer->getX(); |
||
| 133 | } else { |
||
| 134 | $cX = $this->left; |
||
| 135 | $renderer->setX($cX); |
||
| 136 | } |
||
| 137 | // If current position (top) |
||
| 138 | $align_Y = false; |
||
| 139 | $topstr = ""; |
||
|
|
|||
| 140 | if ($this->top < -110000) { // pos='abs' |
||
| 141 | $this->top += 222000; |
||
| 142 | } |
||
| 143 | if ($this->top < -10000) { // <= -100000: both pdf and html; -100000 -- -90000: only html |
||
| 144 | $this->top += 90000; //= ReportBaseElement::CURRENT_POSITION; |
||
| 145 | if ($this->top < -9000) { |
||
| 146 | $this->top += 10000; |
||
| 147 | } |
||
| 148 | $topstr = "top:" . $this->top . "pt;"; |
||
| 149 | $align_Y = true; |
||
| 150 | } |
||
| 151 | if ($this->top === ReportBaseElement::CURRENT_POSITION) { |
||
| 152 | $this->top = $renderer->getY(); |
||
| 153 | } else { |
||
| 154 | $renderer->setY($this->top); |
||
| 155 | } |
||
| 156 | |||
| 157 | // Check the width if set to page wide OR set by xml to larger then page width (margin) |
||
| 158 | if ($this->width === 0.0 || $this->width > $renderer->getRemainingWidth()) { |
||
| 159 | $this->width = $renderer->getRemainingWidth(); |
||
| 160 | } |
||
| 161 | // Setup the CellPadding |
||
| 162 | if ($this->padding) { |
||
| 163 | $cP = $renderer->cPadding; |
||
| 164 | } |
||
| 165 | |||
| 166 | // For padding, we have to use less wrap width |
||
| 167 | $cW = $this->width - $cP * 2.0; |
||
| 168 | |||
| 169 | //-- calculate the text box height |
||
| 170 | // Number of lines, will be converted to height |
||
| 171 | $cHT = 0; |
||
| 172 | // Element height (except text) |
||
| 173 | $eH = 0.0; |
||
| 174 | // Footnote height (in points) |
||
| 175 | $fH = 0; |
||
| 176 | $w = 0; |
||
| 177 | //-- $lw is an array |
||
| 178 | // 0 => last line width |
||
| 179 | // 1 => 1 if text was wrapped, 0 if text did not wrap |
||
| 180 | // 2 => number of LF |
||
| 181 | $lw = []; |
||
| 182 | // Element counter |
||
| 183 | $cE = count($this->elements); |
||
| 184 | for ($i = 0; $i < $cE; $i++) { |
||
| 185 | if (is_object($this->elements[$i])) { |
||
| 186 | $ew = $this->elements[$i]->setWrapWidth($cW - $w - 2, $cW); |
||
| 187 | if ($ew === $cW) { |
||
| 188 | $w = 0; |
||
| 189 | } |
||
| 190 | $lw = $this->elements[$i]->getWidth($renderer); |
||
| 191 | // Text is already gets the # LF |
||
| 192 | $cHT += $lw[2]; |
||
| 193 | if ($lw[1] === 1) { |
||
| 194 | $w = $lw[0]; |
||
| 195 | } elseif ($lw[1] === 2) { |
||
| 196 | $w = 0; |
||
| 197 | } else { |
||
| 198 | $w += $lw[0]; |
||
| 199 | } |
||
| 200 | if ($w > $cW) { |
||
| 201 | $w = $lw[0]; |
||
| 202 | } |
||
| 203 | // For anything else but text (images), get the height |
||
| 204 | $eH += $this->elements[$i]->getHeight($renderer); |
||
| 205 | } else { |
||
| 206 | $fH += abs($renderer->getFootnotesHeight($cW)); |
||
| 207 | } |
||
| 208 | } |
||
| 209 | |||
| 210 | // Add up what’s the final height |
||
| 211 | //$cH = $this->height; |
||
| 212 | $cH = 0; |
||
| 213 | // If any element exist |
||
| 214 | if ($cE > 0) { |
||
| 215 | // Check if this is text or some other element, like images |
||
| 216 | if ($eH === 0.0) { |
||
| 217 | // Number of LF but at least one line |
||
| 218 | $cHT = ($cHT + 1) * $renderer->cellHeightRatio; |
||
| 219 | // Calculate the cell height with the largest font size used |
||
| 220 | $cHT *= $renderer->largestFontHeight; |
||
| 221 | if ($cH < $cHT) { |
||
| 222 | $cH = $cHT; |
||
| 223 | } |
||
| 224 | } else { |
||
| 225 | // This is any other element |
||
| 226 | if ($cH < $eH) { |
||
| 227 | $cH = $eH; |
||
| 228 | } |
||
| 229 | // Add Footnote height to the rest of the height |
||
| 230 | $cH += $fH; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | |||
| 234 | unset($lw, $cHT, $fH, $w); |
||
| 235 | |||
| 236 | // Finally, check the last cells height |
||
| 237 | if ($cH < $renderer->lastCellHeight) { |
||
| 238 | $cH = $renderer->lastCellHeight; |
||
| 239 | } |
||
| 240 | // Update max Y in case of a pagebreak |
||
| 241 | // We don't want to over write any images or other stuff |
||
| 242 | $renderer->addMaxY($this->top + $cH); |
||
| 243 | |||
| 244 | // Start to print HTML |
||
| 245 | if (!$align_Y) { |
||
| 246 | echo '<div style="position:absolute;top:', $this->top, 'pt;'; |
||
| 247 | } else { |
||
| 248 | echo '<div style="position:relative;top:', $this->top, 'pt;'; |
||
| 249 | } |
||
| 250 | //echo '<div style="position:relative;'; |
||
| 251 | // LTR (left) or RTL (right) |
||
| 252 | echo $renderer->alignRTL, ':', $cX, 'pt;'; |
||
| 253 | // Background color |
||
| 254 | if ($this->fill && $this->bgcolor !== '') { |
||
| 255 | echo ' background-color:', $this->bgcolor, ';'; |
||
| 256 | } |
||
| 257 | // Print padding only when it’s set |
||
| 258 | if ($this->padding) { |
||
| 259 | // Use Cell around padding to support RTL also |
||
| 260 | echo 'padding:', $cP, 'pt;'; |
||
| 261 | } |
||
| 262 | // Border setup |
||
| 263 | if ($this->border) { |
||
| 264 | echo ' border:solid black 1pt;'; |
||
| 265 | if (!$align_Y) { |
||
| 266 | echo 'width:', $this->width - 1 - $cP * 2, 'pt;height:', $cH - 1, 'pt;'; |
||
| 267 | } else { |
||
| 268 | echo 'width:', $this->width - 1 - $cP * 2, 'pt;height:auto;'; |
||
| 269 | } // height:',$this->height,'pt;'; //,$topstr; |
||
| 270 | } else { |
||
| 271 | if (!$align_Y) { |
||
| 272 | echo 'width:', $this->width - $cP * 2, 'pt;height:', $cH, 'pt;'; |
||
| 273 | } else { |
||
| 274 | echo 'width:', $this->width - $cP * 2, 'pt;height:auto;'; |
||
| 275 | } //height:',$this->height,'pt;'; //,$topstr; |
||
| 276 | } |
||
| 277 | echo '">'; |
||
| 278 | |||
| 279 | // Do a little "margin" trick before print |
||
| 280 | // to get the correct current position => "." |
||
| 281 | $cXT = $renderer->getX(); |
||
| 282 | $cYT = $renderer->getY(); |
||
| 283 | $renderer->setXy(0, 0); |
||
| 284 | |||
| 285 | // Print the text elements |
||
| 286 | foreach ($this->elements as $element) { |
||
| 287 | if ($element instanceof ReportHtmlText) { |
||
| 288 | $element->render($renderer, false); |
||
| 289 | } elseif ($element instanceof ReportBaseElement) { |
||
| 290 | $element->render($renderer); |
||
| 291 | } elseif ($element === 'footnotetexts') { |
||
| 292 | $renderer->footnotes(); |
||
| 293 | } elseif ($element === 'addpage') { |
||
| 294 | $renderer->addPage(); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | echo "</div>\n"; |
||
| 298 | |||
| 299 | // Reset "margins" |
||
| 300 | $renderer->setXy($cXT, $cYT); |
||
| 301 | // This will be mostly used to trick the multiple images last height |
||
| 302 | if ($this->reseth) { |
||
| 303 | $cH = 0; |
||
| 304 | } |
||
| 305 | // New line and some clean up |
||
| 306 | if (!$this->newline) { |
||
| 307 | $renderer->setXy($cX + $this->width, $this->top); |
||
| 308 | $renderer->lastCellHeight = $cH; |
||
| 309 | } else { |
||
| 310 | $renderer->setXy(0, $this->top + $cH + $cP * 2); |
||
| 311 | $renderer->lastCellHeight = 0; |
||
| 312 | } |
||
| 313 | // This will make images in textboxes to ignore images in previous textboxes |
||
| 314 | // Without this trick the $lastpicbottom in the previos textbox will be used in ReportHtmlImage |
||
| 315 | $renderer->pageN++; |
||
| 316 | } |
||
| 318 |