Passed
Push — master ( b85394...28dc46 )
by Roberto
02:23
created

EvtCPRB::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 4
crap 2
1
<?php
2
3
namespace NFePHP\EFDReinf\Factories;
4
5
/**
6
 * Class EFD-Reinf EvtCPRB Event R-2060 constructor
7
 *
8
 * @category  API
9
 * @package   NFePHP\EFDReinf
10
 * @copyright NFePHP Copyright (c) 2017
11
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
12
 * @license   https://opensource.org/licenses/MIT MIT
13
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
14
 * @author    Roberto L. Machado <linux.rlm at gmail dot com>
15
 * @link      http://github.com/nfephp-org/sped-efdreinf for the canonical source repository
16
 */
17
18
use NFePHP\EFDReinf\Common\Factory;
19
use NFePHP\EFDReinf\Common\FactoryInterface;
20
use NFePHP\EFDReinf\Common\FactoryId;
21
use NFePHP\Common\Certificate;
22
use stdClass;
23
24
class EvtCPRB extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var string
28
     * NOTA: refere-se ao nome do XSD e ao namespace
29
     */
30
    protected $evtName = 'evtInfoCPRB';
31
    /**
32
     *
33
     * @var string
34
     */
35
    protected $evtTag = 'evtCPRB';
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'R-2060';
40
41
    /**
42
     * Constructor
43
     * @param string $config
44
     * @param stdClass $std
45
     * @param Certificate $certificate
46
     * @param string date
47
     */
48
    public function __construct(
49
        $config,
50
        stdClass $std,
51
        Certificate $certificate = null,
52
        $date = ''
53
    ) {
54
        parent::__construct($config, $std, $certificate, $date);
55
    }
56
    
57
    /**
58
     * Node constructor
59
     */
60
    protected function toNode()
61
    {
62
        $ideContri = $this->node->getElementsByTagName('ideContri')->item(0);
63
        //o idEvento pode variar de evento para evento
64
        //então cada factory individualmente terá de construir o seu
65
        $ideEvento = $this->dom->createElement("ideEvento");
66
        $this->dom->addChild(
67
            $ideEvento,
68
            "indRetif",
69
            $this->std->indretif,
70
            true
71
        );
72
        $this->dom->addChild(
73
            $ideEvento,
74
            "nrRecibo",
75
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
76
            true
77
        );
78
        $this->dom->addChild(
79
            $ideEvento,
80
            "perApur",
81
            $this->std->perapur,
82
            true
83
        );
84
        $this->dom->addChild(
85
            $ideEvento,
86
            "tpAmb",
87
            $this->tpAmb,
88
            true
89
        );
90
        $this->dom->addChild(
91
            $ideEvento,
92
            "procEmi",
93
            $this->procEmi,
94
            true
95
        );
96
        $this->dom->addChild(
97
            $ideEvento,
98
            "verProc",
99
            $this->verProc,
100
            true
101
        );
102
        $this->node->insertBefore($ideEvento, $ideContri);
103
        
104
        $info = $this->dom->createElement("infoCPRB");
105
        $ideEstab = $this->dom->createElement("ideEstab");
106
        $this->dom->addChild(
107
            $ideEstab,
108
            "tpInscEstab",
109
            $this->std->tpinscestab,
110
            true
111
        );
112
        $this->dom->addChild(
113
            $ideEstab,
114
            "nrInscEstab",
115
            $this->std->nrinscestab,
116
            true
117
        );
118
        $this->dom->addChild(
119
            $ideEstab,
120
            "vlrRecBrutaTotal",
121
            $this->std->vlrrecbrutatotal,
122
            true
123
        );
124
        $this->dom->addChild(
125
            $ideEstab,
126
            "vlrCPApurTotal",
127
            $this->std->vlrcpapurtotal,
128
            true
129
        );
130
        $this->dom->addChild(
131
            $ideEstab,
132
            "vlrCPRBSuspTotal",
133
            !empty($this->std->vlrcprbsusptotal) ? $this->std->vlrcprbsusptotal : null,
134
            false
135
        );
136
        foreach ($this->std->tipocod as $t) {
137
            $tipoCod = $this->dom->createElement("tipoCod");
138
            $this->dom->addChild(
139
               $tipoCod,
140
               "codAtivEcon",
141
               $t->codativecon,
142
               true
143
            );
144
            $this->dom->addChild(
145
               $tipoCod,
146
               "vlrRecBrutaAtiv",
147
               $t->vlrrecbrutaativ,
148
               true
149
            );
150
            $this->dom->addChild(
151
               $tipoCod,
152
               "vlrExcRecBruta",
153
               $t->vlrexcrecbruta,
154
               true
155
            );
156
            $this->dom->addChild(
157
               $tipoCod,
158
               "vlrAdicRecBruta",
159
               $t->vlradicrecbruta,
160
               true
161
            );
162
            $this->dom->addChild(
163
               $tipoCod,
164
               "vlrBcCPRB",
165
               $t->vlrbccprb,
166
               true
167
            );
168
            $this->dom->addChild(
169
               $tipoCod,
170
               "vlrCPRBapur",
171
               !empty($t->vlrcprbapur) ? $t->vlrcprbapur : null,
172
               false
173
            );
174
            if (!empty($t->tipoajuste)) {
175
                foreach ($t->tipoajuste as $a) {
176
                    $tipoAjuste = $this->dom->createElement("tipoAjuste");
177
                    $this->dom->addChild(
178
                        $tipoAjuste,
179
                        "tpAjuste",
180
                        $a->tpajuste,
181
                        true
182
                    );
183
                    $this->dom->addChild(
184
                        $tipoAjuste,
185
                        "codAjuste",
186
                        $a->codajuste,
187
                        true
188
                    );
189
                    $this->dom->addChild(
190
                        $tipoAjuste,
191
                        "vlrAjuste",
192
                        $a->vlrajuste,
193
                        true
194
                    );
195
                    $this->dom->addChild(
196
                        $tipoAjuste,
197
                        "descAjuste",
198
                        $a->descajuste,
199
                        true
200
                    );
201
                    $this->dom->addChild(
202
                        $tipoAjuste,
203
                        "dtAjuste",
204
                        $a->dtajuste,
205
                        true
206
                    );
207
                    $tipoCod->appendChild($tipoAjuste);
208
                }
209
            }
210
            $ideEstab->appendChild($tipoCod);
211
        }
212
        if (!empty($this->std->infoproc)) {
213
            foreach ($this->std->infoproc as $i) {
214
                $infoProc = $this->dom->createElement("infoProc");
215
                $this->dom->addChild(
216
                    $infoProc,
217
                    "vlrCPRBSusp",
218
                    $i->vlrcprbsusp,
219
                    true
220
                );
221
                $this->dom->addChild(
222
                    $infoProc,
223
                    "tpProc",
224
                    $i->tpproc,
225
                    true
226
                );
227
                $this->dom->addChild(
228
                    $infoProc,
229
                    "nrProc",
230
                    $i->nrproc,
231
                    true
232
                );
233
                $this->dom->addChild(
234
                    $infoProc,
235
                    "codSusp",
236
                    !empty($i->codsusp) ? $i->codsusp : null,
237
                    false
238
                );
239
                $ideEstab->appendChild($infoProc);
240
            }
241
        }    
242
        $info->appendChild($ideEstab);
243
        $this->node->appendChild($info);
244
        $this->reinf->appendChild($this->node);
245
        //$this->xml = $this->dom->saveXML($this->reinf);
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...
246
        $this->sign();
247
    }
248
}
249