Completed
Push — master ( 9654f6...5e67fa )
by Roberto
14:40
created

EvtFechamentoeFinanceira   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 166
Duplicated Lines 19.28 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
c 0
b 0
f 0
lcom 1
cbo 2
dl 32
loc 166
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
D toNode() 32 143 9

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 EvtFechamentoeFinanceira 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 = 'evtFechamentoeFinanceira';
28
        $params->evtTag = 'evtFechamentoeFinanceira';
29
        $params->evtAlias = 'F-4000';
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
            "indRetificacao",
42
            $this->std->indretificacao,
43
            true
44
        );
45
        $this->dom->addChild(
46
            $ideEvento,
47
            "nrRecibo",
48
            isset($this->std->nrrecibo) ? $this->std->nrrecibo : null,
49
            false
50
        );
51
        $this->dom->addChild(
52
            $ideEvento,
53
            "tpAmb",
54
            (string) $this->tpAmb,
55
            true
56
        );
57
        $this->dom->addChild(
58
            $ideEvento,
59
            "aplicEmi",
60
            '1',
61
            true
62
        );
63
        $this->dom->addChild(
64
            $ideEvento,
65
            "verAplic",
66
            $this->verAplic,
67
            true
68
        );
69
        $this->node->insertBefore($ideEvento, $ideDeclarante);
70
        
71
        $infoFechamento = $this->dom->createElement("infoFechamento");
72
        $this->dom->addChild(
73
            $infoFechamento,
74
            "dtInicio",
75
            $this->std->dtinicio,
76
            true
77
        );
78
        $this->dom->addChild(
79
            $infoFechamento,
80
            "dtFim",
81
            $this->std->dtfim,
82
            true
83
        );
84
        $this->dom->addChild(
85
            $infoFechamento,
86
            "sitEspecial",
87
            $this->std->sitespecial,
88
            true
89
        );
90
        $this->node->insertBefore($infoFechamento);
91
92
        if (!empty($this->std->fechamentopp)) {
93
            $fpp = $this->std->fechamentopp;
94
            $FechamentoPP = $this->dom->createElement("FechamentoPP");
95 View Code Duplication
            foreach ($fpp->fechamentomes as $fm) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
                $FechamentoMes = $this->dom->createElement("FechamentoMes");
97
                $this->dom->addChild(
98
                    $FechamentoMes,
99
                    "anoMesCaixa",
100
                    $fm->anomescaixa,
101
                    true
102
                );
103
                $this->dom->addChild(
104
                    $FechamentoMes,
105
                    "quantArqTrans",
106
                    $fm->quantarqtrans,
107
                    true
108
                );
109
                $FechamentoPP->appendChild($FechamentoMes);
110
            }
111
            $this->node->appendChild($FechamentoPP);
112
        }
113
114
        if (!empty($this->std->fechamentomovopfin)) {
115
            $opfin = $this->std->fechamentomovopfin;
116
            $FechamentoMovOpFin = $this->dom->createElement("FechamentoMovOpFin");
117 View Code Duplication
            foreach ($opfin->fechamentomes as $fm) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
118
                $FechamentoMes = $this->dom->createElement("FechamentoMes");
119
                $this->dom->addChild(
120
                    $FechamentoMes,
121
                    "anoMesCaixa",
122
                    $fm->anomescaixa,
123
                    true
124
                );
125
                $this->dom->addChild(
126
                    $FechamentoMes,
127
                    "quantArqTrans",
128
                    $fm->quantarqtrans,
129
                    true
130
                );
131
                $FechamentoMovOpFin->appendChild($FechamentoMes);
132
            }
133
            if (!empty($opfin->entdecexterior)) {
134
                $EntDecExterior = $this->dom->createElement("EntDecExterior");
135
                $this->dom->addChild(
136
                    $EntDecExterior,
137
                    "ContasAReportar",
138
                    $opfin->entdecexterior->contasareportar,
139
                    true
140
                );
141
                $FechamentoMovOpFin->appendChild($EntDecExterior);
142
            }
143
            
144
            if (!empty($opfin->entpatdecexterior)) {
145
                foreach ($opfin->entpatdecexterior as $ex) {
146
                    $EntPatDecExterior = $this->dom->createElement("EntPatDecExterior");
147
                    $this->dom->addChild(
148
                        $EntPatDecExterior,
149
                        "GIIN",
150
                        $ex->giin,
151
                        true
152
                    );
153
                    $this->dom->addChild(
154
                        $EntPatDecExterior,
155
                        "CNPJ",
156
                        $ex->cnpj,
157
                        true
158
                    );
159
                    $this->dom->addChild(
160
                        $EntPatDecExterior,
161
                        "ContasAReportar",
162
                        $ex->contasareportar,
163
                        true
164
                    );
165
                    $FechamentoMovOpFin->appendChild($EntPatDecExterior);
166
                }
167
            }
168
            $this->node->appendChild($FechamentoMovOpFin);
169
        }
170
        
171
        //finalização do xml
172
        $this->eFinanceira->appendChild($this->node);
173
        //$this->xml = $this->dom->saveXML($this->eFinanceira);
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...
174
        $this->sign($this->evtTag);
175
    }
176
}
177