| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace ByTIC\DocumentGenerator\PdfLetters; |
||||
| 4 | |||||
| 5 | use setasign\Fpdi\Tcpdf\Fpdi; |
||||
| 6 | |||||
| 7 | /** |
||||
| 8 | * Class PdfHelper |
||||
| 9 | * @package ByTIC\DocumentGenerator\PdfLetters |
||||
| 10 | */ |
||||
| 11 | class PdfHelper |
||||
| 12 | { |
||||
| 13 | /** |
||||
| 14 | * @param Fpdi $pdf |
||||
| 15 | * @param $value |
||||
| 16 | * @param $x |
||||
| 17 | * @param null $align |
||||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||||
| 18 | * @return int|string |
||||
| 19 | */ |
||||
| 20 | 1 | public static function pdfXPosition($pdf, $value, $x, $align = null) |
|||
| 21 | { |
||||
| 22 | 1 | switch ($align) { |
|||
| 23 | 1 | case 'center': |
|||
| 24 | return $x - ($pdf->GetStringWidth($value) / 2); |
||||
| 25 | 1 | case 'right': |
|||
| 26 | $x = $x - $pdf->GetStringWidth($value); |
||||
| 27 | if ($x < 0) { |
||||
| 28 | $x = 0; |
||||
| 29 | } |
||||
| 30 | return $x; |
||||
| 31 | 1 | case 'left': |
|||
| 32 | default: |
||||
| 33 | 1 | return $x; |
|||
| 34 | } |
||||
| 35 | } |
||||
| 36 | |||||
| 37 | /** |
||||
| 38 | * @param Fpdi $pdf |
||||
| 39 | * @param $value |
||||
| 40 | * @param $y |
||||
| 41 | * @return int|string |
||||
| 42 | */ |
||||
| 43 | 1 | public static function pdfYPosition($pdf, $value, $y) |
|||
|
0 ignored issues
–
show
The parameter
$value is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 44 | { |
||||
| 45 | 1 | $page = 1; |
|||
| 46 | 1 | if ($y > 297) { |
|||
| 47 | $page = round($y / 297, 0); |
||||
| 48 | $y -= ($page * 297); |
||||
| 49 | $page++; |
||||
| 50 | } |
||||
| 51 | |||||
| 52 | 1 | if ($pdf->getPage() != $page && $page <= $pdf->getNumPages()) { |
|||
| 53 | $pdf->setPage($page); |
||||
|
0 ignored issues
–
show
It seems like
$page can also be of type double; however, parameter $pnum of TCPDF::setPage() does only seem to accept integer, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 54 | } |
||||
| 55 | |||||
| 56 | 1 | return $y; |
|||
| 57 | } |
||||
| 58 | |||||
| 59 | /** |
||||
| 60 | * @param Fpdi $pdf |
||||
| 61 | * @param array $colors |
||||
| 62 | * @param bool $ret |
||||
| 63 | * @return string |
||||
| 64 | */ |
||||
| 65 | public static function pdfPrepareColor($pdf, $colors = [], $ret = false) |
||||
| 66 | { |
||||
| 67 | if (is_array($colors) && count($colors) >= 3) { |
||||
| 68 | return $pdf->SetTextColorArray($colors, $ret); |
||||
| 69 | } |
||||
| 70 | return $pdf->SetTextColor(0, 0, 0, $ret); |
||||
|
0 ignored issues
–
show
$ret of type boolean is incompatible with the type double expected by parameter $col4 of TCPDF::setTextColor().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 71 | } |
||||
| 72 | } |
||||
| 73 |