Completed
Push — master ( 0b1d68...e7164a )
by Roberto
12:40 queued 09:51
created

src/Common/DaCommon.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
4
namespace NFePHP\DA\Common;
5
6
use NFePHP\DA\Legacy\Common;
7
8
class DaCommon extends Common
9
{
10
    protected $debugmode;
11
    protected $orientacao = 'P';
12
    protected $papel = 'A4';
13
    protected $margsup = 2;
14
    protected $margesq = 2;
15
    protected $wCanhoto = 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
     * Renderiza o pdf e retorna como raw
52
     *
53
     * @return string
54
     */
55
    public function render()
56
    {
57
        if (empty($this->pdf)) {
0 ignored issues
show
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...
58
            $this->monta();
0 ignored issues
show
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...
59
        }
60
        if (!$this->debugmode) {
61
            return $this->pdf->getPdf();
62
        }
63
        echo "Modo Debug Ativado";
64
    }
65
66
    
67
    /**
68
     * Add the credits to the integrator in the footer message
69
     *
70
     * @param string $message Mensagem do integrador a ser impressa no rodapé das paginas
71
     *
72
     * @return void
73
     */
74
    public function creditsIntegratorFooter($message = '')
75
    {
76
        $this->creditos = trim($message);
77
    }
78
    
79
    /**
80
     *
81
     * @param string $font
82
     */
83
    public function setFontType(string $font = 'times')
84
    {
85
        $this->aFont['font'] = $font;
86
    }
87
    
88
    /**
89
     * Seta as margens superior e esquerda
90
     * a margem direita é igual a esquerda e
91
     * a inferior é igual a superior
92
     * @param int $margSup
93
     * @param int $margEsq
94
     *
95
     * @return void
96
     */
97
    public function margins(int $margSup = null, int $margEsq = null)
98
    {
99
        $this->margsup = $margSup ?? 2;
100
        $this->margesq = $margEsq ?? 2;
101
    }
102
    
103
    /**
104
     * Seta o tamanho da fonte
105
     *
106
     * @param int $size
107
     *
108
     * @return void
109
     */
110
    protected function setFontSize(int $size = 8)
111
    {
112
        
113
        $this->aFont['size'] = $size;
114
    }
115
    
116
    /**
117
     *
118
     * @param string $style
119
     */
120
    protected function setFontStyle(string $style = '')
121
    {
122
        $this->aFont['style'] = $style;
123
    }
124
    
125
    /**
126
     * Seta a orientação
127
     *
128
     * @param string $force
129
     * @param string $tpImp
130
     *
131
     * @return void
132
     */
133
    protected function setOrientationAndSize(
134
        $force = null,
135
        $tpImp = null
136
    ) {
137
        if (!empty($force) && ($force === 'P' || $force === 'L')) {
138
            $this->orientacao = $force;
139
        } elseif (!empty($tpImp)) {
140
            if ($tpImp == '1') {
141
                $this->orientacao = 'P';
142
            } else {
143
                $this->orientacao = 'L';
144
            }
145
        } else {
146
            $this->orientacao = 'P';
147
        }
148
        if ($this->orientacao == 'P') {
149
            if (strtoupper($this->papel) == 'A4') {
150
                $this->maxW = 210;
151
                $this->maxH = 297;
152
            } else {
153
                $this->papel = 'legal';
154
                $this->maxW = 216;
155
                $this->maxH = 355;
156
            }
157
        } else {
158
            if (strtoupper($this->papel) == 'A4') {
159
                $this->maxH = 210;
160
                $this->maxW = 297;
161
            } else {
162
                $this->papel = 'legal';
163
                $this->maxH = 216;
164
                $this->maxW = 355;
165
            }
166
        }
167
        $this->wPrint = $this->maxW - ($this->margesq * 2);
168
        $this->hPrint = $this->maxH - $this->margsup - 2;
169
    }
170
}
171