Passed
Push — master ( 47ff60...8f2c26 )
by Roberto
02:25
created

EvtTabProcesso::toNode()   C

Complexity

Conditions 11
Paths 24

Size

Total Lines 158
Code Lines 122

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
dl 0
loc 158
ccs 0
cts 147
cp 0
rs 5.2653
c 0
b 0
f 0
cc 11
eloc 122
nc 24
nop 0
crap 132

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\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtTabProcesso Event S-1070 constructor
7
 *
8
 * @category  NFePHP
9
 * @package   NFePHPSocial
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-esocial for the canonical source repository
16
 */
17
18
use NFePHP\eSocial\Common\Factory;
19
use NFePHP\eSocial\Common\FactoryInterface;
20
use NFePHP\eSocial\Common\FactoryId;
21
use NFePHP\Common\Certificate;
22
use stdClass;
23
24
class EvtTabProcesso extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtTabProcesso';
35
    /**
36
     * @var string
37
     */
38
    protected $evtAlias = 'S-1070';
39
    /**
40
     * Parameters patterns
41
     * @var array
42
     */
43
    protected $parameters = [];
44
45
    /**
46
     * Constructor
47
     * @param string $config
48
     * @param stdClass $std
49
     * @param Certificate $certificate
50
     */
51
    public function __construct(
52
        $config,
53
        stdClass $std,
54
        Certificate $certificate
55
    ) {
56
        parent::__construct($config, $std, $certificate);
57
    }
58
    
59
    /**
60
     * Node constructor
61
     */
62
    protected function toNode()
63
    {
64
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
65
        //o idEvento pode variar de evento para evento
66
        //então cada factory individualmente terá de construir o seu
67
        $ideEvento = $this->dom->createElement("ideEvento");
68
        $this->dom->addChild(
69
            $ideEvento,
70
            "tpAmb",
71
            $this->tpAmb,
72
            true
73
        );
74
        $this->dom->addChild(
75
            $ideEvento,
76
            "procEmi",
77
            $this->procEmi,
78
            true
79
        );
80
        $this->dom->addChild(
81
            $ideEvento,
82
            "verProc",
83
            $this->verProc,
84
            true
85
        );
86
        $this->node->insertBefore($ideEvento, $ideEmpregador);
87
        
88
        //tag deste evento em particular
89
        $info = $this->dom->createElement("infoProcesso");
90
        
91
        //tag comum a todos os modos
92
        $ide = $this->dom->createElement("ideProcesso");
93
        $this->dom->addChild(
94
            $ide,
95
            "tpProc",
96
            $this->std->tpproc,
97
            true
98
        );
99
        $this->dom->addChild(
100
            $ide,
101
            "nrProc",
102
            $this->std->nrproc,
103
            true
104
        );
105
        $this->dom->addChild(
106
            $ide,
107
            "iniValid",
108
            $this->std->inivalid,
109
            true
110
        );
111
        $this->dom->addChild(
112
            $ide,
113
            "fimValid",
114
            !empty($this->std->fimvalid) ? $this->std->fimvalid : null,
115
            false
116
        );
117
        //seleção do modo
118
        if ($this->std->modo == 'INC') {
119
            $node = $this->dom->createElement("inclusao");
120
        } elseif ($this->std->modo == 'ALT') {
121
            $node = $this->dom->createElement("alteracao");
122
        } else {
123
            $node = $this->dom->createElement("exclusao");
124
        }
125
        $node->appendChild($ide);
126
        
127
        $dados = $this->dom->createElement("dadosProc");
128
        $this->dom->addChild(
129
            $dados,
130
            "indAutoria",
131
            !empty($this->std->dadosproc->indautoria)
132
                ? $this->std->dadosproc->indautoria
133
                : null,
134
            false
135
        );
136
        $this->dom->addChild(
137
            $dados,
138
            "indMatProc",
139
            $this->std->dadosproc->indmatproc,
140
            true
141
        );
142
        if (!empty($this->std->dadosproc->dadosprocjud)) {
143
            $dadosProcJud = $this->dom->createElement("dadosProcJud");
144
            $this->dom->addChild(
145
                $dadosProcJud,
146
                "ufVara",
147
                $this->std->dadosproc->dadosprocjud->ufvara,
148
                true
149
            );
150
            $this->dom->addChild(
151
                $dadosProcJud,
152
                "codMunic",
153
                $this->std->dadosproc->dadosprocjud->codmunic,
154
                true
155
            );
156
            $this->dom->addChild(
157
                $dadosProcJud,
158
                "idVara",
159
                $this->std->dadosproc->dadosprocjud->idvara,
160
                true
161
            );
162
            $dados->appendChild($dadosProcJud);
163
        }
164
        if (!empty($this->std->dadosproc->infosusp)) {
165
            foreach ($this->std->dadosproc->infosusp as $susp) {
166
                $infoSusp = $this->dom->createElement("infoSusp");
167
                $this->dom->addChild(
168
                    $infoSusp,
169
                    "codSusp",
170
                    $susp->codsusp,
171
                    true
172
                );
173
                $this->dom->addChild(
174
                    $infoSusp,
175
                    "indSusp",
176
                    $susp->indsusp,
177
                    true
178
                );
179
                $this->dom->addChild(
180
                    $infoSusp,
181
                    "dtDecisao",
182
                    $susp->dtdecisao,
183
                    true
184
                );
185
                $this->dom->addChild(
186
                    $infoSusp,
187
                    "indDeposito",
188
                    $susp->inddeposito,
189
                    true
190
                );
191
                $dados->appendChild($infoSusp);
192
            }
193
        }
194
        $node->appendChild($dados);
195
        
196
        if (!empty($this->std->novavalidade) && $this->std->modo == 'ALT') {
197
            $newVal = $this->std->novavalidade;
198
            $novaValidade = $this->dom->createElement("novaValidade");
199
            $this->dom->addChild(
200
                $ideRubrica,
201
                "iniValid",
202
                $newVal->inivalid,
203
                true
204
            );
205
            $this->dom->addChild(
206
                $ideRubrica,
207
                "fimValid",
208
                !empty($newVal->fimvalid) ? $newVal->fimvalid : null,
209
                false
210
            );
211
            $node->appendChild($novaValidade);
212
        }
213
        
214
        $info->appendChild($node);
215
        //finalização do xml
216
        $this->node->appendChild($info);
217
        $this->eSocial->appendChild($this->node);
218
        $this->sign();
219
    }
220
}
221