Test Setup Failed
Push — master ( aa40a2...69297c )
by Eduardo
06:24
created

Config::getServiceCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Eduardokum\CorreiosPhp\Config;
3
4
use Eduardokum\CorreiosPhp\Entities\Sender;
5
use Eduardokum\CorreiosPhp\Exception\InvalidArgumentException;
6
use Eduardokum\CorreiosPhp\Traits\MagicTrait;
7
8
abstract class Config
9
{
10
    use MagicTrait;
11
12
    protected $environment = null;
13
    protected $cnpj = null;
14
    protected $user = null;
15
    protected $password = null;
16
    protected $userRastro = null;
17
    protected $passwordRastro = null;
18
    protected $administrativeCode = null;
19
    protected $contract = null;
20
    protected $postCard = null;
21
    protected $direction = null;
22
    protected $sender = null;
23
    protected $directories = [
24
        '01' => ['name' => 'CS – Correios Sede', 'initials' => 'CS'],
25
        '03' => ['name' => 'SE – ACRE', 'initials' => 'ACR'],
26
        '04' => ['name' => 'SE – ALAGOAS', 'initials' => 'AL'],
27
        '06' => ['name' => 'SE – AMAZONAS', 'initials' => 'AM'],
28
        '05' => ['name' => 'SE – AMAPÁ', 'initials' => 'AP'],
29
        '08' => ['name' => 'SE – BAHIA', 'initials' => 'BA'],
30
        '10' => ['name' => 'SE – BRASÍLIA', 'initials' => 'BSB'],
31
        '12' => ['name' => 'SE – CEARÁ', 'initials' => 'CE'],
32
        '14' => ['name' => 'SE - ESPIRITO SANTO', 'initials' => 'ES'],
33
        '16' => ['name' => 'SE – GOIÁS', 'initials' => 'GO'],
34
        '18' => ['name' => 'SE – MARANHÃO', 'initials' => 'MA'],
35
        '20' => ['name' => 'SE - MINAS GERAIS', 'initials' => 'MG'],
36
        '22' => ['name' => 'SE - MATO GROSSO DO SUL', 'initials' => 'MS'],
37
        '24' => ['name' => 'SE - MATO GROSSO', 'initials' => 'MT'],
38
        '28' => ['name' => 'SE – PARÁ', 'initials' => 'PA'],
39
        '30' => ['name' => 'SE – PARAÍBA', 'initials' => 'PB'],
40
        '32' => ['name' => 'SE – PERNAMBUCO', 'initials' => 'PE'],
41
        '34' => ['name' => 'SE – PIAUÍ', 'initials' => 'PI'],
42
        '36' => ['name' => 'SE – PARANÁ', 'initials' => 'PR'],
43
        '50' => ['name' => 'SE - RIO DE JANEIRO', 'initials' => 'RJ'],
44
        '60' => ['name' => 'SE - RIO GRANDE DO NORTE', 'initials' => 'RN'],
45
        '26' => ['name' => 'SE – RONDONIA', 'initials' => 'RO'],
46
        '65' => ['name' => 'SE – RORAIMA', 'initials' => 'RR'],
47
        '64' => ['name' => 'SE - RIO GRANDE DO SUL', 'initials' => 'RS'],
48
        '68' => ['name' => 'SE - SANTA CATARINA', 'initials' => 'SC'],
49
        '70' => ['name' => 'SE – SERGIPE', 'initials' => 'SE'],
50
        '74' => ['name' => 'SE - SÃO PAULO INTERIOR', 'initials' => 'SPI'],
51
        '72' => ['name' => 'SE - SÃO PAULO', 'initials' => 'SPM'],
52
        '75' => ['name' => 'SE- TOCANTINS', 'initials' => 'TO'],
53
    ];
54
55
    public function __construct()
56
    {
57
        $this->setSender(new Sender);
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getEnvironment()
64
    {
65
        return $this->environment;
66
    }
67
68
    /**
69
     * @param $cnpj
70
     *
71
     * @return $this
72
     */
73
    public function setCNPJ($cnpj)
74
    {
75
        $this->cnpj = $cnpj;
76
        return $this;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getCNPJ()
83
    {
84
        if (!$this->cnpj) {
85
            throw new InvalidArgumentException("Cnpj Code Card not set.");
86
        }
87
        return $this->cnpj;
88
    }
89
90
    /**
91
     * @param $user
92
     *
93
     * @return $this
94
     */
95
    public function setUser($user)
96
    {
97
        $this->user = $user;
98
        return $this;
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function getUser()
105
    {
106
        return $this->user;
107
    }
108
109
    /**
110
     * @param $userRastro
111
     *
112
     * @return $this
113
     */
114
    public function setUserRastro($userRastro)
115
    {
116
        $this->userRastro = $userRastro;
117
        return $this;
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    public function getUserRastro()
124
    {
125
        return $this->userRastro;
126
    }
127
128
    /**
129
     * @param $password
130
     *
131
     * @return $this
132
     */
133
    public function setPassword($password)
134
    {
135
        $this->password = $password;
136
        return $this;
137
    }
138
139
    /**
140
     * @return string
141
     */
142
    public function getPassword()
143
    {
144
        return $this->password;
145
    }
146
147
    /**
148
     * @param $passwordRastro
149
     *
150
     * @return $this
151
     */
152
    public function setPasswordRastro($passwordRastro)
153
    {
154
        $this->passwordRastro = $passwordRastro;
155
        return $this;
156
    }
157
158
    /**
159
     * @return string
160
     */
161
    public function getPasswordRastro()
162
    {
163
        return $this->passwordRastro;
164
    }
165
166
    /**
167
     * @param $administrativeCode
168
     *
169
     * @return $this
170
     */
171
    public function setAdministrativeCode($administrativeCode)
172
    {
173
        $this->administrativeCode = $administrativeCode;
174
        return $this;
175
    }
176
177
    /**
178
     * @return string
179
     */
180
    public function getAdministrativeCode()
181
    {
182
        if (!$this->administrativeCode) {
183
            throw new InvalidArgumentException("Administrative Code Card not set.");
184
        }
185
        return $this->administrativeCode;
186
    }
187
188
    /**
189
     * @param $contract
190
     *
191
     * @return $this
192
     */
193
    public function setContract($contract)
194
    {
195
        $this->contract = $contract;
196
        return $this;
197
    }
198
199
    /**
200
     * @return string
201
     */
202
    public function getContract()
203
    {
204
        if (!$this->contract) {
205
            throw new InvalidArgumentException("Contract Card not set.");
206
        }
207
        return $this->contract;
208
    }
209
210
    /**
211
     * @param $postCard
212
     *
213
     * @return $this
214
     */
215
    public function setPostCard($postCard)
216
    {
217
        $this->postCard = $postCard;
218
        return $this;
219
    }
220
221
    /**
222
     * @return string
223
     */
224
    public function getPostCard()
225
    {
226
        if (!$this->postCard) {
227
            throw new InvalidArgumentException("Post Card not set.");
228
        }
229
        return $this->postCard;
230
    }
231
232
    /**
233
     * @param $direction
234
     *
235
     * @return $this
236
     */
237
    public function setDirection($direction)
238
    {
239
        $this->direction = $direction;
240
        return $this;
241
    }
242
243
    /**
244
     * @return string
245
     */
246
    public function getDirection()
247
    {
248
        if (!$this->direction) {
249
            throw new InvalidArgumentException("Direction not set.");
250
        }
251
        return $this->direction;
252
    }
253
254
    /**
255
     * @param null $key
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $key is correct as it would always require null to be passed?
Loading history...
256
     *
257
     * @return array
258
     */
259
    public function getDirectories($key = null)
260
    {
261
        if (is_null($key)) {
0 ignored issues
show
introduced by
The condition is_null($key) is always true.
Loading history...
262
            return $this->directories;
263
        }
264
        if (array_key_exists($key, $this->directories)) {
265
            return $this->directories[$key];
266
        }
267
        throw new InvalidArgumentException("Key $key is not a valid direction.");
268
    }
269
270
    /**
271
     * @return string
272
     */
273
    public function getDirectionName()
274
    {
275
        return $this->getDirectories($this->getDirection())['name'];
276
    }
277
278
    /**
279
     * @return string
280
     */
281
    public function getDirectionInitials()
282
    {
283
        return $this->getDirectories($this->getDirection())['initials'];
284
    }
285
286
    /**
287
     * @param $sender
288
     *
289
     * @return $this
290
     */
291
    public function setSender(Sender $sender)
292
    {
293
        $this->sender = $sender;
294
        return $this;
295
    }
296
297
    /**
298
     * @return Sender
299
     */
300
    public function getSender()
301
    {
302
        if (!$this->sender) {
303
            throw new InvalidArgumentException("Sender Code Card not set.");
304
        }
305
        return $this->sender;
306
    }
307
}
308