Completed
Pull Request — master (#227)
by Roberto
03:27
created

EvtFGTS::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

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 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 2
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtFGTS Event S-5013 constructor
7
 * Read for 2.5.0 layout
8
 *
9
 * @category  library
10
 * @package   NFePHP\eSocial
11
 * @copyright NFePHP Copyright (c) 2017-2019
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\FactoryInterface;
22
use stdClass;
23
24
class EvtFGTS extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
    /**
31
     * @var string
32
     */
33
    protected $evtName = 'evtFGTS';
34
    /**
35
     * @var string
36
     */
37
    protected $evtAlias = 'S-5013';
38
    /**
39
     * Parameters patterns
40
     *
41
     * @var array
42
     */
43
    protected $parameters = [];
44
45
    /**
46
     * Constructor
47
     *
48
     * @param string $config
49
     * @param stdClass $std
50
     * @param Certificate $certificate | null
51
     * @param string $date
52
     */
53
    public function __construct(
54
        $config,
55
        stdClass $std,
56
        Certificate $certificate = null,
57
        $date = ''
58
    ) {
59
        parent::__construct($config, $std, $certificate, $date);
60
    }
61
62
    /**
63
     * Node constructor
64
     */
65
    protected function toNode()
66
    {
67
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
68
        //o idEvento pode variar de evento para evento
69
        //então cada factory individualmente terá de construir o seu
70
        $ideEvento = $this->dom->createElement("ideEvento");
71
        $this->dom->addChild(
72
            $ideEvento,
73
            "perApur",
74
            $this->std->perapur,
75
            true
76
        );
77
        $this->node->insertBefore($ideEvento, $ideEmpregador);
78
        //tag deste evento em particular
79
                
80
        $infofgts = $this->dom->createElement("infoFGTS");
81
        $this->dom->addChild(
82
            $infofgts,
83
            "nrRecArqBase",
84
            $this->std->infofgts->nrrecarqbase,
85
            true
86
        );
87
        $this->dom->addChild(
88
            $infofgts,
89
            "indExistInfo",
90
            $this->std->infofgts->indexistinfo,
91
            true
92
        );
93
        if (!empty($this->std->infofgts->infobasefgts)) {
94
            $infoBaseFGTS = $this->dom->createElement("infoBaseFGTS");
95
            if (!empty($this->std->infofgts->infobasefgts->baseperapur)) {
96
                foreach ($this->std->infofgts->infobasefgts->baseperapur as $bap) {
97
                    $basePerApur = $this->dom->createElement("basePerApur");
98
                    $this->dom->addChild(
99
                        $basePerApur,
100
                        "tpValor",
101
                        $bap->tpvalor,
102
                        true
103
                    );
104
                    $this->dom->addChild(
105
                        $basePerApur,
106
                        "baseFGTS",
107
                        number_format($bap->basefgts, 2, ".", ""),
108
                        true
109
                    );
110
                    $infoBaseFGTS->appendChild($basePerApur);
111
                }
112
            }
113
            if (!empty($this->std->infofgts->infobasefgts->infobaseperante)) {
114
                foreach ($this->std->infofgts->infobasefgts->infobaseperante as $ipa) {
115
                    $infoBasePerAntE = $this->dom->createElement("infoBasePerAntE");
116
                    $this->dom->addChild(
117
                        $infoBasePerAntE,
118
                        "perRef",
119
                        $ipa->perref,
120
                        true
121
                    );
122
                    foreach ($ipa->baseperante as $bpae) {
123
                        $basePerAntE = $this->dom->createElement("basePerAntE");
124
                        $this->dom->addChild(
125
                            $basePerAntE,
126
                            "tpValorE",
127
                            $bpae->tpvalore,
128
                            true
129
                        );
130
                        $this->dom->addChild(
131
                            $basePerAntE,
132
                            "baseFGTSE",
133
                            number_format($bpae->basefgtse, 2, ".", ""),
134
                            true
135
                        );
136
                        $infoBasePerAntE->appendChild($basePerAntE);
137
                    }
138
                    $infoBaseFGTS->appendChild($infoBasePerAntE);
139
                }
140
            }
141
            $infofgts->appendChild($infoBaseFGTS);
142
        }
143
        if (!empty($this->std->infofgts->infodpsfgts)) {
144
            $infoDpsFGTS = $this->dom->createElement("infoDpsFGTS");
145
            if (!empty($this->std->infofgts->infodpsfgts->dpsperapur)) {
146
                foreach ($this->std->infofgts->infodpsfgts->dpsperapur as $dpap) {
147
                    $dpsPerApur = $this->dom->createElement("dpsPerApur");
148
                    $this->dom->addChild(
149
                        $dpsPerApur,
150
                        "tpDps",
151
                        $dpap->tpdps,
152
                        true
153
                    );
154
                    $this->dom->addChild(
155
                        $dpsPerApur,
156
                        "vrFGTS",
157
                        number_format($dpap->vrfgts, 2, ".", ""),
158
                        true
159
                    );
160
                    if (!empty($dpap->infodpsperante)) {
161
                        foreach ($dpap->infodpsperante as $ipte) {
162
                            $infoDpsPerAntE = $this->dom->createElement("infoDpsPerAntE");
163
                            $this->dom->addChild(
164
                                $infoDpsPerAntE,
165
                                "perRef",
166
                                $ipte->perref,
167
                                true
168
                            );
169
                            foreach ($ipte->dpsperante as $dpte) {
170
                                $dpsPerAntE = $this->dom->createElement("dpsPerAntE");
171
                                $this->dom->addChild(
172
                                    $dpsPerAntE,
173
                                    "tpDpsE",
174
                                    $dpte->tpDpsE,
175
                                    true
176
                                );
177
                                $this->dom->addChild(
178
                                    $dpsPerAntE,
179
                                    "vrFGTSE",
180
                                    $dpte->vrfgtse,
181
                                    true
182
                                );
183
                                $infoDpsPerAntE->appendChild($dpsPerAntE);
184
                            }
185
                            $dpsPerApur->appendChild($infoDpsPerAntE);
186
                        }
187
                    }
188
                    $infoDpsFGTS->appendChild($dpsPerApur);
189
                }
190
            }
191
            $infofgts->appendChild($infoDpsFGTS);
192
        }
193
        $this->node->appendChild($infofgts);
194
        //finalização do xml
195
        $this->eSocial->appendChild($this->node);
196
        //$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...
197
        $this->sign();
198
    }
199
}
200