PdfHelper::pdfPrepareColor()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 10
cc 3
nc 2
nop 3
crap 12
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
Are you sure the doc-type for parameter $align is correct as it would always require null to be passed?
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
Unused Code introduced by
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 ignore-unused  annotation

43
    public static function pdfYPosition($pdf, /** @scrutinizer ignore-unused */ $value, $y)

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
Bug introduced by
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 ignore-type  annotation

53
            $pdf->setPage(/** @scrutinizer ignore-type */ $page);
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
Bug introduced by
$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 ignore-type  annotation

70
        return $pdf->SetTextColor(0, 0, 0, /** @scrutinizer ignore-type */ $ret);
Loading history...
71
    }
72
}
73