Conditions | 31 |
Paths | > 20000 |
Total Lines | 145 |
Code Lines | 84 |
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 |
||
37 | public function render($renderer): void |
||
38 | { |
||
39 | if (str_contains($this->text, '{{:ptp:}}')) { |
||
40 | return; |
||
41 | } |
||
42 | $temptext = str_replace('#PAGENUM#', (string) $renderer->pageNo(), $this->text); |
||
43 | // underline «title» part of Source item |
||
44 | $temptext = str_replace([ |
||
45 | '«', |
||
46 | '»', |
||
47 | ], [ |
||
48 | '<u>', |
||
49 | '</u>', |
||
50 | ], $temptext); |
||
51 | |||
52 | // Set up the text style |
||
53 | if ($renderer->getCurrentStyle() !== $this->styleName) { |
||
54 | $renderer->setCurrentStyle($this->styleName); |
||
55 | } |
||
56 | |||
57 | // If (Future-feature-enable/disable cell padding) |
||
58 | $cP = $renderer->cPadding; |
||
59 | |||
60 | // Adjust the positions |
||
61 | if ($this->left === ReportBaseElement::CURRENT_POSITION) { |
||
62 | $this->left = $renderer->getX(); |
||
63 | } else { |
||
64 | $renderer->setX($this->left); |
||
65 | } |
||
66 | |||
67 | if ($this->top === ReportBaseElement::CURRENT_POSITION) { |
||
68 | $this->top = $renderer->getY(); |
||
69 | } else { |
||
70 | $renderer->setY($this->top); |
||
71 | } |
||
72 | |||
73 | // Start collecting the HTML code |
||
74 | echo '<div class="', $this->styleName, '" style="position:absolute;top:', $this->top, 'pt;'; |
||
75 | // Use Cell around padding to support RTL also |
||
76 | echo 'padding:', $cP, 'pt;'; |
||
77 | // LTR (left) or RTL (right) |
||
78 | echo $renderer->alignRTL, ':', $this->left, 'pt;'; |
||
79 | |||
80 | // Background color |
||
81 | if (!empty($this->bgcolor)) { |
||
82 | echo 'background-color:', $this->bgcolor, ';'; |
||
83 | } |
||
84 | |||
85 | // Borders |
||
86 | $bpixX = 0; |
||
87 | $bpixY = 0; |
||
88 | if (!empty($this->border)) { |
||
89 | // Border all around |
||
90 | if ($this->border === '1') { |
||
91 | echo ' border:solid ', $this->bocolor ?: 'black', ' 1pt;'; |
||
92 | $bpixX = 1; |
||
93 | $bpixY = 1; |
||
94 | } else { |
||
95 | if (str_contains($this->border, 'T')) { |
||
96 | echo ' border-top:solid ', $this->bocolor ?: 'black', ' 1pt;'; |
||
97 | $bpixY = 1; |
||
98 | } |
||
99 | if (str_contains($this->border, 'B')) { |
||
100 | echo ' border-bottom:solid ', $this->bocolor ?: 'black', ' 1pt;'; |
||
101 | $bpixY = 1; |
||
102 | } |
||
103 | if (str_contains($this->border, 'R')) { |
||
104 | echo ' border-right:solid ', $this->bocolor ?: 'black', ' 1pt;'; |
||
105 | $bpixX = 1; |
||
106 | } |
||
107 | if (str_contains($this->border, 'L')) { |
||
108 | echo ' border-left:solid ', $this->bocolor ?: 'black', ' 1pt;'; |
||
109 | $bpixX = 1; |
||
110 | } |
||
111 | } |
||
112 | } |
||
113 | // Check the width if set to page wide OR set by xml to larger then page wide |
||
114 | if ($this->width === 0.0 || $this->width > $renderer->getRemainingWidth()) { |
||
115 | $this->width = $renderer->getRemainingWidth(); |
||
116 | } |
||
117 | // We have to calculate a different width for the padding, counting on both side |
||
118 | $cW = $this->width - $cP * 2.0; |
||
119 | |||
120 | // If there is any text |
||
121 | if (!empty($temptext)) { |
||
122 | // Wrap the text |
||
123 | $temptext = $renderer->textWrap($temptext, $cW); |
||
124 | $tmph = $renderer->getTextCellHeight($temptext); |
||
125 | // Add some cell padding |
||
126 | $this->height += $cP; |
||
127 | if ($tmph > $this->height) { |
||
128 | $this->height = $tmph; |
||
129 | } |
||
130 | } |
||
131 | // Check the last cell height and adjust the current cell height if needed |
||
132 | if ($renderer->lastCellHeight > $this->height) { |
||
133 | $this->height = $renderer->lastCellHeight; |
||
134 | } |
||
135 | echo ' width:', $cW - $bpixX, 'pt;height:', $this->height - $bpixY, 'pt;'; |
||
136 | |||
137 | // Text alignment |
||
138 | switch ($this->align) { |
||
139 | case 'C': |
||
140 | echo ' text-align:center;'; |
||
141 | break; |
||
142 | case 'L': |
||
143 | echo ' text-align:left;'; |
||
144 | break; |
||
145 | case 'R': |
||
146 | echo ' text-align:right;'; |
||
147 | break; |
||
148 | } |
||
149 | |||
150 | // Print the collected HTML code |
||
151 | echo '">'; |
||
152 | |||
153 | // Print URL |
||
154 | if (!empty($this->url)) { |
||
155 | echo '<a href="', $this->url, '">'; |
||
156 | } |
||
157 | // Print any text if exists |
||
158 | if (!empty($temptext)) { |
||
159 | $renderer->write($temptext, $this->tcolor, false); |
||
160 | } |
||
161 | if (!empty($this->url)) { |
||
162 | echo '</a>'; |
||
163 | } |
||
164 | // Finish the cell printing and start to clean up |
||
165 | echo "</div>\n"; |
||
166 | |||
167 | // Where to place the next position |
||
168 | if ($this->newline === 0) { |
||
169 | // -> Next to this cell in the same line |
||
170 | $renderer->setXy($this->left + $this->width, $this->top); |
||
171 | $renderer->lastCellHeight = $this->height; |
||
172 | } elseif ($this->newline === 1) { |
||
173 | // -> On a new line at the margin - Default |
||
174 | $renderer->setXy(0, $renderer->getY() + $this->height + $cP * 2); |
||
175 | // Reset the last cell height for the next line |
||
176 | $renderer->lastCellHeight = 0; |
||
177 | } elseif ($this->newline === 2) { |
||
178 | // -> On a new line at the end of this cell |
||
179 | $renderer->setXy($renderer->getX() + $this->width, $renderer->getY() + $this->height + $cP * 2); |
||
180 | // Reset the last cell height for the next line |
||
181 | $renderer->lastCellHeight = 0; |
||
182 | } |
||
185 |