1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OceanApplications\Postmen\Models; |
4
|
|
|
|
5
|
|
|
class Address extends Model |
6
|
|
|
{ |
7
|
|
|
public $country; |
8
|
|
|
public $contact_name; |
9
|
|
|
public $phone; |
10
|
|
|
public $fax; |
11
|
|
|
public $email; |
12
|
|
|
public $company_name; |
13
|
|
|
public $street1; |
14
|
|
|
public $street2; |
15
|
|
|
public $street3; |
16
|
|
|
public $city; |
17
|
|
|
public $state; |
18
|
|
|
public $postal_code; |
19
|
|
|
public $type = 'residential'; |
20
|
|
|
public $tax_id; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param string $value |
24
|
|
|
* |
25
|
|
|
* @throws \Exception |
26
|
|
|
* |
27
|
|
|
* @return $this |
28
|
|
|
*/ |
29
|
|
View Code Duplication |
public function country($value) |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
if (in_array($value, $this->acceptedCountries)) { |
32
|
|
|
$this->country = $value; |
33
|
|
|
} else { |
34
|
|
|
$error = 'Country code invalid or not serviceable'; |
35
|
|
|
throw new \Exception($error); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $this; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $value |
43
|
|
|
* |
44
|
|
|
* @return $this |
45
|
|
|
*/ |
46
|
|
|
public function contact_name($value) |
47
|
|
|
{ |
48
|
|
|
$this->contact_name = strval($value); |
49
|
|
|
|
50
|
|
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $value |
55
|
|
|
* |
56
|
|
|
* @return $this |
57
|
|
|
*/ |
58
|
|
|
public function phone($value) |
59
|
|
|
{ |
60
|
|
|
$this->phone = strval($value); |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $value |
67
|
|
|
* |
68
|
|
|
* @return $this |
69
|
|
|
*/ |
70
|
|
|
public function fax($value) |
71
|
|
|
{ |
72
|
|
|
$this->fax = strval($value); |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $value |
79
|
|
|
* |
80
|
|
|
* @return $this |
81
|
|
|
*/ |
82
|
|
|
public function email($value) |
83
|
|
|
{ |
84
|
|
|
$this->email = strval($value); |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $value |
91
|
|
|
* |
92
|
|
|
* @return $this |
93
|
|
|
*/ |
94
|
|
|
public function company_name($value) |
95
|
|
|
{ |
96
|
|
|
$this->company_name = strval($value); |
97
|
|
|
|
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param string $value |
103
|
|
|
* |
104
|
|
|
* @return $this |
105
|
|
|
*/ |
106
|
|
|
public function street1($value) |
107
|
|
|
{ |
108
|
|
|
$this->street1 = strval($value); |
109
|
|
|
|
110
|
|
|
return $this; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $value |
115
|
|
|
* |
116
|
|
|
* @return $this |
117
|
|
|
*/ |
118
|
|
|
public function street2($value) |
119
|
|
|
{ |
120
|
|
|
if (empty($value)) { |
121
|
|
|
$this->street2 = null; |
122
|
|
|
} else { |
123
|
|
|
$this->street2 = strval($value); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $value |
131
|
|
|
* |
132
|
|
|
* @return $this |
133
|
|
|
*/ |
134
|
|
|
public function street3($value) |
135
|
|
|
{ |
136
|
|
|
if (empty($value)) { |
137
|
|
|
$this->street3 = null; |
138
|
|
|
} else { |
139
|
|
|
$this->street3 = strval($value); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param string $value |
147
|
|
|
* |
148
|
|
|
* @return $this |
149
|
|
|
*/ |
150
|
|
|
public function city($value) |
151
|
|
|
{ |
152
|
|
|
$this->city = strval($value); |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @param string $value |
159
|
|
|
* |
160
|
|
|
* @return $this |
161
|
|
|
*/ |
162
|
|
|
public function state($value) |
163
|
|
|
{ |
164
|
|
|
$this->state = strval($value); |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param string $value |
171
|
|
|
* |
172
|
|
|
* @return $this |
173
|
|
|
*/ |
174
|
|
|
public function postal_code($value) |
175
|
|
|
{ |
176
|
|
|
$this->postal_code = strval($value); |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param string $value |
183
|
|
|
* |
184
|
|
|
* @throws \Exception |
185
|
|
|
* |
186
|
|
|
* @return $this |
187
|
|
|
*/ |
188
|
|
|
public function type($value) |
189
|
|
|
{ |
190
|
|
|
if ($value != 'residential' || $value != 'business') { |
191
|
|
|
$error = 'Type must be residential or business.'; |
192
|
|
|
throw new \Exception($error); |
193
|
|
|
} |
194
|
|
|
$this->type = $value; |
195
|
|
|
|
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param string $value |
201
|
|
|
* |
202
|
|
|
* @return $this |
203
|
|
|
*/ |
204
|
|
|
public function tax_id($value) |
205
|
|
|
{ |
206
|
|
|
$this->tax_id = strval($value); |
207
|
|
|
|
208
|
|
|
return $this; |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.