Completed
Pull Request — master (#60)
by Roberto
13:28
created

Danfce::pConsumidorDANFE()   C

Complexity

Conditions 10
Paths 129

Size

Total Lines 70
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 0
Metric Value
cc 10
eloc 64
nc 129
nop 3
dl 0
loc 70
ccs 0
cts 66
cp 0
crap 110
rs 5.6296
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
/**
6
 * Classe para a impressão em PDF do Documento Auxiliar de NFe Consumidor
7
 * NOTA: Esta classe não é a indicada para quem faz uso de impressoras térmicas ESCPOS
8
 *
9
 * @category  Library
10
 * @package   nfephp-org/sped-da
11
 * @copyright 2009-2016 NFePHP
12
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
13
 * @link      http://github.com/nfephp-org/sped-da for the canonical source repository
14
 * @author    Roberto Spadim <roberto at spadim dot com dot br>
15
 */
16
17
use Exception;
18
use NFePHP\DA\Legacy\Dom;
19
use NFePHP\DA\Legacy\Pdf;
20
use NFePHP\DA\Legacy\Common;
21
use Endroid\QrCode\QrCode;
22
use DateTime;
23
24
class Danfce extends Common
25
{
26
    protected $papel;
27
    protected $xml; // string XML NFe
28
    protected $logomarca=''; // path para logomarca em jpg
29
    protected $formatoChave="#### #### #### #### #### #### #### #### #### #### ####";
30
    protected $debugMode=0; //ativa ou desativa o modo de debug
31
    protected $tpImp; //ambiente
32
    protected $fontePadrao='Times';
33
    protected $nfeProc;
34
    protected $nfe;
35
    protected $infNFe;
36
    protected $ide;
37
    protected $enderDest;
38
    protected $ICMSTot;
39
    protected $imposto;
40
    protected $emit;
41
    protected $enderEmit;
42
    protected $qrCode;
43
    protected $det;
44
    protected $pag;
45
    protected $dest;
46
    protected $imgQRCode;
47
    protected $urlQR = '';
48
    protected $pdf;
49
    protected $margemInterna = 2;
50
    protected $hMaxLinha = 9;
51
    protected $hBoxLinha = 6;
52
    protected $hLinha = 3;
53
    
54
    /**
55
     * __contruct
56
     *
57
     * @param string $docXML
58
     * @param string $sPathLogo
59
     * @param string $mododebug
60
     * @param string $idToken
61
     * @param string $Token
0 ignored issues
show
Bug introduced by
There is no parameter named $Token. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
62
     */
63
    public function __construct(
64
        $docXML = '',
65
        $sPathLogo = '',
66
        $mododebug = 0,
67
        // habilita os erros do sistema
68
        $idToken = '',
0 ignored issues
show
Unused Code introduced by
The parameter $idToken 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...
69
        $emitToken = '',
0 ignored issues
show
Unused Code introduced by
The parameter $emitToken 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...
70
        $urlQR = ''
0 ignored issues
show
Unused Code introduced by
The parameter $urlQR 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...
71
    ) {
72
        if (is_numeric($mododebug)) {
73
            $this->debugMode = $mododebug;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mododebug can also be of type double or string. However, the property $debugMode is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
74
        }
75 View Code Duplication
        if ($this->debugMode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
            //ativar modo debug
77
            error_reporting(E_ALL);
78
            ini_set('display_errors', 'On');
79
        } else {
80
            //desativar modo debug
81
            error_reporting(0);
82
            ini_set('display_errors', 'Off');
83
        }
84
        $this->xml = $docXML;
85
        $this->logomarca = $sPathLogo;
86
        if (empty($fonteDANFE)) {
0 ignored issues
show
Bug introduced by
The variable $fonteDANFE seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
87
            $this->fontePadrao = 'Times';
88
        } else {
89
            $this->fontePadrao = $fonteDANFE;
90
        }
91
        if (!empty($this->xml)) {
92
            $this->dom = new Dom();
0 ignored issues
show
Bug introduced by
The property dom 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...
93
            $this->dom->loadXML($this->xml);
94
            $this->nfeProc    = $this->dom->getElementsByTagName("nfeProc")->item(0);
95
            $this->nfe        = $this->dom->getElementsByTagName("NFe")->item(0);
96
            $this->infNFe     = $this->dom->getElementsByTagName("infNFe")->item(0);
97
            $this->ide        = $this->dom->getElementsByTagName("ide")->item(0);
98
            $this->emit       = $this->dom->getElementsByTagName("emit")->item(0);
99
            $this->enderEmit  = $this->dom->getElementsByTagName("enderEmit")->item(0);
100
            $this->det        = $this->dom->getElementsByTagName("det");
101
            $this->dest       = $this->dom->getElementsByTagName("dest")->item(0);
102
            $this->pag        = $this->dom->getElementsByTagName("pag");
103
            $this->imposto    = $this->dom->getElementsByTagName("imposto")->item(0);
104
            $this->ICMSTot    = $this->dom->getElementsByTagName("ICMSTot")->item(0);
105
            $this->tpImp      = $this->ide->getElementsByTagName("tpImp")->item(0)->nodeValue;
106
        }
107
        $this->qrCode = $this->dom->getElementsByTagName('qrCode')->item(0)->nodeValue;
108
        if ($this->pSimpleGetValue($this->ide, "mod") != '65') {
109
            throw new nfephpException("O xml do DANFE deve ser uma NFC-e modelo 65");
110
        }
111
    }
112
    
113
    public function getPapel()
114
    {
115
        return $this->papel;
116
    }
117
    
118
    public function setPapel($aPap)
119
    {
120
        $this->papel = $aPap;
121
    }
122
    
123
    public function montaDANFE(
124
        $orientacao = 'P',
125
        $papel = '',
0 ignored issues
show
Unused Code introduced by
The parameter $papel 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...
126
        $logoAlign = 'C',
127
        $classPdf = false,
128
        $depecNumReg = ''
129
    ) {
130
        $qtdItens = $this->det->length;
131
        $qtdPgto = $this->pag->length;
132
        $hMaxLinha = $this->hMaxLinha;
133
        $hBoxLinha = $this->hBoxLinha;
0 ignored issues
show
Unused Code introduced by
$hBoxLinha is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
134
        $hLinha = $this->hLinha;
135
        $tamPapelVert = 160 +16+ (($qtdItens-1)*$hMaxLinha) + ($qtdPgto*$hLinha);
136
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
137
        if ($orientacao == '') {
138
            $orientacao = 'P';
139
        }
140
        $this->orientacao = $orientacao;
0 ignored issues
show
Bug introduced by
The property orientacao 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...
141
        $this->papel = array(80,$tamPapelVert);
142
        $this->logoAlign = $logoAlign;
0 ignored issues
show
Bug introduced by
The property logoAlign 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...
143
        $this->situacao_externa = $situacaoExterna;
0 ignored issues
show
Bug introduced by
The property situacao_externa 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...
Bug introduced by
The variable $situacaoExterna 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...
144
        $this->numero_registro_dpec = $depecNumReg;
0 ignored issues
show
Bug introduced by
The property numero_registro_dpec 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...
145
        //instancia a classe pdf
146
        if ($classPdf) {
147
            $this->pdf = $classPdf;
148
        } else {
149
            $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
0 ignored issues
show
Documentation introduced by
$this->papel is of type array<integer,integer,{"...nteger","1":"integer"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
150
        }
151
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
152
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
153
        //apenas para controle se necessário ser maior do que a margem superior
154
        $margSup = 2;
155
        $margEsq = 2;
156
        $margInf = 2;
157
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
158
        $xInic = $margEsq;
159
        $yInic = $margSup;
160
        $maxW = 80;
161
        $maxH = $tamPapelVert;
162
        //total inicial de paginas
163
        $totPag = 1;
0 ignored issues
show
Unused Code introduced by
$totPag is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
164
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
165
        $this->wPrint = $maxW-($margEsq*2);
0 ignored issues
show
Bug introduced by
The property wPrint 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...
166
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
167
        //superior e inferior
168
        $this->hPrint = $maxH-$margSup-$margInf;
0 ignored issues
show
Bug introduced by
The property hPrint 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...
169
        // estabelece contagem de paginas
170
        $this->pdf->aliasNbPages();
171
        $this->pdf->setMargins($margEsq, $margSup); // fixa as margens
172
        $this->pdf->setDrawColor(0, 0, 0);
173
        $this->pdf->setFillColor(255, 255, 255);
174
        $this->pdf->open(); // inicia o documento
175
        $this->pdf->addPage($this->orientacao, $this->papel); // adiciona a primeira página
0 ignored issues
show
Documentation introduced by
$this->papel is of type array<integer,integer,{"...nteger","1":"integer"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
176
        $this->pdf->setLineWidth(0.1); // define a largura da linha
177
        $this->pdf->setTextColor(0, 0, 0);
178
        $this->pTextBox(0, 0, $maxW, $maxH); // POR QUE PRECISO DESA LINHA?
179
        $hcabecalho = 27;//para cabeçalho (dados emitente mais logomarca)  (FIXO)
180
        $hcabecalhoSecundario = 10;//para cabeçalho secundário (cabeçalho sefaz) (FIXO)
181
        $hprodutos = $hLinha + ($qtdItens*$hMaxLinha) ;//box poduto
182
        $hTotal = 12; //box total (FIXO)
183
        $hpagamentos = $hLinha + ($qtdPgto*$hLinha);//para pagamentos
184
        $hmsgfiscal = 21;// para imposto (FIXO)
185
        if (!isset($this->dest)) {
186
            $hcliente = 6;// para cliente (FIXO)
187
        } else {
188
            $hcliente = 12;
189
        }// para cliente (FIXO)};
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
190
        $hQRCode = 50;// para qrcode (FIXO)
191
        $hCabecItens = 4;//cabeçalho dos itens
192
        
193
        $hUsado = $hCabecItens;
0 ignored issues
show
Unused Code introduced by
$hUsado is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
194
        $w2 = round($this->wPrint*0.31, 0);
0 ignored issues
show
Unused Code introduced by
$w2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
195
        $totPag = 1;
196
        $pag = 1;
197
        $x = $xInic;
198
        //COLOCA CABEÇALHO
199
        $y = $yInic;
200
        $y = $this->pCabecalhoDANFE($x, $y, $hcabecalho, $pag, $totPag);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pCabecalhoDANFE($...becalho, $pag, $totPag) (which targets NFePHP\DA\NFe\Danfce::pCabecalhoDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
201
        //COLOCA CABEÇALHO SECUNDÁRIO
202
        $y = $hcabecalho;
203
        $y = $this->pCabecalhoSecundarioDANFE($x, $y, $hcabecalhoSecundario);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pCabecalhoSecunda... $hcabecalhoSecundario) (which targets NFePHP\DA\NFe\Danfce::pCabecalhoSecundarioDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
204
        //COLOCA PRODUTOS
205
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario;
206
        $y = $this->pProdutosDANFE($x, $y, $hprodutos);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pProdutosDANFE($x, $y, $hprodutos) (which targets NFePHP\DA\NFe\Danfce::pProdutosDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
207
        //COLOCA TOTAL
208
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos;
209
        $y = $this->pTotalDANFE($x, $y, $hTotal);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pTotalDANFE($x, $y, $hTotal) (which targets NFePHP\DA\NFe\Danfce::pTotalDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
210
        //COLOCA PAGAMENTOS
211
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal;
212
        $y = $this->pPagamentosDANFE($x, $y, $hpagamentos);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pPagamentosDANFE($x, $y, $hpagamentos) (which targets NFePHP\DA\NFe\Danfce::pPagamentosDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
213
        //COLOCA MENSAGEM FISCAL
214
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal+ $hpagamentos;
215
        $y = $this->pFiscalDANFE($x, $y, $hmsgfiscal);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pFiscalDANFE($x, $y, $hmsgfiscal) (which targets NFePHP\DA\NFe\Danfce::pFiscalDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
216
        //COLOCA CONSUMIDOR
217
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos + $hmsgfiscal;
218
        $y = $this->pConsumidorDANFE($x, $y, $hcliente);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pConsumidorDANFE($x, $y, $hcliente) (which targets NFePHP\DA\NFe\Danfce::pConsumidorDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
219
        //COLOCA QRCODE
220
        $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos
221
            + $hTotal + $hpagamentos + $hmsgfiscal + $hcliente;
222
        $y = $this->pQRDANFE($x, $y, $hQRCode);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $y is correct as $this->pQRDANFE($x, $y, $hQRCode) (which targets NFePHP\DA\NFe\Danfce::pQRDANFE()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$y is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
223
        //retorna o ID na NFe
224 View Code Duplication
        if ($classPdf!==false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
225
            $aR = [
226
             'id'=>str_replace('NFe', '', $this->infNFe->getAttribute("Id")),
227
             'classe_PDF'=>$this->pdf
228
            ];
229
            return $aR;
230
        } else {
231
            return str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
232
        }
233
    }
234
    
235
    protected function pCabecalhoDANFE($x = 0, $y = 0, $h = 0, $pag = '1', $totPag = '1')
0 ignored issues
show
Unused Code introduced by
The parameter $x 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...
Unused Code introduced by
The parameter $pag 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...
Unused Code introduced by
The parameter $totPag 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...
236
    {
237
        $emitRazao  = $this->pSimpleGetValue($this->emit, "xNome");
238
        $emitCnpj   = $this->pSimpleGetValue($this->emit, "CNPJ");
239
        $emitCnpj   = $this->pFormat($emitCnpj, "##.###.###/####-##");
240
        $emitIE     = $this->pSimpleGetValue($this->emit, "IE");
241
        $emitIM     = $this->pSimpleGetValue($this->emit, "IM");
242
        $emitFone = $this->pSimpleGetValue($this->enderEmit, "fone");
243
        $foneLen = strlen($emitFone);
244
        if ($foneLen>0) {
245
            $ddd = substr($emitFone, 0, 2);
246
            $fone1 = substr($emitFone, -8);
247
            if ($foneLen == 11) {
248
                $digito9 = substr($emitFone, 2, 1);
249
            }
250
            $emitFone = ' - ('.$ddd.') '.$digito9. ' ' . substr($fone1, 0, 4) . '-' . substr($fone1, -4);
0 ignored issues
show
Bug introduced by
The variable $digito9 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
251
        } else {
252
            $emitFone = '';
253
        }
254
        $emitLgr = $this->pSimpleGetValue($this->enderEmit, "xLgr");
255
        $emitNro = $this->pSimpleGetValue($this->enderEmit, "nro");
256
        $emitCpl = $this->pSimpleGetValue($this->enderEmit, "xCpl", "");
257
        $emitBairro = $this->pSimpleGetValue($this->enderEmit, "xBairro");
258
        $emitCEP = $this->pFormat($this->pSimpleGetValue($this->enderEmit, "CEP"), "#####-###");
259
        $emitMun = $this->pSimpleGetValue($this->enderEmit, "xMun");
260
        $emitUF = $this->pSimpleGetValue($this->enderEmit, "UF");
261
        // CONFIGURAÇÃO DE POSIÇÃO
262
        $margemInterna = $this->margemInterna;
263
        $maxW = $this->wPrint;
264
        $h = $h-($margemInterna);
265
        //COLOCA LOGOMARCA
266
        if (is_file($this->logomarca)) {
267
            $xImg = $margemInterna;
268
            $yImg = $margemInterna + 1;
269
            $this->pdf->Image($this->logomarca, $xImg, $yImg, 30, 22.5);
270
            $xRs = ($maxW*0.4) + $margemInterna;
271
            $wRs = ($maxW*0.6);
272
            $alignEmit = 'L';
273
        } else {
274
            $xRs = $margemInterna;
275
            $wRs = ($maxW*1);
276
            $alignEmit = 'L';
277
        }
278
        //COLOCA RAZÃO SOCIAL
279
        $texto = $emitRazao;
280
        $texto = $texto . "\nCNPJ:" . $emitCnpj;
281
        $texto = $texto . "\nIE:" . $emitIE;
282
        if (!empty($emitIM)) {
283
            $texto = $texto . " - IM:" . $emitIM;
284
        }
285
        $texto = $texto . "\n" . $emitLgr . "," . $emitNro . " " . $emitCpl . "," . $emitBairro
286
                . ". CEP:" . $emitCEP . ". " . $emitMun . "-" . $emitUF . $emitFone;
287
        $this->pTextBox($xRs, $y, $wRs, $h, $texto, $aFont, 'C', $alignEmit, 0, '', false);
0 ignored issues
show
Bug introduced by
The variable $aFont 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...
288
    }
289
    
290
    protected function pCabecalhoSecundarioDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
291
    {
292
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
293
        $maxW = $this->wPrint;
294
        $w = ($maxW*1);
295
        $hBox1 = 7;
296
        $texto = "DANFE NFC-e\nDocumento Auxiliar da Nota Fiscal de Consumidor Eletrônica";
297
        $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
298
        $this->pTextBox($x, $y, $w, $hBox1, $texto, $aFont, 'C', 'C', 0, '', false);
299
        $hBox2 = 4;
300
        $yBox2 = $y + $hBox1;
301
        $texto = "\nNFC-e não permite aproveitamento de crédito de ICMS";
302
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
303
        $this->pTextBox($x, $yBox2, $w, $hBox2, $texto, $aFont, 'C', 'C', 0, '', false);
304
    }
305
    
306
    protected function pProdutosDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
307
    {
308
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
309
        $maxW = $this->wPrint;
310
        $qtdItens = $this->det->length;
311
        $w = ($maxW*1);
312
        $hLinha = $this->hLinha;
313
        $aFontCabProdutos = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
314
        $wBoxCod = $w*0.17;
315
        $texto = "CÓDIGO";
316
        $this->pTextBox($x, $y, $wBoxCod, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
317
        $wBoxDescricao = $w*0.43;
318
        $xBoxDescricao = $wBoxCod + $x;
319
        $texto = "DESCRICÃO";
320
        $this->pTextBox(
321
            $xBoxDescricao,
322
            $y,
323
            $wBoxDescricao,
324
            $hLinha,
325
            $texto,
326
            $aFontCabProdutos,
327
            'T',
328
            'L',
329
            0,
330
            '',
331
            false
332
        );
333
        $wBoxQt = $w*0.08;
334
        $xBoxQt = $wBoxDescricao + $xBoxDescricao;
335
        $texto = "QT";
336
        $this->pTextBox($xBoxQt, $y, $wBoxQt, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
337
        $wBoxUn = $w*0.06;
338
        $xBoxUn = $wBoxQt + $xBoxQt;
339
        $texto = "UN";
340
        $this->pTextBox($xBoxUn, $y, $wBoxUn, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
341
        $wBoxVl = $w*0.13;
342
        $xBoxVl = $wBoxUn + $xBoxUn;
343
        $texto = "VALOR";
344
        $this->pTextBox($xBoxVl, $y, $wBoxVl, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
345
        $wBoxTotal = $w*0.13;
346
        $xBoxTotal = $wBoxVl + $xBoxVl;
347
        $texto = "TOTAL";
348
        $this->pTextBox($xBoxTotal, $y, $wBoxTotal, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false);
349
        $hBoxLinha = $this->hBoxLinha;
0 ignored issues
show
Unused Code introduced by
$hBoxLinha is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
350
        $hMaxLinha = $this->hMaxLinha;
351
        $cont = 0;
352
        $aFontProdutos = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
353
        if ($qtdItens > 0) {
354
            foreach ($this->det as $detI) {
355
                $thisItem   = $detI;
356
                $prod       = $thisItem->getElementsByTagName("prod")->item(0);
357
                $nitem      = $thisItem->getAttribute("nItem");
0 ignored issues
show
Unused Code introduced by
$nitem is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
358
                $cProd      = $this->pSimpleGetValue($prod, "cProd");
359
                $xProd      = $this->pSimpleGetValue($prod, "xProd");
360
                $qCom       = number_format($this->pSimpleGetValue($prod, "qCom"), 2, ",", ".");
361
                $uCom       = $this->pSimpleGetValue($prod, "uCom");
362
                $vUnCom     = number_format($this->pSimpleGetValue($prod, "vUnCom"), 2, ",", ".");
363
                $vProd      = number_format($this->pSimpleGetValue($prod, "vProd"), 2, ",", ".");
364
                //COLOCA PRODUTO
365
                $yBoxProd = $y + $hLinha + ($cont*$hMaxLinha);
366
                //COLOCA PRODUTO CÓDIGO
367
                $wBoxCod = $w*0.17;
368
                $texto = $cProd;
369
                $this->pTextBox($x, $yBoxProd, $wBoxCod, $hMaxLinha, $texto, $aFontProdutos, 'C', 'C', 0, '', false);
370
                //COLOCA PRODUTO DESCRIÇÃO
371
                $wBoxDescricao = $w*0.43;
372
                $xBoxDescricao = $wBoxCod + $x;
373
                $texto = $xProd;
374
                $this->pTextBox(
375
                    $xBoxDescricao,
376
                    $yBoxProd,
377
                    $wBoxDescricao,
378
                    $hMaxLinha,
379
                    $texto,
380
                    $aFontProdutos,
381
                    'C',
382
                    'L',
383
                    0,
384
                    '',
385
                    false
386
                );
387
                //COLOCA PRODUTO QUANTIDADE
388
                $wBoxQt = $w*0.08;
389
                $xBoxQt = $wBoxDescricao + $xBoxDescricao;
390
                $texto = $qCom;
391
                $this->pTextBox(
392
                    $xBoxQt,
393
                    $yBoxProd,
394
                    $wBoxQt,
395
                    $hMaxLinha,
396
                    $texto,
397
                    $aFontProdutos,
398
                    'C',
399
                    'C',
400
                    0,
401
                    '',
402
                    false
403
                );
404
                //COLOCA PRODUTO UNIDADE
405
                $wBoxUn = $w*0.06;
406
                $xBoxUn = $wBoxQt + $xBoxQt;
407
                $texto = $uCom;
408
                $this->pTextBox(
409
                    $xBoxUn,
410
                    $yBoxProd,
411
                    $wBoxUn,
412
                    $hMaxLinha,
413
                    $texto,
414
                    $aFontProdutos,
415
                    'C',
416
                    'C',
417
                    0,
418
                    '',
419
                    false
420
                );
421
                //COLOCA PRODUTO VL UNITÁRIO
422
                $wBoxVl = $w*0.13;
423
                $xBoxVl = $wBoxUn + $xBoxUn;
424
                $texto = $vUnCom;
425
                $this->pTextBox(
426
                    $xBoxVl,
427
                    $yBoxProd,
428
                    $wBoxVl,
429
                    $hMaxLinha,
430
                    $texto,
431
                    $aFontProdutos,
432
                    'C',
433
                    'R',
434
                    0,
435
                    '',
436
                    false
437
                );
438
                //COLOCA PRODUTO VL TOTAL
439
                $wBoxTotal = $w*0.13;
440
                $xBoxTotal = $wBoxVl + $xBoxVl;
441
                $texto = $vProd;
442
                $this->pTextBox(
443
                    $xBoxTotal,
444
                    $yBoxProd,
445
                    $wBoxTotal,
446
                    $hMaxLinha,
447
                    $texto,
448
                    $aFontProdutos,
449
                    'C',
450
                    'R',
451
                    0,
452
                    '',
453
                    false
454
                );
455
                
456
                $cont++;
457
            }
458
        }
459
    }
460
    
461
    protected function pTotalDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
462
    {
463
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
464
        $maxW = $this->wPrint;
465
        $hLinha = 3;
466
        $wColEsq = ($maxW*0.7);
467
        $wColDir = ($maxW*0.3);
468
        $xValor = $x + $wColEsq;
469
        $qtdItens = $this->det->length;
470
        $vProd = $this->pSimpleGetValue($this->ICMSTot, "vProd");
471
        $vNF = $this->pSimpleGetValue($this->ICMSTot, "vNF");
472
        $vDesc  = $this->pSimpleGetValue($this->ICMSTot, "vDesc");
473
        $texto = "Qtd. Total de Itens";
474
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
475
        $this->pTextBox($x, $y, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
476
        $texto = $qtdItens;
477
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
478
        $this->pTextBox($xValor, $y, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
479
        $yTotal = $y + ($hLinha);
480
        $texto = "Total de Produtos";
481
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
482
        $this->pTextBox($x, $yTotal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
483
        $texto = "R$ " . number_format($vProd, 2, ",", ".");
484
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
485
        $this->pTextBox($xValor, $yTotal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
486
        $yDesconto = $y + ($hLinha*2);
487
        $texto = "Descontos";
488
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
489
        $this->pTextBox($x, $yDesconto, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
490
        $texto = "R$ " . $vDesc;
491
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
492
        $this->pTextBox($xValor, $yDesconto, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
493
        $yTotalFinal = $y + ($hLinha*3);
494
        $texto = "Total";
495
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
496
        $this->pTextBox($x, $yTotalFinal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
497
        $texto = "R$ " . $vNF;
498
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
499
        $this->pTextBox($xValor, $yTotalFinal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
500
        $yTotalFinal = $y + ($hLinha*4);
501
        $texto = "Informação dos Tributos Totais Incidentes";
502
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'');
503
        $this->pTextBox($x, $yTotalFinal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
504
        $texto = "R$ " . $vTotTrib;
0 ignored issues
show
Bug introduced by
The variable $vTotTrib 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...
505
        $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
506
        $this->pTextBox($xValor, $yTotalFinal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false);
507
    }
508
    
509
    protected function pPagamentosDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
510
    {
511
        $y += 4;
512
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
513
        $maxW = $this->wPrint;
514
        $qtdPgto = $this->pag->length;
515
        $w = ($maxW*1);
516
        $hLinha = $this->hLinha;
517
        $wColEsq = ($maxW*0.7);
518
        $wColDir = ($maxW*0.3);
0 ignored issues
show
Unused Code introduced by
$wColDir is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
519
        $xValor = $x + $wColEsq;
0 ignored issues
show
Unused Code introduced by
$xValor is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
520
        $aFontPgto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B');
521
        $wBoxEsq = $w*0.7;
522
        $texto = "FORMA DE PAGAMENTO";
523
        $this->pTextBox($x, $y, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false);
524
        $wBoxDir = $w*0.3;
525
        $xBoxDescricao = $x + $wBoxEsq;
526
        $texto = "VALOR PAGO";
527
        $this->pTextBox($xBoxDescricao, $y, $wBoxDir, $hLinha, $texto, $aFontPgto, 'T', 'R', 0, '', false);
528
        $cont = 0;
529
        if ($qtdPgto > 0) {
530
            foreach ($this->pag as $pagI) {
531
                $tPag = $this->pSimpleGetValue($pagI, "tPag");
532
                $tPagNome = $this->tipoPag($tPag);
533
                $tPnome = $tPagNome;
0 ignored issues
show
Unused Code introduced by
$tPnome is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
534
                $vPag = number_format($this->pSimpleGetValue($pagI, "vPag"), 2, ",", ".");
535
                $card = $pagI->getElementsByTagName("card")->item(0);
536
                $cardCNPJ = '';
0 ignored issues
show
Unused Code introduced by
$cardCNPJ is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
537
                $tBand = '';
0 ignored issues
show
Unused Code introduced by
$tBand is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
538
                $tBandNome = '';
0 ignored issues
show
Unused Code introduced by
$tBandNome is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
539
                if (isset($card)) {
540
                    $cardCNPJ = $this->pSimpleGetValue($card, "CNPJ");
0 ignored issues
show
Unused Code introduced by
$cardCNPJ is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
541
                    $tBand    = $this->pSimpleGetValue($card, "tBand");
542
                    $cAut = $this->pSimpleGetValue($card, "cAut");
0 ignored issues
show
Unused Code introduced by
$cAut is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
543
                    $tBandNome = self::getCardName($tBand);
0 ignored issues
show
Unused Code introduced by
$tBandNome is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
544
                }
545
                //COLOCA PRODUTO
546
                $yBoxProd = $y + $hLinha + ($cont*$hLinha);
547
                //COLOCA PRODUTO CÓDIGO
548
                $texto = $tPagNome;
549
                $this->pTextBox($x, $yBoxProd, $wBoxEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false);
0 ignored issues
show
Bug introduced by
The variable $aFont 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...
550
                //COLOCA PRODUTO DESCRIÇÃO
551
                $xBoxDescricao = $wBoxEsq + $x;
552
                $texto = "R$ " . $vPag;
553
                $this->pTextBox(
554
                    $xBoxDescricao,
555
                    $yBoxProd,
556
                    $wBoxDir,
557
                    $hLinha,
558
                    $texto,
559
                    $aFontProdutos,
0 ignored issues
show
Bug introduced by
The variable $aFontProdutos 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...
560
                    'C',
561
                    'R',
562
                    0,
563
                    '',
564
                    false
565
                );
566
                $cont++;
567
            }
568
        }
569
    }
570
    
571
    protected function pFiscalDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
572
    {
573
        $y += 4;
574
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
575
        $maxW = $this->wPrint;
576
        $w = ($maxW*1);
577
        $hLinha = $this->hLinha;
578
        $aFontTit = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
579
        $aFontTex = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
580
        $digVal = $this->pSimpleGetValue($this->nfe, "DigestValue");
0 ignored issues
show
Unused Code introduced by
$digVal is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
581
        $chNFe = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
582
        $tpAmb = $this->pSimpleGetValue($this->ide, 'tpAmb');
583
        $cUF = $this->pSimpleGetValue($this->ide, 'cUF');
584
        $nNF = $this->pSimpleGetValue($this->ide, 'nNF');
585
        $serieNF = str_pad($this->pSimpleGetValue($this->ide, "serie"), 3, "0", STR_PAD_LEFT);
586
        $dhEmi = $this->pSimpleGetValue($this->ide, "dhEmi");
587
        $urlChave = $this->urlConsulta[$tpAmb][$cUF]['chave'];
0 ignored issues
show
Bug introduced by
The property urlConsulta 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...
588
        $texto = "ÁREA DE MENSAGEM FISCAL";
589
        $this->pTextBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false);
590
        $yTex1 = $y + ($hLinha*1);
591
        $hTex1 = $hLinha*2;
592
        $texto = "Número " . $nNF . " Série " . $serieNF . " " .$dhEmi . " - Via Consumidor";
593
        $this->pTextBox($x, $yTex1, $w, $hTex1, $texto, $aFontTex, 'C', 'C', 0, '', false);
594
        $yTex2 = $y + ($hLinha*3);
595
        $hTex2 = $hLinha*2;
596
        $texto = "Consulte pela Chave de Acesso em " . $urlChave;
597
        $this->pTextBox($x, $yTex2, $w, $hTex2, $texto, $aFontTex, 'C', 'C', 0, '', false);
598
        $texto = "CHAVE DE ACESSO";
599
        $yTit2 = $y + ($hLinha*5);
600
        $this->pTextBox($x, $yTit2, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false);
601
        $yTex3 = $y + ($hLinha*6);
602
        $texto = $chNFe;
603
        $this->pTextBox($x, $yTex3, $w, $hLinha, $texto, $aFontTex, 'C', 'C', 0, '', false);
604
    }
605
    
606
    protected function pConsumidorDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
607
    {
608
        $y += 4;
609
        $margemInterna = $this->margemInterna;
0 ignored issues
show
Unused Code introduced by
$margemInterna is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
610
        $maxW = $this->wPrint;
611
        $w = ($maxW*1);
612
        $hLinha = $this->hLinha;
613
        $aFontTit = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
614
        $aFontTex = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
615
        $texto = "CONSUMIDOR";
616
        $this->pTextBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false);
617
        if (isset($this->dest)) {
618
            $considEstrangeiro = !empty($this->dest->getElementsByTagName("idEstrangeiro")->item(0)->nodeValue)
619
                    ? $this->dest->getElementsByTagName("idEstrangeiro")->item(0)->nodeValue
620
                    : '';
621
            $consCPF = !empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue)
622
                    ? $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue
623
                    : '';
624
            $consCNPJ = !empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)
625
                    ? $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue
626
                    : '';
627
            $cDest = $consCPF.$consCNPJ.$considEstrangeiro; //documentos do consumidor
0 ignored issues
show
Unused Code introduced by
$cDest is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
628
            $enderDest = $this->dest->getElementsByTagName("enderDest")->item(0);
629
            $consNome = $this->pSimpleGetValue($this->dest, "xNome");
630
            $consLgr = $this->pSimpleGetValue($enderDest, "xLgr");
631
            $consNro = $this->pSimpleGetValue($enderDest, "nro");
632
            $consCpl = $this->pSimpleGetValue($enderDest, "xCpl", " - ");
633
            $consBairro = $this->pSimpleGetValue($enderDest, "xBairro");
634
            $consCEP = $this->pFormat($this->pSimpleGetValue($enderDest, "CEP"));
635
            $consMun = $this->pSimpleGetValue($enderDest, "xMun");
636
            $consUF = $this->pSimpleGetValue($enderDest, "UF");
637
            $considEstrangeiro = $this->pSimpleGetValue($this->dest, "idEstrangeiro");
638
            $consCPF = $this->pSimpleGetValue($this->dest, "CPF");
639
            $consCNPJ = $this->pSimpleGetValue($this->dest, "CNPJ");
640
            $consDoc = "";
641
            if (!empty($consCNPJ)) {
642
                $consDoc = "CNPJ: $consCNPJ";
643
            } elseif (!empty($consCPF)) {
644
                $consDoc = "CPF: $consCPF";
645
            } elseif (!empty($considEstrangeiro)) {
646
                $consDoc = "id: $considEstrangeiro";
647
            }
648
            $consEnd = "";
649
            if (!empty($consLgr)) {
650
                $consEnd = $consLgr 
651
                    . ","
652
                    . $consNro
653
                    . " "
654
                    . $consCpl
655
                    . ","
656
                    . $consBairro
657
                    . ". CEP:"
658
                    . $consCEP
659
                    . ". "
660
                    . $consMun
661
                    . "-"
662
                    . $consUF;
663
            }
664
            $yTex1 = $y + $hLinha;
665
            $texto = $consNome;
666
            if (!empty($consDoc)) {
667
                $texto .= " - ". $consDoc . "\n" . $consEnd;
668
                $this->pTextBox($x, $yTex1, $w, $hLinha*3, $texto, $aFontTex, 'C', 'C', 0, '', false);
669
            }    
670
        } else {
671
            $yTex1 = $y + $hLinha;
672
            $texto = "Consumidor não identificado";
673
            $this->pTextBox($x, $yTex1, $w, $hLinha, $texto, $aFontTex, 'C', 'C', 0, '', false);
674
        }
675
    }
676
    
677
    protected function pQRDANFE($x = 0, $y = 0, $h = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $h 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...
678
    {
679
        $y += 4;
680
        $margemInterna = $this->margemInterna;
681
        $maxW = $this->wPrint;
682
        $w = ($maxW*1);
683
        $hLinha = $this->hLinha;
0 ignored issues
show
Unused Code introduced by
$hLinha is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
684
        $hBoxLinha = $this->hBoxLinha;
685
        $aFontTit = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B');
0 ignored issues
show
Unused Code introduced by
$aFontTit is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
686
        $aFontTex = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'');
687
        $dhRecbto = '';
688
        $nProt = '';
689
        if (isset($this->nfeProc)) {
690
            $nProt = $this->pSimpleGetValue($this->nfeProc, "nProt");
691
            $dhRecbto  = $this->pSimpleGetValue($this->nfeProc, "dhRecbto");
692
        }
693
        $qrcode = new QRcode($this->qrCode, 'M');
0 ignored issues
show
Unused Code introduced by
The call to QrCode::__construct() has too many arguments starting with 'M'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
694
        $wQr = 50;
695
        $hQr = 50;
696
        $yQr = ($y+$margemInterna);
697
        $xQr = ($w/2) - ($wQr/2);
698
        // prepare a base64 encoded "data url"
699
        $pic = 'data://text/plain;base64,' . base64_encode($qrcode->writeString());
700
        $info = getimagesize($pic);
0 ignored issues
show
Unused Code introduced by
$info is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
701
        $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG');
702
        $dt = new DateTime($dhRecbto);
703
        $yQr = ($yQr+$hQr+$margemInterna);
704
        $this->pTextBox($x, $yQr, $w, $hBoxLinha, "Protocolo de Autorização: " . $nProt . "\n"
705
            . $dt->format('d/m/Y H:i:s'), $aFontTex, 'C', 'C', 0, '', false);
706
    }
707
   
708
    /**
709
     * printDANFE
710
     * Esta função envia a DANFE em PDF criada para o dispositivo informado.
711
     * O destino da impressão pode ser :
712
     * I-browser
713
     * D-browser com download
714
     * F-salva em um arquivo local com o nome informado
715
     * S-retorna o documento como uma string e o nome é ignorado.
716
     * Para enviar o pdf diretamente para uma impressora indique o
717
     * nome da impressora e o destino deve ser 'S'.
718
     *
719
     * @param  string $nome    Path completo com o nome do arquivo pdf
720
     * @param  string $destino Direção do envio do PDF
721
     * @param  string $printer Identificação da impressora no sistema
722
     * @return string Caso o destino seja S o pdf é retornado como uma string
723
     * @todo   Rotina de impressão direta do arquivo pdf criado
724
     */
725 View Code Duplication
    public function printDANFE($nome = '', $destino = 'I', $printer = '')
0 ignored issues
show
Unused Code introduced by
The parameter $printer 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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
726
    {
727
        $arq = $this->pdf->Output($nome, $destino);
728
        if ($destino == 'S') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
729
            //aqui pode entrar a rotina de impressão direta
730
        }
731
        return $arq;
732
    }
733
    
734
    /**
735
     * str2Hex
736
     * Converte string para haxadecimal ASCII
737
     *
738
     * @param  string $str
739
     * @return string
740
     */
741
    protected static function str2Hex($str)
742
    {
743
        if ($str == '') {
744
            return '';
745
        }
746
        $hex = "";
747
        $iCount = 0;
748
        do {
749
            $hex .= sprintf("%02x", ord($str{$iCount}));
750
            $iCount++;
751
        } while ($iCount < strlen($str));
752
        return $hex;
753
    }//fim str2Hex
754
    
755
    protected static function getCardName($tBand)
756
    {
757
        switch ($tBand) {
758
            case '01':
759
                $tBandNome = 'VISA';
760
                break;
761
            case '02':
762
                $tBandNome = 'MASTERCARD';
763
                break;
764
            case '03':
765
                $tBandNome = 'AMERICAM EXPRESS';
766
                break;
767
            case '04':
768
                $tBandNome = 'SOROCRED';
769
                break;
770
            case '99':
771
                $tBandNome = 'OUTROS';
772
        }
773
        return $tBandNome;
0 ignored issues
show
Bug introduced by
The variable $tBandNome does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
774
    }
775
    
776
    protected function tipoPag($tPag)
777
    {
778
        switch ($tPag) {
779
            case '01':
780
                $tPagNome = 'Dinheiro';
781
                break;
782
            case '02':
783
                $tPagNome = 'Cheque';
784
                break;
785
            case '03':
786
                $tPagNome = 'Cartão de Crédito';
787
                break;
788
            case '04':
789
                $tPagNome = 'Cartão de Débito';
790
                break;
791
            case '05':
792
                $tPagNome = 'Crédito Loja';
793
                break;
794
            case '10':
795
                $tPagNome = 'Vale Alimentação';
796
                break;
797
            case '11':
798
                $tPagNome = 'Vale Refeição';
799
                break;
800
            case '12':
801
                $tPagNome = 'Vale Presente';
802
                break;
803
            case '13':
804
                $tPagNome = 'Vale Combustível';
805
                break;
806
            case '99':
807
                $tPagNome = 'Outros';
808
        }
809
        return $tPagNome;
0 ignored issues
show
Bug introduced by
The variable $tPagNome does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
810
    }
811
    
812
    /**
813
     * hex2Str
814
     * Converte hexadecimal ASCII para string
815
     *
816
     * @param  string $str
817
     * @return string
818
     */
819
    protected static function hex2Str($str)
820
    {
821
        if ($str == '') {
822
            return '';
823
        }
824
        $bin = "";
825
        $iCount = 0;
826
        do {
827
            $bin .= chr(hexdec($str{$iCount}.$str{($iCount + 1)}));
828
            $iCount += 2;
829
        } while ($iCount < strlen($str));
830
        return $bin;
831
    }
832
    
833
    protected function makeQRCode(
834
        $chNFe,
835
        $url,
836
        $tpAmb,
837
        $cDest = '',
838
        $dhEmi = '',
839
        $vNF = '',
840
        $vICMS = '',
841
        $digVal = '',
842
        $idToken = '000001',
843
        $token = ''
844
    ) {
845
        $nVersao = '100';
846
        $dhHex = self::str2Hex($dhEmi);
847
        $digHex = self::str2Hex($digVal);
848
        $seq = '';
849
        $seq .= 'chNFe=' . $chNFe;
850
        $seq .= '&nVersao=' . $nVersao;
851
        $seq .= '&tpAmb=' . $tpAmb;
852
        if ($cDest != '') {
853
            $seq .= '&cDest=' . $cDest;
854
        }
855
        $seq .= '&dhEmi=' . strtolower($dhHex);
856
        $seq .= '&vNF=' . $vNF;
857
        $seq .= '&vICMS=' . $vICMS;
858
        $seq .= '&digVal=' . strtolower($digHex);
859
        $seq .= '&cIdToken=' . $idToken;
860
        //o hash code é calculado com o Token incluso
861
        $hash = sha1($seq.$token);
862
        $seq .= '&cHashQRCode='. strtoupper($hash);
863
        if (strpos($url, '?') === false) {
864
            $seq = $url.'?'.$seq;
865
        } else {
866
            $seq = $url.''.$seq;
867
        }
868
        return $seq;
869
    }
870
}
871