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