Completed
Pull Request — master (#279)
by Roberto
02:21
created

DaCommon::margins()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A DaCommon::creditsIntegratorFooter() 0 4 1
1
<?php
2
3
namespace NFePHP\DA\Common;
4
5
use NFePHP\DA\Legacy\Common;
6
7
class DaCommon extends Common
8
{
9
10
    protected $debugmode;
11
    protected $orientacao = 'P';
12
    protected $force;
13
    protected $papel = 'A4';
14
    protected $margsup = 2;
15
    protected $margesq = 2;
16
    protected $wPrint;
17
    protected $hPrint;
18
    protected $xIni;
19
    protected $yIni;
20
    protected $maxH;
21
    protected $maxW;
22
    protected $fontePadrao = 'times';
23
    protected $aFont = ['font' => 'times', 'size' => 8, 'style' => ''];
24
    protected $creditos;
25
26
    /**
27
     * Ativa ou desativa o modo debug
28
     *
29
     * @param bool $activate Ativa ou desativa o modo debug
30
     *
31
     * @return bool
32
     */
33
    public function debugMode($activate = null)
34
    {
35
        if (isset($activate) && is_bool($activate)) {
36
            $this->debugmode = $activate;
37
        }
38
        if ($this->debugmode) {
39
            //ativar modo debug
40
            error_reporting(E_ALL);
41
            ini_set('display_errors', 'On');
42
        } else {
43
            //desativar modo debug
44
            error_reporting(0);
45
            ini_set('display_errors', 'Off');
46
        }
47
        return $this->debugmode;
48
    }
49
    
50
    /**
51
     * Define parametros de impressão
52
     * @param string $orientacao
53
     * @param string $papel
54
     * @param int $margSup
55
     * @param int $margEsq
56
     */
57
    public function printParameters(
58
        $orientacao = 'P',
59
        $papel = 'A4',
60
        $margSup = null,
61
        $margEsq = null
62
    ) {
63
        if ($orientação === 'P' || $orientacao === 'L') {
0 ignored issues
show
Bug introduced by
The variable $orientação does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
64
            $this->force = $orientacao;
65
        }
66
        $p = strtoupper($papel);
67
        if ($p == 'A4' || $p == 'LEGAL') {
68
            $this->papel = $papel;
69
        }
70
        $this->margsup = $margSup ?? 2;
71
        $this->margesq = $margEsq ?? 2;
72
    }
73
74
    /**
75
     * Renderiza o pdf e retorna como raw
76
     *
77
     * @return string
78
     */
79
    public function render()
80
    {
81
        if (empty($this->pdf)) {
0 ignored issues
show
Bug introduced by
The property pdf does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
82
            $this->monta();
0 ignored issues
show
Bug introduced by
The method monta() does not seem to exist on object<NFePHP\DA\Common\DaCommon>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
        }
84
        if (!$this->debugmode) {
85
            return $this->pdf->getPdf();
86
        }
87
        throw new \Exception("Modo Debug Ativado");
88
    }
89
90
    /**
91
     * Add the credits to the integrator in the footer message
92
     *
93
     * @param string $message Mensagem do integrador a ser impressa no rodapé das paginas
94
     *
95
     * @return void
96
     */
97
    public function creditsIntegratorFooter($message = '')
98
    {
99
        $this->creditos = trim($message);
100
    }
101
102
    /**
103
     *
104
     * @param string $font
105
     */
106
    public function setFontType(string $font = 'times')
107
    {
108
        $this->aFont['font'] = $font;
109
    }
110
111
    /**
112
     * Seta o tamanho da fonte
113
     *
114
     * @param int $size
115
     *
116
     * @return void
117
     */
118
    protected function setFontSize(int $size = 8)
119
    {
120
        $this->aFont['size'] = $size;
121
    }
122
123
    /**
124
     *
125
     * @param string $style
126
     */
127
    protected function setFontStyle(string $style = '')
128
    {
129
        $this->aFont['style'] = $style;
130
    }
131
132
    /**
133
     * Seta a orientação
134
     *
135
     * @param string $force
136
     * @param string $tpImp
137
     *
138
     * @return void
139
     */
140
    protected function setOrientationAndSize($force = null, $tpImp = null)
141
    {
142
        $this->orientacao = 'P';
143
        if (!empty($force)) {
144
            $this->orientacao = $force;
145
        } elseif (!empty($tpImp)) {
146
            if ($tpImp == '2') {
147
                $this->orientacao = 'L';
148
            } else {
149
                $this->orientacao = 'P';
150
            }
151
        }
152
        if (strtoupper($this->papel) == 'A4') {
153
            $this->maxW = 210;
154
            $this->maxH = 297;
155
        } else {
156
            $this->papel = 'legal';
157
            $this->maxW = 216;
158
            $this->maxH = 355;
159
        }
160
        if ($this->orientacao == 'L') {
161
            if (strtoupper($this->papel) == 'A4') {
162
                $this->maxH = 210;
163
                $this->maxW = 297;
164
            } else {
165
                $this->papel = 'legal';
166
                $this->maxH = 216;
167
                $this->maxW = 355;
168
            }
169
        }
170
        $this->wPrint = $this->maxW - $this->margesq * 2;
171
        $this->hPrint = $this->maxH - $this->margsup - 5;
172
    }
173
    
174
    protected function imagePNGtoJPG($original)
175
    {
176
        $image = imagecreatefrompng($original);
177
        ob_start();
178
        imagejpeg($image, null, 100);
179
        imagedestroy($image);
180
        $stringdata = ob_get_contents(); // read from buffer
181
        ob_end_clean();
182
        return 'data://text/plain;base64,'.base64_encode($stringdata);
183
    }
184
}
185