Passed
Push — master ( 65876e...b72b80 )
by Roberto
03:58
created

EvtTabEquipamento::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtTabEquipamento Event S-1065 constructor
7
 * READ for 2.4.2 layout
8
 *
9
 * @category  library
10
 * @package   NFePHP\eSocial
11
 * @copyright NFePHP Copyright (c) 2017
12
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
13
 * @license   https://opensource.org/licenses/MIT MIT
14
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
15
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
16
 * @link      http://github.com/nfephp-org/sped-esocial for the canonical source repository
17
 */
18
19
use NFePHP\Common\Certificate;
20
use NFePHP\eSocial\Common\Factory;
21
use NFePHP\eSocial\Common\FactoryId;
22
use NFePHP\eSocial\Common\FactoryInterface;
23
use stdClass;
24
25
class EvtTabEquipamento extends Factory implements FactoryInterface
26
{
27
    /**
28
     * @var int
29
     */
30
    public $sequencial;
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtTabEquipamento';
35
    /**
36
     * @var string
37
     */
38
    protected $evtAlias = 'S-1065';
39
40
    /**
41
     * Constructor
42
     * @param string $config
43
     * @param stdClass $std
44
     * @param Certificate $certificate
45
     */
46
    public function __construct(
47
        $config,
48
        stdClass $std,
49
        Certificate $certificate
50
    ) {
51
        parent::__construct($config, $std, $certificate);
52
    }
53
54
    /**
55
     * Node constructor
56
     */
57
    protected function toNode()
58
    {
59
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
60
        //o idEvento pode variar de evento para evento
61
        //então cada factory individualmente terá de construir o seu
62
        $ideEvento = $this->dom->createElement("ideEvento");
63
        $this->dom->addChild(
64
            $ideEvento,
65
            "tpAmb",
66
            $this->tpAmb,
67
            true
68
        );
69
        $this->dom->addChild(
70
            $ideEvento,
71
            "procEmi",
72
            $this->procEmi,
73
            true
74
        );
75
        $this->dom->addChild(
76
            $ideEvento,
77
            "verProc",
78
            $this->verProc,
79
            true
80
        );
81
        $this->node->insertBefore($ideEvento, $ideEmpregador);
82
        
83
        $ide = $this->dom->createElement("ideEquipamento");
84
        $this->dom->addChild(
85
            $ide,
86
            "codEP",
87
            $this->std->codep,
88
            true
89
        );
90
        $this->dom->addChild(
91
            $ide,
92
            "iniValid",
93
            $this->std->inivalid,
94
            false
95
        );
96
        $this->dom->addChild(
97
            $ide,
98
            "fimValid",
99
            ! empty($this->std->fimvalid) ? $this->std->fimvalid : null,
100
            false
101
        );
102
        
103
        $dados = null;
104
        if (!empty($this->std->tpep)) {
105
            $dados = $this->dom->createElement("dadosEquipamento");
106
            $this->dom->addChild(
107
                $dados,
108
                "tpEP",
109
                $this->std->tpep,
110
                true
111
            );
112
            $this->dom->addChild(
113
                $dados,
114
                "dscEP",
115
                $this->std->dscep,
116
                true
117
            );
118
            $this->dom->addChild(
119
                $dados,
120
                "caEPI",
121
                $this->std->caepi,
122
                false
123
            );
124
        }
125
        
126
        $nova = null;
127
        if (!empty($this->std->novavalidade)) {
128
            $nova = $this->dom->createElement("novaValidade");
129
            $this->dom->addChild(
130
                $nova,
131
                "iniValid",
132
                $this->std->novavalidade->inivalid,
133
                true
134
            );
135
            $this->dom->addChild(
136
                $nova,
137
                "fimValid",
138
                ! empty($this->std->novavalidade->fimvalid)
139
                    ? $this->std->novavalidade->fimvalid
140
                    : null,
141
                false
142
            );
143
        }
144
        
145
        $info = $this->dom->createElement("infoEquipamento");
146
        //seleção do modo
147
        if ($this->std->modo == 'INC') {
148
            $node = $this->dom->createElement("inclusao");
149
            $node->appendChild($ide);
150
            if (!empty($dados)) {
151
                $node->appendChild($dados);
152
            }
153
        } elseif ($this->std->modo == 'ALT') {
154
            $node = $this->dom->createElement("alteracao");
155
            $node->appendChild($ide);
156
            if (!empty($dados)) {
157
                $node->appendChild($dados);
158
            }
159
            if (!empty($nova)) {
160
                $node->appendChild($nova);
161
            }
162
        } else {
163
            $node = $this->dom->createElement("exclusao");
164
            $node->appendChild($ide);
165
        }
166
        $info->appendChild($node);
167
        $this->node->appendChild($info);
168
        $this->eSocial->appendChild($this->node);
169
        $this->xml = $this->dom->saveXML($this->eSocial);
170
        //$this->sign();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
171
    }
172
}
173