Passed
Pull Request — master (#10)
by Roberto
03:47
created

EvtInfoContri   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 220
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
lcom 1
cbo 2
dl 0
loc 220
ccs 0
cts 190
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
D toNode() 0 188 15
1
<?php
2
3
namespace NFePHP\EFDReinf\Factories;
4
5
/**
6
 * Class EFD-Reinf EvtInfoContri Event R-1000 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 EvtInfoContri extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var string
28
     */
29
    protected $evtName = 'evtInfoContribuinte';
30
    protected $evtTag = 'evtInfoContri';
31
    /**
32
     * @var string
33
     */
34
    protected $evtAlias = 'R-1000';
35
36
    /**
37
     * Constructor
38
     * @param string $config
39
     * @param stdClass $std
40
     * @param Certificate $certificate
41
     * @param string date
42
     */
43
    public function __construct(
44
        $config,
45
        stdClass $std,
46
        Certificate $certificate = null,
47
        $date = ''
48
    ) {
49
        parent::__construct($config, $std, $certificate, $date);
50
    }
51
    
52
    /**
53
     * Node constructor
54
     */
55
    protected function toNode()
56
    {
57
        $ideContri = $this->node->getElementsByTagName('ideContri')->item(0);
58
        //o idEvento pode variar de evento para evento
59
        //então cada factory individualmente terá de construir o seu
60
        $ideEvento = $this->dom->createElement("ideEvento");
61
        $this->dom->addChild(
62
            $ideEvento,
63
            "tpAmb",
64
            $this->tpAmb,
65
            true
66
        );
67
        $this->dom->addChild(
68
            $ideEvento,
69
            "procEmi",
70
            $this->procEmi,
71
            true
72
        );
73
        $this->dom->addChild(
74
            $ideEvento,
75
            "verProc",
76
            $this->verProc,
77
            true
78
        );
79
        $this->node->insertBefore($ideEvento, $ideContri);
80
        //tag deste evento em particular
81
        $infoContri = $this->dom->createElement("infoContri");
82
        //se aplica a todos os modos
83
        $idePeriodo = $this->dom->createElement("idePeriodo");
84
        $this->dom->addChild(
85
            $idePeriodo,
86
            "iniValid",
87
            $this->std->inivalid,
88
            true
89
        );
90
        $this->dom->addChild(
91
            $idePeriodo,
92
            "fimValid",
93
            !empty($this->std->fimvalid) ? $this->std->fimvalid : null,
94
            false
95
        );
96
        if (!empty($this->std->infocadastro)) {
97
            $cad = $this->std->infocadastro;
98
            $infocadastro = $this->dom->createElement("infoCadastro");
99
            $this->dom->addChild(
100
                $infocadastro,
101
                "classTrib",
102
                $cad->classtrib,
103
                true
104
            );
105
            $this->dom->addChild(
106
                $infocadastro,
107
                "indEscrituracao",
108
                $cad->indescrituracao,
109
                true
110
            );
111
            $this->dom->addChild(
112
                $infocadastro,
113
                "indDesoneracao",
114
                $cad->inddesoneracao,
115
                true
116
            );
117
            $this->dom->addChild(
118
                $infocadastro,
119
                "indAcordoIsenMulta",
120
                $cad->indacordoisenmulta,
121
                true
122
            );
123
            $indsitpj = null;
124
            if (isset($cad->indsitpj)) {
125
                $indsitpj = $cad->indsitpj;
126
            }
127
            $this->dom->addChild(
128
                $infocadastro,
129
                "indSitPJ",
130
                $indsitpj,
131
                false
132
            );
133
            $contato = $this->dom->createElement("contato");
134
            $this->dom->addChild(
135
                $contato,
136
                "nmCtt",
137
                $cad->contato->nmctt,
138
                true
139
            );
140
            $this->dom->addChild(
141
                $contato,
142
                "cpfCtt",
143
                $cad->contato->cpfctt,
144
                true
145
            );
146
            $this->dom->addChild(
147
                $contato,
148
                "foneFixo",
149
                !empty($cad->contato->fonefixo)
150
                    ? $cad->contato->fonefixo
151
                    : null,
152
                false
153
            );
154
            $this->dom->addChild(
155
                $contato,
156
                "foneCel",
157
                !empty($cad->contato->fonecel)
158
                    ? $cad->contato->fonecel
159
                    : null,
160
                false
161
            );
162
            $this->dom->addChild(
163
                $contato,
164
                "email",
165
                !empty($cad->contato->email)
166
                    ? $cad->contato->email
167
                    : null,
168
                false
169
            );
170
            $infocadastro->appendChild($contato);
171
            if (!empty($cad->softhouse)) {
172
                foreach($cad->softhouse as $soft) {
173
                    $softhouse = $this->dom->createElement("softHouse");
174
                    $this->dom->addChild(
175
                        $softhouse,
176
                        "cnpjSoftHouse",
177
                        $soft->cnpjsofthouse,
178
                        true
179
                    );
180
                    $this->dom->addChild(
181
                        $softhouse,
182
                        "nmRazao",
183
                        $soft->nmrazao,
184
                        true
185
                    );
186
                    $this->dom->addChild(
187
                        $softhouse,
188
                        "nmCont",
189
                        $soft->nmcont,
190
                        true
191
                    );
192
                    $this->dom->addChild(
193
                        $softhouse,
194
                        "telefone",
195
                        !empty($soft->telefone) ? $soft->telefone : null,
196
                        false
197
                    );
198
                    $this->dom->addChild(
199
                        $softhouse,
200
                        "email",
201
                        !empty($soft->email) ? $soft->email : null,
202
                        false
203
                    );
204
                    $infocadastro->appendChild($softhouse);
205
                }
206
            }
207
            if (!empty($cad->infoefr)) {
208
                $infoEFR = $this->dom->createElement("infoEFR");
209
                $this->dom->addChild(
210
                    $infoEFR,
211
                    "ideEFR",
212
                    $cad->infoefr->ideefr,
213
                    true
214
                );
215
                $this->dom->addChild(
216
                    $infoEFR,
217
                    "cnpjEFR",
218
                    !empty($cad->infoefr->cnpjefr) ? $cad->infoefr->cnpjefr : null,
219
                    false
220
                );
221
                $infocadastro->appendChild($infoEFR);
222
            }
223
        }
224
        if ($this->std->modo == 'INC') {
225
            $modo = $this->dom->createElement("inclusao");
226
            $modo->appendChild($idePeriodo);
227
            $modo->appendChild($infocadastro);
0 ignored issues
show
Bug introduced by
The variable $infocadastro does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
228
        } elseif ($this->std->modo == 'ALT') {
229
            $modo = $this->dom->createElement("alteracao");
230
            $modo->appendChild($idePeriodo);
231
            $modo->appendChild($infocadastro);
232
        } else {
233
            $modo = $this->dom->createElement("exclusao");
234
            $modo->appendChild($idePeriodo);
235
        }
236
        //finalização do xml
237
        $infoContri->appendChild($modo);
238
        $this->node->appendChild($infoContri);
239
        $this->reinf->appendChild($this->node);
240
        //$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...
241
        $this->sign();
242
    }
243
}
244