Passed
Push — master ( 403c65...ada905 )
by Roberto
01:04
created

EvtBenPrRP::toNode()   B

Complexity

Conditions 6
Paths 2

Size

Total Lines 137
Code Lines 95

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 137
ccs 0
cts 116
cp 0
rs 8.1463
cc 6
eloc 95
nc 2
nop 0
crap 42

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 EvtBenPrRP Event S-1207 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 EvtBenPrRP extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtBenPrRP';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-1207';
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
        $evtBenPrRP = $this->dom->createElement("evtBenPrRP");
76
77
        $att = $this->dom->createAttribute('Id');
78
79
        $att->value = $evtid;
80
81
        $evtBenPrRP->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
            !empty($this->std->nrrecibo) ? $this->std->nrrecibo : null,
96
            false
97
        );
98
        $this->dom->addChild(
99
            $ideEvento,
100
            "indApuracao",
101
            $this->std->indapuracao,
102
            true
103
        );
104
        $this->dom->addChild(
105
            $ideEvento,
106
            "perApur",
107
            $this->std->perapur,
108
            true
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
        $ideBenef = $this->dom->createElement("ideBenef");
132
133
        $this->dom->addChild(
134
            $ideBenef,
135
            "cpfBenef",
136
            $this->std->cpfbenef,
137
            true
138
        );
139
140
        $this->node->appendChild($ideBenef);
141
142
        if (isset($this->std->dmdev)) {
143
            foreach ($this->std->dmdev as $dev) {
144
                $dmDev = $this->dom->createElement("dmDev");
145
146
                $this->dom->addChild(
147
                    $dmDev,
148
                    "tpBenef",
149
                    $dev->tpbenef,
150
                    true
151
                );
152
153
                $this->dom->addChild(
154
                    $dmDev,
155
                    "nrBenefic",
156
                    $dev->nrbenefic,
157
                    true
158
                );
159
160
                $this->dom->addChild(
161
                    $dmDev,
162
                    "ideDmDev",
163
                    $dev->idedmdev,
164
                    true
165
                );
166
167
                if (isset($dev->itens)) {
168
                    foreach ($dev->itens as $item) {
169
                        $itens = $this->dom->createElement("itens");
170
171
                        $this->dom->addChild(
172
                            $itens,
173
                            "codRubr",
174
                            $item->codrubr,
175
                            true
176
                        );
177
178
                        $this->dom->addChild(
179
                            $itens,
180
                            "ideTabRubr",
181
                            $item->idetabrubr,
182
                            true
183
                        );
184
185
                        $this->dom->addChild(
186
                            $itens,
187
                            "vrRubr",
188
                            $item->vrrubr,
189
                            true
190
                        );
191
192
                        $dmDev->appendChild($itens);
193
                    }
194
                }
195
196
                $this->node->appendChild($dmDev);
197
            }
198
        }
199
200
        $this->eSocial->appendChild($this->node);
201
        $this->sign();
202
    }
203
}
204