Completed
Push — master ( 03ed34...af80fe )
by Roberto
06:02 queued 02:43
created

EvtMonit::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
crap 2
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtMonit Event S-2220 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 EvtMonit extends Factory implements FactoryInterface
26
{
27
    /**
28
     * @var int
29
     */
30
    public $sequencial;
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtMonit';
35
    /**
36
     * @var string
37
     */
38
    protected $evtAlias = 'S-2220';
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
            "indRetif",
66
            $this->std->indretif,
67
            true
68
        );
69
        $this->dom->addChild(
70
            $ideEvento,
71
            "tpAmb",
72
            $this->tpAmb,
73
            true
74
        );
75
        $this->dom->addChild(
76
            $ideEvento,
77
            "procEmi",
78
            $this->procEmi,
79
            true
80
        );
81
        $this->dom->addChild(
82
            $ideEvento,
83
            "verProc",
84
            $this->verProc,
85
            true
86
        );
87
        $this->node->insertBefore($ideEvento, $ideEmpregador);
88
        $ideVinculo = $this->dom->createElement("ideVinculo");
89
        $this->dom->addChild(
90
            $ideVinculo,
91
            "cpfTrab",
92
            $this->std->idevinculo->cpftrab,
93
            true
94
        );
95
        $this->dom->addChild(
96
            $ideVinculo,
97
            "nisTrab",
98
            $this->std->idevinculo->nistrab,
99
            true
100
        );
101
        $this->dom->addChild(
102
            $ideVinculo,
103
            "matricula",
104
            $this->std->idevinculo->matricula,
105
            true
106
        );
107
        $this->node->appendChild($ideVinculo);
108
        $aso = $this->dom->createElement("aso");
109
        $this->dom->addChild(
110
            $aso,
111
            "dtAso",
112
            $this->std->aso->dtaso,
113
            true
114
        );
115
        $this->dom->addChild(
116
            $aso,
117
            "tpAso",
118
            $this->std->aso->tpaso,
119
            true
120
        );
121
        $this->dom->addChild(
122
            $aso,
123
            "resAso",
124
            $this->std->aso->resaso,
125
            true
126
        );
127
        if (isset($this->std->aso->exame)) {
128
            foreach ($this->std->aso->exame as $exa) {
129
                $exame = $this->dom->createElement("exame");
130
                $this->dom->addChild(
131
                    $exame,
132
                    "dtExm",
133
                    $exa->dtexm,
134
                    true
135
                );
136
                $this->dom->addChild(
137
                    $exame,
138
                    "procRealizado",
139
                    !empty($exa->procrealizado) ? $exa->procrealizado : null,
140
                    false
141
                );
142
                $this->dom->addChild(
143
                    $exame,
144
                    "obsProc",
145
                    !empty($exa->obsproc) ? $exa->obsproc : null,
146
                    false
147
                );
148
                $this->dom->addChild(
149
                    $exame,
150
                    "interprExm",
151
                    $exa->interprexm,
152
                    true
153
                );
154
                $this->dom->addChild(
155
                    $exame,
156
                    "ordExame",
157
                    $exa->ordexame,
158
                    true
159
                );
160
                $this->dom->addChild(
161
                    $exame,
162
                    "dtIniMonit",
163
                    $exa->dtinimonit,
164
                    true
165
                );
166
                $this->dom->addChild(
167
                    $exame,
168
                    "dtFimMonit",
169
                    !empty($exa->dtfimmonit) ? $exa->dtfimmonit : null,
170
                    false
171
                );
172
                $this->dom->addChild(
173
                    $exame,
174
                    "indResult",
175
                    !empty($exa->indresult) ? $exa->indresult : null,
176
                    false
177
                );
178
                $respMonit = $this->dom->createElement("respMonit");
179
                $resm = $exa->respmonit;
180
                $this->dom->addChild(
181
                    $respMonit,
182
                    "nisResp",
183
                    $resm->nisresp,
184
                    true
185
                );
186
                $this->dom->addChild(
187
                    $respMonit,
188
                    "nrConsClasse",
189
                    $resm->nrconsclasse,
190
                    true
191
                );
192
                $this->dom->addChild(
193
                    $respMonit,
194
                    "ufConsClasse",
195
                    !empty($resm->ufconsclasse) ? $resm->ufconsclasse : null,
196
                    false
197
                );
198
                $exame->appendChild($respMonit);
199
                $aso->appendChild($exame);
200
            }
201
        }
202
        $ideServSaude = $this->dom->createElement("ideServSaude");
203
        $sers = $this->std->aso->ideservsaude;
204
        $this->dom->addChild(
205
            $ideServSaude,
206
            "codCNES",
207
            !empty($sers->codcnes) ? $sers->codcnes : null,
208
            false
209
        );
210
        $this->dom->addChild(
211
            $ideServSaude,
212
            "frmCtt",
213
            $sers->frmctt,
214
            true
215
        );
216
        $this->dom->addChild(
217
            $ideServSaude,
218
            "email",
219
            !empty($sers->email) ? $sers->email : null,
220
            false
221
        );
222
        $medico = $this->dom->createElement("medico");
223
        $med = $sers->medico;
224
        $this->dom->addChild(
225
            $medico,
226
            "nmMed",
227
            $med->nmmed,
228
            true
229
        );
230
        $crm = $this->dom->createElement("crm");
231
        $this->dom->addChild(
232
            $crm,
233
            "nrCRM",
234
            $med->nrcrm,
235
            true
236
        );
237
        $this->dom->addChild(
238
            $crm,
239
            "ufCRM",
240
            $med->ufcrm,
241
            true
242
        );
243
        $medico->appendChild($crm);
244
        $ideServSaude->appendChild($medico);
245
        $aso->appendChild($ideServSaude);
246
        $this->node->appendChild($aso);
247
        //finalização do xml
248
        $this->eSocial->appendChild($this->node);
249
        //$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...
250
        $this->sign();
251
    }
252
}
253