Completed
Pull Request — master (#119)
by
unknown
02:40
created

EvtInfoComplPer::toNode()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 123
Code Lines 85

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 123
ccs 0
cts 104
cp 0
rs 8.1463
cc 5
eloc 85
nc 8
nop 0
crap 30

How to fix   Long Method   

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 EvtInfoComplPer Event S-1280 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\Common\Certificate;
19
use NFePHP\eSocial\Common\Factory;
20
use NFePHP\eSocial\Common\FactoryId;
21
use NFePHP\eSocial\Common\FactoryInterface;
22
use stdClass;
23
24
class EvtInfoComplPer extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtInfoComplPer';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-1280';
40
41
    /**
42
     * Parameters patterns
43
     *
44
     * @var array
45
     */
46
    protected $parameters = [];
47
48
    /**
49
     * Constructor
50
     *
51
     * @param string $config
52
     * @param stdClass $std
53
     * @param Certificate $certificate
54
     */
55
    public function __construct(
56
        $config,
57
        stdClass $std,
58
        Certificate $certificate
59
    ) {
60
        parent::__construct($config, $std, $certificate);
61
    }
62
63
    /**
64
     * Node constructor
65
     */
66
    protected function toNode()
67
    {
68
        $evtid = FactoryId::build(
69
            $this->tpInsc,
70
            $this->nrInsc,
71
            $this->date,
72
            $this->sequencial
73
        );
74
75
        $evtInfoComplPer = $this->dom->createElement("evtInfoComplPer");
76
77
        $att = $this->dom->createAttribute('Id');
78
79
        $att->value = $evtid;
80
81
        $evtInfoComplPer->appendChild($att);
82
83
        $ideEmpregador = $this->node->getElementsByTagName('ideEmpregador')->item(0);
84
85
        $ideEvento = $this->dom->createElement("ideEvento");
86
        $this->dom->addChild(
87
            $ideEvento,
88
            "indRetif",
89
            $this->std->indretif,
90
            true
91
        );
92
        $this->dom->addChild(
93
            $ideEvento,
94
            "nrRecibo",
95
            $this->std->nrrecibo,
96
            false
97
        );
98
        $this->dom->addChild(
99
            $ideEvento,
100
            "indApuracao",
101
            $this->std->indapuracao,
102
            false
103
        );
104
        $this->dom->addChild(
105
            $ideEvento,
106
            "perApur",
107
            $this->std->perapur,
108
            false
109
        );
110
        $this->dom->addChild(
111
            $ideEvento,
112
            "tpAmb",
113
            $this->tpAmb,
114
            true
115
        );
116
        $this->dom->addChild(
117
            $ideEvento,
118
            "procEmi",
119
            $this->procEmi,
120
            true
121
        );
122
        $this->dom->addChild(
123
            $ideEvento,
124
            "verProc",
125
            $this->verProc,
126
            true
127
        );
128
129
        $this->node->insertBefore($ideEvento, $ideEmpregador);
130
131
        if (isset($this->std->infosubstpatr)) {
132
            $infoSubstPatr = $this->dom->createElement("infoSubstPatr");
133
134
            $this->dom->addChild(
135
                $infoSubstPatr,
136
                "indSubstPatr",
137
                $this->std->infosubstpatr->indsubstpatr,
138
                true
139
            );
140
141
            $this->dom->addChild(
142
                $infoSubstPatr,
143
                "percRedContrib",
144
                $this->std->infosubstpatr->percpedcontrib,
145
                true
146
            );
147
148
            $this->node->appendChild($infoSubstPatr);
149
        }
150
151
        if (isset($this->std->infosubstpatropport)) {
152
            foreach ($this->std->infosubstpatropport as $info) {
153
                $infoSubstPatrOpPort = $this->dom->createElement("infoSubstPatrOpPort");
154
155
                $this->dom->addChild(
156
                    $infoSubstPatrOpPort,
157
                    "cnpjOpPortuario",
158
                    $info->cnpjopportuario,
159
                    true
160
                );
161
162
                $this->node->appendChild($infoSubstPatrOpPort);
163
            }
164
        }
165
166
        if (isset($this->std->infoativconcom)) {
167
            $infoAtivConcom = $this->dom->createElement("infoAtivConcom");
168
169
            $this->dom->addChild(
170
                $infoAtivConcom,
171
                "fatorMes",
172
                $this->std->infoativconcom->fatormes,
173
                true
174
            );
175
176
            $this->dom->addChild(
177
                $infoAtivConcom,
178
                "fator13",
179
                $this->std->infoativconcom->fator13,
180
                true
181
            );
182
183
            $this->node->appendChild($infoAtivConcom);
184
        }
185
186
        $this->eSocial->appendChild($this->node);
187
        $this->sign();
188
    }
189
}
190