Completed
Push — master ( 0f6c35...16dc49 )
by Roberto
06:14 queued 03:03
created

EvtTreiCap   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 195
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 195
ccs 0
cts 156
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
C toNode() 0 153 8
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtTreiCap Event S-2245 constructor
7
 * Read for 2.5.0 layout
8
 *
9
 *
10
 * @category  library
11
 * @package   NFePHP\eSocial
12
 * @copyright NFePHP Copyright (c) 2018
13
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
14
 * @license   https://opensource.org/licenses/MIT MIT
15
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
16
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
17
 * @link      http://github.com/nfephp-org/sped-esocial for the canonical source repository
18
 */
19
20
use NFePHP\Common\Certificate;
21
use NFePHP\eSocial\Common\Factory;
22
use NFePHP\eSocial\Common\FactoryId;
23
use NFePHP\eSocial\Common\FactoryInterface;
24
use stdClass;
25
26
class EvtTreiCap extends Factory implements FactoryInterface
27
{
28
    /**
29
     * @var int
30
     */
31
    public $sequencial;
32
    /**
33
     * @var string
34
     */
35
    protected $evtName = 'evtTreiCap';
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-2245';
40
    /**
41
     * Parameters patterns
42
     *
43
     * @var array
44
     */
45
    protected $parameters = [];
46
47
    /**
48
     * Constructor
49
     *
50
     * @param string $config
51
     * @param stdClass $std
52
     * @param Certificate $certificate | null
53
     * @param string $date
54
     */
55
    public function __construct(
56
        $config,
57
        stdClass $std,
58
        Certificate $certificate = null,
59
        $date = ''
60
    ) {
61
        parent::__construct($config, $std, $certificate, $date);
62
    }
63
64
    /**
65
     * Node constructor
66
     */
67
    protected function toNode()
68
    {
69
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
70
        //o idEvento pode variar de evento para evento
71
        //então cada factory individualmente terá de construir o seu
72
        $ideEvento = $this->dom->createElement("ideEvento");
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "indRetif",
76
            $this->std->indretif,
77
            true
78
        );
79
        $this->dom->addChild(
80
            $ideEvento,
81
            "nrRecibo",
82
            $this->std->nrrecibo,
83
            true
84
        );
85
        $this->dom->addChild(
86
            $ideEvento,
87
            "tpAmb",
88
            $this->tpAmb,
89
            true
90
        );
91
        $this->dom->addChild(
92
            $ideEvento,
93
            "procEmi",
94
            $this->procEmi,
95
            true
96
        );
97
        $this->dom->addChild(
98
            $ideEvento,
99
            "verProc",
100
            $this->verProc,
101
            true
102
        );
103
        $this->node->insertBefore($ideEvento, $ideEmpregador);
104
        $ideVinculo = $this->dom->createElement("ideVinculo");
105
        $this->dom->addChild(
106
            $ideVinculo,
107
            "cpfTrab",
108
            $this->std->idevinculo->cpftrab,
109
            true
110
        );
111
        $this->dom->addChild(
112
            $ideVinculo,
113
            "nisTrab",
114
            !empty($this->std->idevinculo->nistrab) ? $this->std->idevinculo->nistrab : null,
115
            false
116
        );
117
        $this->dom->addChild(
118
            $ideVinculo,
119
            "matricula",
120
            !empty($this->std->idevinculo->matricula) ? $this->std->idevinculo->matricula : null,
121
            false
122
        );
123
        $this->dom->addChild(
124
            $ideVinculo,
125
            "codCateg",
126
            !empty($this->std->idevinculo->codcateg) ? $this->std->idevinculo->codcateg : null,
127
            false
128
        );
129
        $this->node->appendChild($ideVinculo);
130
        
131
        $t = $this->std->treicap;
132
        $treiCap = $this->dom->createElement("treiCap");
133
        $this->dom->addChild(
134
            $treiCap,
135
            "codTreiCap",
136
            $t->codtreicap,
137
            true
138
        );
139
        $this->dom->addChild(
140
            $treiCap,
141
            "obsTreiCap",
142
            !empty($t->obstreicap) ? $t->obstreicap : null,
143
            false
144
        );
145
        if (!empty($t->infocomplem)) {
146
            $i = $t->infocomplem;
147
            $infoComplem = $this->dom->createElement("infoComplem");
148
            $this->dom->addChild(
149
                $infoComplem,
150
                "dtTreiCap",
151
                $i->dttreicap,
152
                true
153
            );
154
            $this->dom->addChild(
155
                $infoComplem,
156
                "durTreiCap",
157
                $i->durtreicap,
158
                true
159
            );
160
            $this->dom->addChild(
161
                $infoComplem,
162
                "modTreiCap",
163
                $i->modtreicap,
164
                true
165
            );
166
            $this->dom->addChild(
167
                $infoComplem,
168
                "tpTreiCap",
169
                $i->tptreicap,
170
                true
171
            );
172
            
173
            foreach ($i->ideprofresp as $p) {
174
                $ideProfResp = $this->dom->createElement("ideProfResp");
175
                $this->dom->addChild(
176
                    $ideProfResp,
177
                    "cpfProf",
178
                    !empty($p->cpfprof) ? $p->cpfprof : null,
179
                    false
180
                );
181
                $this->dom->addChild(
182
                    $ideProfResp,
183
                    "nmProf",
184
                    $p->nmprof,
185
                    true
186
                );
187
                $this->dom->addChild(
188
                    $ideProfResp,
189
                    "tpProf",
190
                    $p->tpprof,
191
                    true
192
                );
193
                $this->dom->addChild(
194
                    $ideProfResp,
195
                    "formProf",
196
                    $p->formprof,
197
                    true
198
                );
199
                $this->dom->addChild(
200
                    $ideProfResp,
201
                    "codCBO",
202
                    $p->codcbo,
203
                    true
204
                );
205
                $this->dom->addChild(
206
                    $ideProfResp,
207
                    "nacProf",
208
                    $p->nacprof,
209
                    true
210
                );
211
                $infoComplem->appendChild($ideProfResp);
212
            }
213
            $treiCap->appendChild($infoComplem);
214
        }
215
        $this->node->appendChild($treiCap);
216
        $this->eSocial->appendChild($this->node);
217
        //$this->xml = $this->dom->saveXML($this->eSocial);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
218
        $this->sign();
219
    }
220
}
221