Passed
Push — master ( 668b4c...323018 )
by Roberto
06:06 queued 05:23
created

EvtContrSindPatr::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
crap 2
1
<?php
2
3
namespace NFePHP\eSocial\Factories;
4
5
/**
6
 * Class eSocial EvtContrSindPatr Event S-1300 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 EvtContrSindPatr extends Factory implements FactoryInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    public $sequencial;
30
31
    /**
32
     * @var string
33
     */
34
    protected $evtName = 'evtContrSindPatr';
35
36
    /**
37
     * @var string
38
     */
39
    protected $evtAlias = 'S-1300';
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
        $evtContrSindPatr = $this->dom->createElement("evtContrSindPatr");
76
77
        $att = $this->dom->createAttribute('Id');
78
79
        $att->value = $evtid;
80
81
        $evtContrSindPatr->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
        if (isset($this->std->contribsind)) {
132
            foreach ($this->std->contribsind as $contrib) {
133
                $contribSind = $this->dom->createElement("contribSind");
134
135
                $this->dom->addChild(
136
                    $contribSind,
137
                    "cnpjSindic",
138
                    $contrib->cnpjsindic,
139
                    true
140
                );
141
142
                $this->dom->addChild(
143
                    $contribSind,
144
                    "tpContribSind",
145
                    $contrib->tpcontribsind,
146
                    true
147
                );
148
149
                $this->dom->addChild(
150
                    $contribSind,
151
                    "vlrContribSind",
152
                    $contrib->vlrcontribsind,
153
                    true
154
                );
155
156
                $this->node->appendChild($contribSind);
157
            }
158
        }
159
160
        $this->eSocial->appendChild($this->node);
161
        $this->sign();
162
    }
163
}
164