Test Failed
Push — master ( 50ebf9...195aca )
by Gabriel
12:00 queued 12s
created

PdfHelper   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 43.48%

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 0
dl 0
loc 64
ccs 10
cts 23
cp 0.4348
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pdfXPosition() 0 16 5
A pdfYPosition() 0 15 4
A pdfPrepareColor() 0 7 3
1
<?php
2
3
namespace ByTIC\DocumentGenerator\PdfLetters;
4
5
use setasign\Fpdi\Tcpdf\Fpdi;
6
7
8
/**
9
 * Class PdfHelper
10
 * @package ByTIC\DocumentGenerator\PdfLetters
11
 */
12
class PdfHelper
13
{
14
15
16
    /**
17
     * @param Fpdi $pdf
18
     * @param $value
19
     * @param $x
20
     * @param null $align
21
     * @return int|string
22
     */
23 1
    public static function pdfXPosition($pdf, $value, $x, $align = null)
24
    {
25
        switch ($align) {
26 1
            case 'center':
27
                return $x - ($pdf->GetStringWidth($value) / 2);
28 1
            case 'right':
29
                $x = $x - $pdf->GetStringWidth($value);
30
                if ($x < 0) {
31
                    $x = 0;
32
                }
33
                return $x;
34 1
            case 'left':
35
            default:
36 1
                return $x;
37
        }
38
    }
39
40
    /**
41
     * @param Fpdi $pdf
42
     * @param $value
43
     * @param $y
44
     * @return int|string
45
     */
46 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.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48 1
        $page = 1;
49 1
        if ($y > 297) {
50
            $page = round($y / 297, 0);
51
            $y -= ($page * 297);
52
            $page++;
53
        }
54
55 1
        if ($pdf->getPage() != $page && $page <= $pdf->getNumPages()) {
56
            $pdf->setPage($page);
57
        }
58
59 1
        return $y;
60
    }
61
62
    /**
63
     * @param Fpdi $pdf
64
     * @param array $colors
65
     * @param bool $ret
66
     * @return string
67
     */
68
    public static function pdfPrepareColor($pdf, $colors = [], $ret = false)
69
    {
70
        if (is_array($colors) && count($colors) >= 3) {
71
            return $pdf->SetTextColorArray($colors, $ret);
72
        }
73
        return $pdf->SetTextColor(0, 0, 0, $ret);
74
    }
75
}
76