Conditions | 50 |
Paths | 10752 |
Total Lines | 143 |
Code Lines | 99 |
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 |
||
103 | public function addSticker(&$pdf, $outputlangs, $param) |
||
104 | { |
||
105 | global $mysoc, $conf; |
||
106 | |||
107 | $textleft = $param['textleft']; |
||
108 | $header = $param['textheader']; |
||
109 | $footer = $param['textfooter']; |
||
110 | $textright = $param['textright']; |
||
111 | $code = $param['code']; |
||
112 | $encoding = $param['encoding']; |
||
113 | $is2d = $param['is2d']; |
||
114 | |||
115 | |||
116 | // We are in a new page, then we must add a page |
||
117 | if (($this->_COUNTX == 0) && ($this->_COUNTY == 0) and (!$this->_First == 1)) { |
||
118 | $pdf->AddPage(); |
||
119 | } |
||
120 | $this->_First = 0; |
||
121 | $_PosX = $this->_Margin_Left + ($this->_COUNTX * ($this->_Width + $this->_X_Space)); |
||
122 | $_PosY = $this->_Margin_Top + ($this->_COUNTY * ($this->_Height + $this->_Y_Space)); |
||
123 | |||
124 | // Define logo |
||
125 | $logo = $conf->mycompany->dir_output . '/logos/' . $mysoc->logo; |
||
126 | if (!is_readable($logo)) { |
||
127 | $logo = ''; |
||
128 | if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small)) { |
||
129 | $logo = $conf->mycompany->dir_output . '/logos/thumbs/' . $mysoc->logo_small; |
||
130 | } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output . '/logos/' . $mysoc->logo)) { |
||
131 | $logo = $conf->mycompany->dir_output . '/logos/' . $mysoc->logo; |
||
132 | } |
||
133 | } |
||
134 | |||
135 | $xleft = 2; |
||
136 | $ytop = 2; |
||
137 | |||
138 | // Top |
||
139 | if ($header != '') { |
||
140 | $pdf->SetXY($_PosX + $xleft, $_PosY + 1); // Only 1 mm and not ytop for top text |
||
141 | $pdf->Cell(2 * strlen($header), $this->_Line_Height, $outputlangs->convToOutputCharset($header), 0, 1, 'C'); |
||
142 | } |
||
143 | |||
144 | $ytop += (empty($header) ? 0 : (1 + $this->_Line_Height)); |
||
145 | |||
146 | // Define widthtouse and heighttouse |
||
147 | $pageMargins = $pdf->getMargins(); |
||
148 | $maxwidthtouse = round($this->_Width - 2 * $xleft); |
||
149 | $maxheighttouse = round($this->_Height - 2 * $ytop); |
||
150 | $maxheighttouse -= (empty($footer) ? 0 : (1 + $this->_Line_Height)); |
||
151 | $defaultratio = ($maxwidthtouse / $maxheighttouse); |
||
152 | $widthtouse = $maxwidthtouse; |
||
153 | $heighttouse = $maxheighttouse; |
||
154 | $logoHeight = $heighttouse; |
||
155 | $logoWidth = $widthtouse; |
||
156 | |||
157 | //var_dump($this->_Width.'x'.$this->_Height.' with border and scale '.$imgscale.' => max '.$maxwidthtouse.'x'.$maxheighttouse.' => We use '.$widthtouse.'x'.$heighttouse);exit; |
||
158 | |||
159 | // Center |
||
160 | if ($textright == '') { // Only a left part |
||
161 | // Output left area |
||
162 | if ($textleft == '%LOGO%' && $logo) { |
||
163 | $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight); |
||
164 | } elseif ($code && !empty($encoding)) { |
||
165 | $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); |
||
166 | } else { |
||
167 | $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); |
||
168 | $pdf->MultiCell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); |
||
169 | } |
||
170 | } elseif ($textleft != '' && $textright != '') { // left and right part |
||
171 | $logoHeight = $heighttouse / 2; |
||
172 | $logoWidth = $widthtouse / 2; |
||
173 | if (($textleft == '%LOGO%' || $textleft == '%PHOTO%' || $textleft == '%BARCODE%') && !strstr($textright, '%')) { // left part logo/barcode right part text |
||
174 | if ($textleft == '%LOGO%' && $logo) { |
||
175 | $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, $logoWidth, 0); |
||
176 | } elseif ($code && !empty($encoding)) { |
||
177 | $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse / 2, $heighttouse); |
||
178 | } |
||
179 | $pdf->SetXY($_PosX + ($widthtouse / 2), $_PosY + $ytop); |
||
180 | $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); |
||
181 | } elseif (($textright == '%LOGO%' || $textright == '%PHOTO%' || $textright == '%BARCODE%') && !strstr($textleft, '%')) { // right part logo/barcode left part text |
||
182 | if ($textright == '%LOGO%' && $logo) { |
||
183 | $pdf->Image($logo, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $logoWidth, 0); |
||
184 | } elseif ($code && !empty($encoding)) { |
||
185 | $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + ($widthtouse / 2), $_PosY + $ytop, $widthtouse / 2, $heighttouse); |
||
186 | } |
||
187 | $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); |
||
188 | $pdf->MultiCell($widthtouse / 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); |
||
189 | } elseif ($textleft == '%LOGO%') { // left part logo right part text/barcode |
||
190 | if ($logo) { |
||
191 | $pdf->Image($logo, $_PosX + $xleft, $_PosY + $ytop, 0, $logoHeight); |
||
192 | } |
||
193 | if ($code && !empty($encoding)) { |
||
194 | $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse); |
||
195 | } else { |
||
196 | $pdf->SetXY($_PosX + $xleft + $logoWidth + 1, $_PosY + $ytop); |
||
197 | $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); |
||
198 | } |
||
199 | } elseif ($textright == '%LOGO%') { // right part logo left part text/barcode |
||
200 | if ($logo) { |
||
201 | $pdf->Image($logo, $_PosX + $xleft + $widthtouse - $logoWidth + 1, $_PosY + $ytop, 0, $logoHeight); |
||
202 | } |
||
203 | if ($code && !empty($encoding)) { |
||
204 | $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $xleft, $_PosY + $ytop, $widthtouse - $logoWidth - 1, $heighttouse); |
||
205 | } else { |
||
206 | $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); |
||
207 | $pdf->MultiCell($widthtouse - $logoWidth - 1, $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); |
||
208 | } |
||
209 | } else { // text on halft left and text on half right |
||
210 | $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); |
||
211 | $pdf->MultiCell(round($this->_Width / 2), $this->_Line_Height, $outputlangs->convToOutputCharset($textleft), 0, 'L'); |
||
212 | $pdf->SetXY($_PosX + round($this->_Width / 2), $_PosY + $ytop); |
||
213 | $pdf->MultiCell(round($this->_Width / 2) - 2, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); |
||
214 | } |
||
215 | } else { // Only a right part |
||
216 | // Output right area |
||
217 | if ($textright == '%LOGO%' && $logo) { |
||
218 | $pdf->Image($logo, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, 0, $logoHeight); |
||
219 | } elseif ($code && !empty($encoding)) { |
||
220 | $this->writeBarcode($pdf, $code, $encoding, $is2d, $_PosX + $this->_Width - $widthtouse - $xleft, $_PosY + $ytop, $widthtouse, $heighttouse); |
||
221 | } else { |
||
222 | $pdf->SetXY($_PosX + $xleft, $_PosY + $ytop); |
||
223 | $pdf->MultiCell($this->_Width - $xleft, $this->_Line_Height, $outputlangs->convToOutputCharset($textright), 0, 'R'); |
||
224 | } |
||
225 | } |
||
226 | |||
227 | // Bottom |
||
228 | if ($footer != '') { |
||
229 | $pdf->SetXY($_PosX, $_PosY + $this->_Height - $this->_Line_Height - 1); |
||
230 | $pdf->Cell($this->_Width, $this->_Line_Height, $outputlangs->convToOutputCharset($footer), 0, 1, 'C'); |
||
231 | } |
||
232 | //print "$_PosY+$this->_Height-$this->_Line_Height-1<br>\n"; |
||
233 | |||
234 | $this->_COUNTY++; |
||
235 | |||
236 | if ($this->_COUNTY == $this->_Y_Number) { |
||
237 | // Si on est en bas de page, on remonte le 'curseur' de position |
||
238 | $this->_COUNTX++; |
||
239 | $this->_COUNTY = 0; |
||
240 | } |
||
241 | |||
242 | if ($this->_COUNTX == $this->_X_Number) { |
||
243 | // Si on est en bout de page, alors on repart sur une nouvelle page |
||
244 | $this->_COUNTX = 0; |
||
245 | $this->_COUNTY = 0; |
||
246 | } |
||
372 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.