Passed
Push — master ( e850ef...69529f )
by Roberto
02:10
created

EvtComProd   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 190
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 190
ccs 0
cts 172
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
C toNode() 0 164 12
1
<?php
2
3
namespace NFePHP\EFDReinf\Factories;
4
5
/**
6
 * Class EFD-Reinf EvtComProd Event R-2050 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 EvtComProd extends Factory implements FactoryInterface
25
{
26
    /**
27
     * Constructor
28
     * @param string $config
29
     * @param stdClass $std
30
     * @param Certificate $certificate
31
     * @param string date
32
     */
33
    public function __construct(
34
        $config,
35
        stdClass $std,
36
        Certificate $certificate = null,
37
        $date = ''
38
    ) {
39
        $params = new \stdClass();
40
        $params->evtName = 'evtInfoProdRural';
41
        $params->evtTag = 'evtComProd';
42
        $params->evtAlias = 'R-2050';
43
        parent::__construct($config, $std, $params, $certificate, $date);
44
    }
45
    
46
    /**
47
     * Node constructor
48
     */
49
    protected function toNode()
50
    {
51
        $ideContri = $this->node->getElementsByTagName('ideContri')->item(0);
52
        //o idEvento pode variar de evento para evento
53
        //então cada factory individualmente terá de construir o seu
54
        $ideEvento = $this->dom->createElement("ideEvento");
55
        $this->dom->addChild(
56
            $ideEvento,
57
            "indRetif",
58
            $this->std->indretif,
59
            true
60
        );
61
        $this->dom->addChild(
62
            $ideEvento,
63
            "nrRecibo",
64
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
65
            true
66
        );
67
        $this->dom->addChild(
68
            $ideEvento,
69
            "perApur",
70
            $this->std->perapur,
71
            true
72
        );
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "tpAmb",
76
            $this->tpAmb,
77
            true
78
        );
79
        $this->dom->addChild(
80
            $ideEvento,
81
            "procEmi",
82
            $this->procEmi,
83
            true
84
        );
85
        $this->dom->addChild(
86
            $ideEvento,
87
            "verProc",
88
            $this->verProc,
89
            true
90
        );
91
        $this->node->insertBefore($ideEvento, $ideContri);
92
        
93
        $info = $this->dom->createElement("infoComProd");
94
        $ideEstab = $this->dom->createElement("ideEstab");
95
        $this->dom->addChild(
96
            $ideEstab,
97
            "tpInscEstab",
98
            $this->std->tpinscestab,
99
            true
100
        );
101
        $this->dom->addChild(
102
            $ideEstab,
103
            "nrInscEstab",
104
            $this->std->nrinscestab,
105
            true
106
        );
107
        $this->dom->addChild(
108
            $ideEstab,
109
            "vlrRecBrutaTotal",
110
            number_format($this->std->vlrrecbrutatotal, 2, ',', ''),
111
            true
112
        );
113
        $this->dom->addChild(
114
            $ideEstab,
115
            "vlrCPApur",
116
            number_format($this->std->vlrcpapur, 2, ',', ''),
117
            true
118
        );
119
        $this->dom->addChild(
120
            $ideEstab,
121
            "vlrRatApur",
122
            number_format($this->std->vlrratapur, 2, ',', ''),
123
            true
124
        );
125
        $this->dom->addChild(
126
            $ideEstab,
127
            "vlrSenarApur",
128
            number_format($this->std->vlrsenarapur, 2, ',', ''),
129
            true
130
        );
131
        $this->dom->addChild(
132
            $ideEstab,
133
            "vlrCPSuspTotal",
134
            !empty($this->std->vlrcpsusptotal) ? number_format($this->std->vlrcpsusptotal, 2, ',', '') : null,
135
            false
136
        );
137
        $this->dom->addChild(
138
            $ideEstab,
139
            "vlrRatSuspTotal",
140
            !empty($this->std->vlrratsusptotal) ? number_format($this->std->vlrratsusptotal, 2, ',', '') : null,
141
            false
142
        );
143
        $this->dom->addChild(
144
            $ideEstab,
145
            "vlrSenarSuspTotal",
146
            !empty($this->std->vlrsenarsusptotal) ? number_format($this->std->vlrsenarsusptotal, 2, ',', '') : null,
147
            false
148
        );
149
        foreach ($this->std->tipocom as $tp) {
150
            $tipoCom = $this->dom->createElement("tipoCom");
151
            $this->dom->addChild(
152
                $tipoCom,
153
                "indCom",
154
                $tp->indcom,
155
                true
156
            );
157
            $this->dom->addChild(
158
                $tipoCom,
159
                "vlrRecBruta",
160
                number_format($tp->vlrrecbruta, 2, ',', ''),
161
                true
162
            );
163
            $ideEstab->appendChild($tipoCom);
164
        }
165
        if (!empty($this->std->infoproc)) {
166
            foreach($this->std->infoproc as $ip) {
167
                $infoProc = $this->dom->createElement("infoProc");
168
                $this->dom->addChild(
169
                    $infoProc,
170
                    "tpProc",
171
                    $ip->tpproc,
172
                    true
173
                );
174
                $this->dom->addChild(
175
                    $infoProc,
176
                    "nrProc",
177
                    $ip->nrproc,
178
                    true
179
                );
180
                $this->dom->addChild(
181
                    $infoProc,
182
                    "codSusp",
183
                    !empty($ip->codsusp) ? $ip->codsusp : null,
184
                    false
185
                );
186
                $this->dom->addChild(
187
                    $infoProc,
188
                    "vlrCPSusp",
189
                    !empty($ip->vlrcpsusp) ? number_format($ip->vlrcpsusp, 2, ',', '') : null,
190
                    false
191
                );
192
                $this->dom->addChild(
193
                    $infoProc,
194
                    "vlrRatSusp",
195
                    !empty($ip->vlrratsusp) ? number_format($ip->vlrratsusp, 2, ',', '') : null,
196
                    false
197
                );
198
                $this->dom->addChild(
199
                    $infoProc,
200
                    "vlrSenarSusp",
201
                    !empty($ip->vlrsenarsusp) ? number_format($ip->vlrsenarsusp, 2, ',', '') : null,
202
                    false
203
                );
204
                $ideEstab->appendChild($infoProc);
205
            }
206
        }
207
        $info->appendChild($ideEstab);
208
        $this->node->appendChild($info);
209
        $this->reinf->appendChild($this->node);
210
        //$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...
211
        $this->sign($this->evtTag);
212
    }
213
}
214