Conditions | 60 |
Paths | > 20000 |
Total Lines | 285 |
Code Lines | 176 |
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 |
||
40 | public function render($renderer): void |
||
41 | { |
||
42 | $newelements = []; |
||
43 | $lastelement = ''; |
||
44 | $footnote_element = []; |
||
45 | // Element counter |
||
46 | $cE = count($this->elements); |
||
47 | //-- collapse duplicate elements |
||
48 | for ($i = 0; $i < $cE; $i++) { |
||
49 | $element = $this->elements[$i]; |
||
50 | if ($element instanceof ReportBaseElement) { |
||
51 | if ($element instanceof ReportBaseText) { |
||
52 | ksort($footnote_element); |
||
53 | foreach ($footnote_element as $links) { |
||
54 | $newelements[] = $links; |
||
55 | } |
||
56 | $footnote_element = []; |
||
57 | if (empty($lastelement)) { |
||
58 | $lastelement = $element; |
||
59 | } elseif ($element->getStyleName() === $lastelement->getStyleName()) { |
||
60 | // Checking if the Text has the same style |
||
61 | $lastelement->addText(str_replace("\n", '<br>', $element->getValue())); |
||
62 | } else { |
||
63 | $newelements[] = $lastelement; |
||
64 | $lastelement = $element; |
||
65 | } |
||
66 | } elseif ($element instanceof ReportPdfFootnote) { |
||
67 | // Check if the Footnote has been set with it’s link number |
||
68 | $renderer->checkFootnote($element); |
||
69 | // Save first the last element if any |
||
70 | if (!empty($lastelement)) { |
||
71 | $newelements[] = $lastelement; |
||
72 | $lastelement = []; |
||
73 | } |
||
74 | // Save the Footnote with it’s link number as key for sorting later |
||
75 | $footnote_element[$element->num] = $element; |
||
76 | } elseif (!$element instanceof ReportPdfFootnote || trim($element->getValue()) !== '') { |
||
77 | // Do not keep empty footnotes |
||
78 | if (!empty($footnote_element)) { |
||
79 | ksort($footnote_element); |
||
80 | foreach ($footnote_element as $links) { |
||
81 | $newelements[] = $links; |
||
82 | } |
||
83 | $footnote_element = []; |
||
84 | } |
||
85 | if (!empty($lastelement)) { |
||
86 | $newelements[] = $lastelement; |
||
87 | $lastelement = []; |
||
88 | } |
||
89 | $newelements[] = $element; |
||
90 | } |
||
91 | } else { |
||
92 | if (!empty($lastelement)) { |
||
93 | $newelements[] = $lastelement; |
||
94 | $lastelement = []; |
||
95 | } |
||
96 | if (!empty($footnote_element)) { |
||
97 | ksort($footnote_element); |
||
98 | foreach ($footnote_element as $links) { |
||
99 | $newelements[] = $links; |
||
100 | } |
||
101 | $footnote_element = []; |
||
102 | } |
||
103 | $newelements[] = $element; |
||
104 | } |
||
105 | } |
||
106 | if (!empty($lastelement)) { |
||
107 | $newelements[] = $lastelement; |
||
108 | } |
||
109 | if (!empty($footnote_element)) { |
||
110 | ksort($footnote_element); |
||
111 | foreach ($footnote_element as $links) { |
||
112 | $newelements[] = $links; |
||
113 | } |
||
114 | } |
||
115 | $this->elements = $newelements; |
||
116 | unset($footnote_element, $lastelement, $links, $newelements); |
||
117 | |||
118 | // Used with line breaks and cell height calculation within this box |
||
119 | $renderer->largestFontHeight = 0; |
||
120 | |||
121 | // If current position (left) |
||
122 | if ($this->left === ReportBaseElement::CURRENT_POSITION) { |
||
123 | $cX = $renderer->tcpdf->GetX(); |
||
124 | } else { |
||
125 | // For static position add margin (returns and updates X) |
||
126 | $cX = $renderer->addMarginX($this->left); |
||
127 | } |
||
128 | |||
129 | // If current position (top) |
||
130 | if ($this->top === ReportBaseElement::CURRENT_POSITION) { |
||
131 | $cY = $renderer->tcpdf->GetY(); |
||
132 | } else { |
||
133 | $cY = $this->top; |
||
134 | $renderer->tcpdf->setY($cY); |
||
135 | } |
||
136 | |||
137 | // Check the width if set to page wide OR set by xml to larger then page width (margin) |
||
138 | if ($this->width === 0.0 || $this->width > $renderer->getRemainingWidthPDF()) { |
||
139 | $cW = $renderer->getRemainingWidthPDF(); |
||
140 | } else { |
||
141 | $cW = $this->width; |
||
142 | } |
||
143 | |||
144 | // Save the original margins |
||
145 | $cM = $renderer->tcpdf->getMargins(); |
||
146 | // Use cell padding to wrap the width |
||
147 | // Temp Width with cell padding |
||
148 | if (is_array($cM['cell'])) { |
||
149 | $cWT = $cW - ($cM['padding_left'] + $cM['padding_right']); |
||
150 | } else { |
||
151 | $cWT = $cW - $cM['cell'] * 2; |
||
152 | } |
||
153 | // Element height (except text) |
||
154 | $eH = 0.0; |
||
155 | $w = 0; |
||
156 | // Temp Height |
||
157 | $cHT = 0; |
||
158 | //-- $lw is an array |
||
159 | // 0 => last line width |
||
160 | // 1 => 1 if text was wrapped, 0 if text did not wrap |
||
161 | // 2 => number of LF |
||
162 | $lw = []; |
||
163 | // Element counter |
||
164 | $cE = count($this->elements); |
||
165 | //-- calculate the text box height + width |
||
166 | for ($i = 0; $i < $cE; $i++) { |
||
167 | if (is_object($this->elements[$i])) { |
||
168 | $ew = $this->elements[$i]->setWrapWidth($cWT - $w, $cWT); |
||
169 | if ($ew === $cWT) { |
||
170 | $w = 0; |
||
171 | } |
||
172 | $lw = $this->elements[$i]->getWidth($renderer); |
||
173 | // Text is already gets the # LF |
||
174 | $cHT += $lw[2]; |
||
175 | if ($lw[1] === 1) { |
||
176 | $w = $lw[0]; |
||
177 | } elseif ($lw[1] === 2) { |
||
178 | $w = 0; |
||
179 | } else { |
||
180 | $w += $lw[0]; |
||
181 | } |
||
182 | if ($w > $cWT) { |
||
183 | $w = $lw[0]; |
||
184 | } |
||
185 | // Footnote is at the bottom of the page. No need to calculate it’s height or wrap the text! |
||
186 | // We are changing the margins anyway! |
||
187 | // For anything else but text (images), get the height |
||
188 | $eH += $this->elements[$i]->getHeight($renderer); |
||
189 | } |
||
190 | } |
||
191 | |||
192 | // Add up what’s the final height |
||
193 | $cH = $this->height; |
||
194 | // If any element exist |
||
195 | if ($cE > 0) { |
||
196 | // Check if this is text or some other element, like images |
||
197 | if ($eH === 0.0) { |
||
198 | // This is text elements. Number of LF but at least one line |
||
199 | $cHT = ($cHT + 1) * $renderer->tcpdf->getCellHeightRatio(); |
||
200 | // Calculate the cell height with the largest font size used within this Box |
||
201 | $cHT *= $renderer->largestFontHeight; |
||
202 | // Add cell padding |
||
203 | if ($this->padding) { |
||
204 | if (is_array($cM['cell'])) { |
||
205 | $cHT += $cM['padding_bottom'] + $cM['padding_top']; |
||
206 | } else { |
||
207 | $cHT += $cM['cell'] * 2; |
||
208 | } |
||
209 | } |
||
210 | if ($cH < $cHT) { |
||
211 | $cH = $cHT; |
||
212 | } |
||
213 | } elseif ($cH < $eH) { |
||
214 | // This is any other element |
||
215 | $cH = $eH; |
||
216 | } |
||
217 | } |
||
218 | // Finally, check the last cells height |
||
219 | if ($cH < $renderer->lastCellHeight) { |
||
220 | $cH = $renderer->lastCellHeight; |
||
221 | } |
||
222 | // Add a new page if needed |
||
223 | if ($this->pagecheck) { |
||
224 | // Reset last cell height or Header/Footer will inherit it, in case of pagebreak |
||
225 | $renderer->lastCellHeight = 0; |
||
226 | if ($renderer->checkPageBreakPDF($cH)) { |
||
227 | $cY = $renderer->tcpdf->GetY(); |
||
228 | } |
||
229 | } |
||
230 | |||
231 | // Setup the border and background color |
||
232 | $cS = ''; // Class Style |
||
233 | if ($this->border) { |
||
234 | $cS = 'D'; |
||
235 | } // D or empty string: Draw (default) |
||
236 | $match = []; |
||
237 | // Fill the background |
||
238 | if ($this->fill) { |
||
239 | if (preg_match('/#?(..)(..)(..)/', $this->bgcolor, $match)) { |
||
240 | $cS .= 'F'; // F: Fill the background |
||
241 | $r = hexdec($match[1]); |
||
242 | $g = hexdec($match[2]); |
||
243 | $b = hexdec($match[3]); |
||
244 | $renderer->tcpdf->setFillColor($r, $g, $b); |
||
245 | } |
||
246 | } |
||
247 | // Clean up a bit |
||
248 | unset($lw, $w, $match, $cE, $eH); |
||
249 | // Draw the border |
||
250 | if (!empty($cS)) { |
||
251 | if (!$renderer->tcpdf->getRTL()) { |
||
252 | $cXM = $cX; |
||
253 | } else { |
||
254 | $cXM = $renderer->tcpdf->getPageWidth() - $cX - $cW; |
||
255 | } |
||
256 | $renderer->tcpdf->Rect($cXM, $cY, $cW, $cH, $cS); |
||
257 | } |
||
258 | // Add cell padding if set and if any text (element) exist |
||
259 | if ($this->padding) { |
||
260 | if ($cHT > 0) { |
||
261 | if (is_array($cM['cell'])) { |
||
262 | $renderer->tcpdf->setY($cY + $cM['padding_top']); |
||
263 | } else { |
||
264 | $renderer->tcpdf->setY($cY + $cM['cell']); |
||
265 | } |
||
266 | } |
||
267 | } |
||
268 | // Change the margins X, Width |
||
269 | if (!$renderer->tcpdf->getRTL()) { |
||
270 | if ($this->padding) { |
||
271 | if (is_array($cM['cell'])) { |
||
272 | $renderer->tcpdf->setLeftMargin($cX + $cM['padding_left']); |
||
273 | } else { |
||
274 | $renderer->tcpdf->setLeftMargin($cX + $cM['cell']); |
||
275 | } |
||
276 | } else { |
||
277 | $renderer->tcpdf->setLeftMargin($cX); |
||
278 | } |
||
279 | $renderer->tcpdf->setRightMargin($renderer->getRemainingWidthPDF() - $cW + $cM['right']); |
||
280 | } elseif ($this->padding) { |
||
281 | if (is_array($cM['cell'])) { |
||
282 | $renderer->tcpdf->setRightMargin($cX + $cM['padding_right']); |
||
283 | } else { |
||
284 | $renderer->tcpdf->setRightMargin($cX + $cM['cell']); |
||
285 | } |
||
286 | $renderer->tcpdf->setLeftMargin($renderer->getRemainingWidthPDF() - $cW + $cM['left']); |
||
287 | } else { |
||
288 | $renderer->tcpdf->setRightMargin($cX); |
||
289 | $renderer->tcpdf->setLeftMargin($renderer->getRemainingWidthPDF() - $cW + $cM['left']); |
||
290 | } |
||
291 | // Save the current page number |
||
292 | $cPN = $renderer->tcpdf->getPage(); |
||
293 | |||
294 | // Render the elements (write text, print picture...) |
||
295 | foreach ($this->elements as $element) { |
||
296 | if ($element instanceof ReportBaseElement) { |
||
297 | $element->render($renderer); |
||
298 | } elseif ($element === 'footnotetexts') { |
||
299 | $renderer->footnotes(); |
||
300 | } elseif ($element === 'addpage') { |
||
301 | $renderer->newPage(); |
||
302 | } |
||
303 | } |
||
304 | // Restore the margins |
||
305 | $renderer->tcpdf->setLeftMargin($cM['left']); |
||
306 | $renderer->tcpdf->setRightMargin($cM['right']); |
||
307 | |||
308 | // This will be mostly used to trick the multiple images last height |
||
309 | if ($this->reseth) { |
||
310 | $cH = 0; |
||
311 | // This can only happen with multiple images and with pagebreak |
||
312 | if ($cPN !== $renderer->tcpdf->getPage()) { |
||
313 | $renderer->tcpdf->setPage($cPN); |
||
314 | } |
||
315 | } |
||
316 | // New line and some clean up |
||
317 | if (!$this->newline) { |
||
318 | $renderer->tcpdf->setXY($cX + $cW, $cY); |
||
319 | $renderer->lastCellHeight = $cH; |
||
320 | } else { |
||
321 | // addMarginX() also updates X |
||
322 | $renderer->addMarginX(0); |
||
323 | $renderer->tcpdf->setY($cY + $cH); |
||
324 | $renderer->lastCellHeight = 0; |
||
325 | } |
||
328 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths