EvtRERCT::toNode()   F
last analyzed

Complexity

Conditions 24
Paths 2

Size

Total Lines 179

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 179
rs 3.3333
c 0
b 0
f 0
cc 24
nc 2
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace NFePHP\eFinanc\Factories;
4
5
use NFePHP\eFinanc\Common\Factory;
6
use NFePHP\eFinanc\Common\FactoryInterface;
7
use NFePHP\eFinanc\Common\FactoryId;
8
use NFePHP\Common\Certificate;
9
use stdClass;
10
11
class EvtRERCT extends Factory implements FactoryInterface
12
{
13
        /**
14
     * Constructor
15
     * @param string $config
16
     * @param stdClass $std
17
     * @param Certificate $certificate
18
     * @param string $data
19
     */
20
    public function __construct(
21
        $config,
22
        stdClass $std,
23
        Certificate $certificate = null,
24
        $data = ''
25
    ) {
26
        $params = new \stdClass();
27
        $params->evtName = 'evtRERCT';
28
        $params->evtTag = 'evtRERCT';
29
        $params->evtAlias = 'F-8000';
30
        parent::__construct($config, $std, $params, $certificate, $data);
31
    }
32
33
    protected function toNode()
34
    {
35
        $ideDeclarante = $this->node->getElementsByTagName('ideDeclarante')->item(0);
36
        //o idEvento pode variar de evento para evento
37
        //então cada factory individualmente terá de construir o seu
38
        $ideEvento = $this->dom->createElement("ideEvento");
39
        $this->dom->addChild(
40
            $ideEvento,
41
            "ideEventoRERCT",
42
            $this->std->ideeventorerct,
43
            true
44
        );
45
        $this->dom->addChild(
46
            $ideEvento,
47
            "indRetificacao",
48
            $this->std->indretificacao,
49
            true
50
        );
51
        $this->dom->addChild(
52
            $ideEvento,
53
            "nrRecibo",
54
            isset($this->std->nrrecibo) ? $this->std->nrrecibo : null,
55
            false
56
        );
57
        $this->dom->addChild(
58
            $ideEvento,
59
            "tpAmb",
60
            (string) $this->tpAmb,
61
            true
62
        );
63
        $this->dom->addChild(
64
            $ideEvento,
65
            "aplicEmi",
66
            '1',
67
            true
68
        );
69
        $this->dom->addChild(
70
            $ideEvento,
71
            "verAplic",
72
            $this->verAplic,
73
            true
74
        );
75
        $this->node->insertBefore($ideEvento, $ideDeclarante);
76
        
77
        $ideDeclarado = $this->dom->createElement("ideDeclarado");
78
        $cpfCnpjDeclarado = $this->dom->createElement("cpfCnpjDeclarado");
79
        $this->dom->addChild(
80
            $cpfCnpjDeclarado,
81
            "tpInscr",
82
            $this->std->idedeclarado->tpinscr,
83
            true
84
        );
85
        $this->dom->addChild(
86
            $cpfCnpjDeclarado,
87
            "nrInscr",
88
            $this->std->idedeclarado->nrinscr,
89
            true
90
        );
91
        $ideDeclarado->appendChild($cpfCnpjDeclarado);
92
        $this->node->appendChild($ideDeclarado);
93
        
94
        if (!empty($this->std->rerct)) {
95
            foreach ($this->std->rerct as $r) {
96
                $RERCT = $this->dom->createElement("RERCT");
97
                $this->dom->addChild(
98
                    $RERCT,
99
                    "nomeBancoOrigem",
100
                    !empty($r->nomebancoorigem) ? $r->nomebancoorigem : null,
101
                    false
102
                );
103
                $this->dom->addChild(
104
                    $RERCT,
105
                    "paisOrigem",
106
                    !empty($r->paisorigem) ? $r->paisorigem : null,
107
                    false
108
                );
109
                $this->dom->addChild(
110
                    $RERCT,
111
                    "BICBancoOrigem",
112
                    !empty($r->bicbancoorigem) ? $r->bicbancoorigem : null,
113
                    false
114
                );
115
                if (!empty($r->infocontaexterior)) {
116
                    foreach ($r->infocontaexterior as $ce) {
117
                        $infoContaExterior = $this->dom->createElement("infoContaExterior");
118
                        if (!empty($ce->titular)) {
119
                            foreach ($ce->titular as $t) {
120
                                $titular = $this->dom->createElement("titular");
121
                                $this->dom->addChild(
122
                                    $titular,
123
                                    "nomeTitular",
124
                                    !empty($t->nometitular) ? $t->nometitular : null,
125
                                    false
126
                                );
127
                                if (!empty($t->tpinsc) && !empty($t->nrinsc)) {
128
                                    $cpfCnpjTitular = $this->dom->createElement("cpfCnpjTitular");
129
                                    $this->dom->addChild(
130
                                        $cpfCnpjTitular,
131
                                        "tpInscr",
132
                                        $t->tpinscr,
133
                                        true
134
                                    );
135
                                    $this->dom->addChild(
136
                                        $cpfCnpjTitular,
137
                                        "nrInsc",
138
                                        $t->nrinscr,
139
                                        true
140
                                    );
141
                                    $titular->appendChild($cpfCnpjTitular);
142
                                }
143
                                $this->dom->addChild(
144
                                    $titular,
145
                                    "NIFTitular",
146
                                    !empty($t->niftitular) ? $t->niftitular : null,
147
                                    false
148
                                );
149
                                $infoContaExterior->appendChild($titular);
150
                            }
151
                        }
152
                        if (!empty($ce->beneficiariofinal)) {
153
                            foreach ($ce->beneficiariofinal as $t) {
154
                                $beneficiariofinal = $this->dom->createElement("beneficiarioFinal");
155
                                $this->dom->addChild(
156
                                    $beneficiariofinal,
157
                                    "nomeBeneficiarioFinal",
158
                                    !empty($t->nomebeneficiariofinal) ? $t->nomebeneficiariofinal : null,
159
                                    false
160
                                );
161
                                $this->dom->addChild(
162
                                    $beneficiariofinal,
163
                                    "cpfBeneficiarioFinal",
164
                                    !empty($t->cpfbeneficiariofinal) ? $t->cpfbeneficiariofinal : null,
165
                                    false
166
                                );
167
                                $this->dom->addChild(
168
                                    $beneficiariofinal,
169
                                    "NIFBeneficiarioFinal",
170
                                    !empty($t->nifbeneficiariofinal) ? $t->nifbeneficiariofinal : null,
171
                                    false
172
                                );
173
                                $infoContaExterior->appendChild($beneficiariofinal);
174
                            }
175
                        }
176
                        
177
                        $this->dom->addChild(
178
                            $infoContaExterior,
179
                            "tpContaExterior",
180
                            !empty($ce->tpcontaexterior) ? $ce->tpcontaexterior : null,
181
                            false
182
                        );
183
                        $this->dom->addChild(
184
                            $infoContaExterior,
185
                            "nrContaExterior",
186
                            !empty($ce->nrcontaexterior) ? $ce->nrcontaexterior : null,
187
                            false
188
                        );
189
                        $this->dom->addChild(
190
                            $infoContaExterior,
191
                            "vlrUltDia",
192
                            !empty($ce->vlrultdia) ? number_format($ce->vlrultdia, 2, ",", "") : null,
193
                            false
194
                        );
195
                        $this->dom->addChild(
196
                            $infoContaExterior,
197
                            "moeda",
198
                            !empty($ce->moeda) ? $ce->moeda : null,
199
                            false
200
                        );
201
                        $RERCT->appendChild($infoContaExterior);
202
                    }
203
                }
204
                $this->node->appendChild($RERCT);
205
            }
206
        }
207
        //finalização do xml
208
        $this->eFinanceira->appendChild($this->node);
209
        //$this->xml = $this->dom->saveXML($this->eFinanceira);
210
        $this->sign($this->evtTag);
211
    }
212
}
213