Passed
Push — master ( adf353...32c19c )
by Luiz Kim
01:27
created

NFePHP::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
namespace ControleOnline\Library;
4
5
use ControleOnline\Entity\Order;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\Order was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use ControleOnline\Entity\Product;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\Product was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Symfony\Component\Security\Core\Security;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Security\Core\Security was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
use NFePHP\NFe\Tools;
0 ignored issues
show
Bug introduced by
The type NFePHP\NFe\Tools was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use NFePHP\NFe\Make;
0 ignored issues
show
Bug introduced by
The type NFePHP\NFe\Make was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use NFePHP\Common\Certificate;
0 ignored issues
show
Bug introduced by
The type NFePHP\Common\Certificate was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
class NFePHP
15
{
16
    /**
17
     * @var  Make $make
18
     */
19
    protected $make;
20
    protected $model;
21
    protected $version;
22
23
    public function __construct(
24
        protected EntityManagerInterface $manager,
25
        protected Security $security,
26
    ) {
27
        $this->make = new Make();
28
    }
29
30
    //ide OBRIGATÓRIA
31
    protected function makeIde(Order $order)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

31
    protected function makeIde(/** @scrutinizer ignore-unused */ Order $order)

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

Loading history...
32
    {
33
34
        $std = new \stdClass();
35
        $std->cUF = 14;
36
        $std->cNF = '03701267';
37
        $std->natOp = 'VENDA CONSUMIDOR';
38
        $std->mod = 65;
39
        $std->serie = 1;
40
        $std->nNF = 100;
41
        $std->dhEmi = (new \DateTime())->format('Y-m-d\TH:i:sP');
42
        $std->dhSaiEnt = null;
43
        $std->tpNF = 1;
44
        $std->idDest = 1;
45
        $std->cMunFG = 1400100;
46
        $std->tpImp = 1;
47
        $std->tpEmis = 1;
48
        $std->cDV = 2;
49
        $std->tpAmb = 2;
50
        $std->finNFe = 1;
51
        $std->indFinal = 1;
52
        $std->indPres = 1;
53
        $std->procEmi = 3;
54
        $std->verProc = '4.13';
55
        $std->dhCont = null;
56
        $std->xJust = null;
57
        $this->make->tagIde($std);
58
    }
59
60
    //emit OBRIGATÓRIA
61
    protected function makeEmit(Order $order)
62
    {
63
64
        $std = new \stdClass();
65
        $std->xNome = 'SUA RAZAO SOCIAL LTDA';
66
        $std->xFant = 'RAZAO';
67
        $std->IE = '111111111';
68
        $std->IEST = null;
69
        //$std->IM = '95095870';
70
        $std->CNAE = '4642701';
71
        $std->CRT = 1;
72
        $std->CNPJ = '99999999999999';
73
        //$std->CPF = '12345678901'; //NÃO PASSE TAGS QUE NÃO EXISTEM NO CASO
74
        $this->make->tagemit($std);
75
76
        //enderEmit OBRIGATÓRIA
77
        $this->makeEmitAddress($order);
78
    }
79
80
    protected function makeEmitAddress(Order $order)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

80
    protected function makeEmitAddress(/** @scrutinizer ignore-unused */ Order $order)

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

Loading history...
81
    {
82
        $std = new \stdClass();
83
        $std->xLgr = 'Avenida Getúlio Vargas';
84
        $std->nro = '5022';
85
        $std->xCpl = 'LOJA 42';
86
        $std->xBairro = 'CENTRO';
87
        $std->cMun = 1400100;
88
        $std->xMun = 'BOA VISTA';
89
        $std->UF = 'RR';
90
        $std->CEP = '69301030';
91
        $std->cPais = 1058;
92
        $std->xPais = 'Brasil';
93
        $std->fone = '55555555';
94
        $this->make->tagenderemit($std);
95
    }
96
    //dest OPCIONAL
97
    protected function makeDest(Order $order)
98
    {
99
        $std = new \stdClass();
100
        $std->xNome = 'Eu Ltda';
101
        $std->CNPJ = '01234123456789';
102
        //$std->CPF = '12345678901';
103
        //$std->idEstrangeiro = 'AB1234';
104
        $std->indIEDest = 9;
105
        //$std->IE = '';
106
        //$std->ISUF = '12345679';
107
        //$std->IM = 'XYZ6543212';
108
        $std->email = '[email protected]';
109
        $dest = $this->make->tagdest($std);
0 ignored issues
show
Unused Code introduced by
The assignment to $dest is dead and can be removed.
Loading history...
110
111
112
        $this->makeDestAddress($order);
113
    }
114
    //enderDest OPCIONAL
115
    protected function makeDestAddress(Order $order)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

115
    protected function makeDestAddress(/** @scrutinizer ignore-unused */ Order $order)

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

Loading history...
116
    {
117
118
        $std = new \stdClass();
119
        $std->xLgr = 'Avenida Sebastião Diniz';
120
        $std->nro = '458';
121
        $std->xCpl = null;
122
        $std->xBairro = 'CENTRO';
123
        $std->cMun = 1400100;
124
        $std->xMun = 'Boa Vista';
125
        $std->UF = 'RR';
126
        $std->CEP = '69301088';
127
        $std->cPais = 1058;
128
        $std->xPais = 'Brasil';
129
        $std->fone = '1111111111';
130
        $this->make->tagenderdest($std);
131
    }
132
133
    protected function makeProds(Order $order)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

133
    protected function makeProds(/** @scrutinizer ignore-unused */ Order $order)

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

Loading history...
134
    {
135
        $products  = [];
136
        $item = 1;
137
        foreach ($products as $product) {
138
139
            //prod OBRIGATÓRIA
140
            $std = new \stdClass();
141
            $std->item = $item;
142
            $std->cProd = '00341';
143
            $std->cEAN = 'SEM GTIN';
144
            $std->cEANTrib = 'SEM GTIN';
145
            $std->xProd = 'Produto com serviço';
146
            $std->NCM = '96081000';
147
            $std->CFOP = '5933';
148
            $std->uCom = 'JG';
149
            $std->uTrib = 'JG';
150
            $std->cBarra = NULL;
151
            $std->cBarraTrib = NULL;
152
            $std->qCom = '1';
153
            $std->qTrib = '1';
154
            $std->vUnCom = '200';
155
            $std->vUnTrib = '200';
156
            $std->vProd = '200';
157
            $std->vDesc = NULL;
158
            $std->vOutro = NULL;
159
            $std->vSeg = NULL;
160
            $std->vFrete = NULL;
161
            $std->cBenef = NULL;
162
            $std->xPed = NULL;
163
            $std->nItemPed = NULL;
164
            $std->indTot = 1;
165
            $this->make->tagprod($std);
166
            $this->makeImpostos($product, $item);
167
        }
168
    }
169
    protected function makeImpostos(Product $product, $item)
170
    {
171
        $this->makePIS($product, $item);
172
        $this->makeCOFINS($product, $item);
173
        $this->makeISSQN($product, $item);
174
175
        //Imposto
176
        $std = new \stdClass();
177
        $std->item = $item; //item da NFe
178
        $std->vTotTrib = 0;
179
        $this->make->tagimposto($std);
180
181
182
183
        $std = new \stdClass();
184
        $this->make->tagICMSTot($std);
185
186
        $std = new \stdClass();
187
        $std->dCompet = '2010-09-12';
188
        $std->cRegTrib = 6;
189
        $this->make->tagISSQNTot($std);
190
        $this->make->tagISSQNTot($std);
191
    }
192
193
    protected function makeInfNFe($version)
194
    {
195
        //infNFe OBRIGATÓRIA
196
        $std = new \stdClass();
197
        $std->Id = '';
198
        $std->versao =  $version;
199
        $this->make->taginfNFe($std);
200
    }
201
202
    protected function makeISSQN(Product $product, $item)
0 ignored issues
show
Unused Code introduced by
The parameter $product is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

202
    protected function makeISSQN(/** @scrutinizer ignore-unused */ Product $product, $item)

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

Loading history...
203
    {
204
        // Monta a tag de impostos mas não adiciona no xml
205
        $std = new \stdClass();
206
        $std->item = $item; //item da NFe
207
        $std->vBC = 2.0;
208
        $std->vAliq = 8.0;
209
        $std->vISSQN = 0.16;
210
        $std->cMunFG = 1300029;
211
        $std->cMun = 1300029;
212
        $std->cPais = '1058';
213
        $std->cListServ = '01.01';
214
        $std->indISS = 1;
215
        $std->indIncentivo = 2;
216
        // Adiciona a tag de imposto ISSQN no xml
217
        $this->make->tagISSQN($std);
218
    }
219
220
    protected function makePIS(Product $product, $item)
0 ignored issues
show
Unused Code introduced by
The parameter $product is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

220
    protected function makePIS(/** @scrutinizer ignore-unused */ Product $product, $item)

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

Loading history...
221
    {
222
        //PIS
223
        $std = new \stdClass();
224
        $std->item = $item; //item da NFe
225
        $std->CST = '99';
226
        $std->vBC = 200;
227
        $std->pPIS = 0.65;
228
        $std->vPIS = 13;
229
        $this->make->tagPIS($std);
230
    }
231
    protected function makeCOFINS(Product $product, $item)
0 ignored issues
show
Unused Code introduced by
The parameter $product is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

231
    protected function makeCOFINS(/** @scrutinizer ignore-unused */ Product $product, $item)

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

Loading history...
232
    {
233
        //COFINS
234
        $std = new \stdClass();
235
        $std->item = $item; //item da NFe
236
        $std->CST = '99';
237
        $std->vBC = 200;
238
        $std->pCOFINS = 3;
239
        $std->vCOFINS = 60;
240
        $this->make->tagCOFINS($std);
241
    }
242
243
    protected function sign(Order $order)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

243
    protected function sign(/** @scrutinizer ignore-unused */ Order $order)

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

Loading history...
244
    {
245
        $arr = [
246
            "atualizacao" => "2017-02-20 09:11:21",
247
            "tpAmb"       => 2,
248
            "razaosocial" => "SUA RAZAO SOCIAL LTDA",
249
            "cnpj"        => "99999999999999",
250
            "siglaUF"     => "SP",
251
            "schemes"     => "PL_009_V4",
252
            "versao"      => '4.00',
253
            "tokenIBPT"   => "AAAAAAA",
254
            "CSC"         => "GPB0JBWLUR6HWFTVEAS6RJ69GPCROFPBBB8G",
255
            "CSCid"       => "000001",
256
            "proxyConf"   => [
257
                "proxyIp"   => "",
258
                "proxyPort" => "",
259
                "proxyUser" => "",
260
                "proxyPass" => ""
261
            ]
262
        ];
263
        $configJson = json_encode($arr);
264
        $pfxcontent = file_get_contents('fixtures/expired_certificate.pfx');
265
266
        $tools = new Tools($configJson, Certificate::readPfx($pfxcontent, 'associacao'));
267
        $tools->model($this->model);
268
        //$tools->disableCertValidation(true); //tem que desabilitar
269
        return   $tools->signNFe($this->make->getXML());
270
    }
271
272
273
    protected function makeTransp(Order $order)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

273
    protected function makeTransp(/** @scrutinizer ignore-unused */ Order $order)

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

Loading history...
274
    {
275
        //transp OBRIGATÓRIA
276
        $std = new \stdClass();
277
        $this->make->tagtransp($std);
278
    }
279
280
281
    protected function makePag(Order $order)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

281
    protected function makePag(/** @scrutinizer ignore-unused */ Order $order)

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

Loading history...
282
    {
283
        //pag OBRIGATÓRIA
284
        $std = new \stdClass();
285
        $std->vTroco = 0;
286
        $this->make->tagpag($std);
287
    }
288
289
290
    protected function makedetPag(Order $order)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

290
    protected function makedetPag(/** @scrutinizer ignore-unused */ Order $order)

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

Loading history...
291
    {
292
        //detPag OBRIGATÓRIA
293
        $std = new \stdClass();
294
        $std->indPag = '0';
295
        $std->xPag = NULL;
296
        $std->tPag = '01';
297
        $std->vPag = 2.01;
298
        $this->make->tagdetpag($std);
299
    }
300
    protected function makeInfRespTec()
301
    {
302
303
        $std = new \stdClass();
304
        $std->CNPJ = '99999999999999'; //CNPJ da pessoa jurídica responsável pelo sistema utilizado na emissão do documento fiscal eletrônico
305
        $std->xContato = 'Fulano de Tal'; //Nome da pessoa a ser contatada
306
        $std->email = '[email protected]'; //E-mail da pessoa jurídica a ser contatada
307
        $std->fone = '1155551122'; //Telefone da pessoa jurídica/física a ser contatada
308
        //$std->CSRT = 'G8063VRTNDMO886SFNK5LDUDEI24XJ22YIPO'; //Código de Segurança do Responsável Técnico
309
        //$std->idCSRT = '01'; //Identificador do CSRT
310
        $this->make->taginfRespTec($std);
311
    }
312
}
313