Completed
Pull Request — master (#105)
by Tom
02:40
created

VCardAddress::parser()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 30
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 24
nc 4
nop 3
1
<?php
2
3
namespace JeroenDesloovere\VCard\Model;
4
5
use JeroenDesloovere\VCard\Exception\InvalidVersionException;
6
7
/**
8
 * Class VCardAddress
9
 *
10
 * @package JeroenDesloovere\VCard\Model
11
 */
12
class VCardAddress
13
{
14
    /**
15
     * @var string|null
16
     */
17
    protected $name;
18
19
    /**
20
     * @var string|null
21
     */
22
    protected $extended;
23
24
    /**
25
     * @var string|null
26
     */
27
    protected $street;
28
29
    /**
30
     * @var string|null
31
     */
32
    protected $locality;
33
34
    /**
35
     * @var string|null
36
     */
37
    protected $region;
38
39
    /**
40
     * @var string|null
41
     */
42
    protected $postalCode;
43
44
    /**
45
     * @var string|null
46
     */
47
    protected $country;
48
49
    /**
50
     * @var string|null
51
     */
52
    protected $label;
53
54
    /**
55
     * @return string|null
56
     */
57
    public function getName(): ?string
58
    {
59
        return $this->name;
60
    }
61
62
    /**
63
     * @param string|null $name
64
     */
65
    public function setName(?string $name): void
66
    {
67
        $this->name = $name;
68
    }
69
70
    /**
71
     * @return string|null
72
     */
73
    public function getExtended(): ?string
74
    {
75
        return $this->extended;
76
    }
77
78
    /**
79
     * @param string|null $extended
80
     */
81
    public function setExtended(?string $extended): void
82
    {
83
        $this->extended = $extended;
84
    }
85
86
    /**
87
     * @return string|null
88
     */
89
    public function getStreet(): ?string
90
    {
91
        return $this->street;
92
    }
93
94
    /**
95
     * @param string|null $street
96
     */
97
    public function setStreet(?string $street): void
98
    {
99
        $this->street = $street;
100
    }
101
102
    /**
103
     * @return string|null
104
     */
105
    public function getLocality(): ?string
106
    {
107
        return $this->locality;
108
    }
109
110
    /**
111
     * @param string|null $locality
112
     */
113
    public function setLocality(?string $locality): void
114
    {
115
        $this->locality = $locality;
116
    }
117
118
    /**
119
     * @return string|null
120
     */
121
    public function getRegion(): ?string
122
    {
123
        return $this->region;
124
    }
125
126
    /**
127
     * @param string|null $region
128
     */
129
    public function setRegion(?string $region): void
130
    {
131
        $this->region = $region;
132
    }
133
134
    /**
135
     * @return string|null
136
     */
137
    public function getPostalCode(): ?string
138
    {
139
        return $this->postalCode;
140
    }
141
142
    /**
143
     * @param string|null $postalCode
144
     */
145
    public function setPostalCode(?string $postalCode): void
146
    {
147
        $this->postalCode = $postalCode;
148
    }
149
150
    /**
151
     * @return string|null
152
     */
153
    public function getCountry(): ?string
154
    {
155
        return $this->country;
156
    }
157
158
    /**
159
     * @param string|null $country
160
     */
161
    public function setCountry(?string $country): void
162
    {
163
        $this->country = $country;
164
    }
165
166
    /**
167
     * @return string|null
168
     */
169
    public function getLabel(): ?string
170
    {
171
        return $this->label;
172
    }
173
174
    /**
175
     * @param string|null $label
176
     */
177
    public function setLabel(?string $label): void
178
    {
179
        $this->label = $label;
180
    }
181
182
    /**
183
     * @param string $version
184
     * @param string $key
185
     * @param string $value
186
     *
187
     * @throws InvalidVersionException
188
     */
189
    public function parser(string $version, string $key, string $value): void
190
    {
191
        if ($version === '3.0') {
192
            $this->setLabel($key);
193
        } elseif ($version === '4.0') {
194
            if (strpos($key, 'LABEL=') !== false) {
195
                $this->setLabel($key);
196
            }
197
        } else {
198
            throw new InvalidVersionException();
199
        }
200
201
        @list(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
202
            $name,
203
            $extended,
204
            $street,
205
            $locality,
206
            $region,
207
            $postalCode,
208
            $country,
209
            ) = explode(';', $value);
210
211
        $this->setName($name);
212
        $this->setExtended($extended);
213
        $this->setStreet($street);
214
        $this->setLocality($locality);
215
        $this->setRegion($region);
216
        $this->setPostalCode($postalCode);
217
        $this->setCountry($country);
218
    }
219
220
    /**
221
     * @return string
222
     */
223
    public function getAddress(): string
224
    {
225
        return $this->getName().';'.$this->getExtended().';'.$this->getStreet().';'.$this->getLocality().';'.$this->getRegion().';'.$this->getPostalCode().';'.$this->getCountry();
226
    }
227
}
228