Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
87 / 87 |
|
100.00% |
42 / 42 |
CRAP | |
100.00% |
1 / 1 |
| Address | |
100.00% |
87 / 87 |
|
100.00% |
42 / 42 |
57 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
5 | |||
| setFirstName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getFirstName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasFirstName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setLastName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getLastName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasLastName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setCompany | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getCompany | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasCompany | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setAddress1 | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getAddress1 | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasAddress1 | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setAddress2 | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getAddress2 | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasAddress2 | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setCity | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getCity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasCity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setState | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getState | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasState | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setPostalCode | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getPostalCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasPostalCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setCountry | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getCountry | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasCountry | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setPhone | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getPhone | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasPhone | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setResidential | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| isResidential | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| toArray | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __set | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| __get | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| __isset | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| __unset | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| offsetExists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| offsetGet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| offsetSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| offsetUnset | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <dev@noladev.com> |
| 8 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Shipping; |
| 16 | |
| 17 | /** |
| 18 | * Pop shipping address class |
| 19 | * |
| 20 | * @category Pop |
| 21 | * @package Pop\Shipping |
| 22 | * @author Nick Sagona, III <dev@noladev.com> |
| 23 | * @copyright Copyright (c) 2009-2027 NOLA Interactive, LLC. |
| 24 | * @license https://www.popphp.org/license New BSD License |
| 25 | * @version 4.0.0 |
| 26 | */ |
| 27 | class Address implements \ArrayAccess |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * Address data |
| 32 | * @var array |
| 33 | */ |
| 34 | protected array $data = [ |
| 35 | 'first_name' => null, |
| 36 | 'last_name' => null, |
| 37 | 'company' => null, |
| 38 | 'address1' => null, |
| 39 | 'address2' => null, |
| 40 | 'city' => null, |
| 41 | 'state' => null, |
| 42 | 'postal_code' => null, |
| 43 | 'country' => null, |
| 44 | 'phone' => null, |
| 45 | 'residential' => false, |
| 46 | ]; |
| 47 | |
| 48 | /** |
| 49 | * Constructor |
| 50 | * |
| 51 | * Instantiate the shipping address object |
| 52 | * |
| 53 | * @param array $address |
| 54 | */ |
| 55 | public function __construct(array $address = []) |
| 56 | { |
| 57 | $this->data['first_name'] = $address['first_name'] ?? null; |
| 58 | $this->data['last_name'] = $address['last_name'] ?? null; |
| 59 | $this->data['company'] = $address['company'] ?? null; |
| 60 | $this->data['address1'] = $address['address1'] ?? null; |
| 61 | $this->data['address2'] = $address['address2'] ?? null; |
| 62 | $this->data['city'] = $address['city'] ?? null; |
| 63 | $this->data['country'] = $address['country'] ?? null; |
| 64 | $this->data['phone'] = $address['phone'] ?? null; |
| 65 | $this->data['residential'] = $address['residential'] ?? false; |
| 66 | |
| 67 | if (isset($address['province'])) { |
| 68 | $this->data['state'] = $address['province']; |
| 69 | } else if (isset($address['state'])) { |
| 70 | $this->data['state'] = $address['state']; |
| 71 | } |
| 72 | |
| 73 | if (isset($address['zip'])) { |
| 74 | $this->data['postal_code'] = $address['zip']; |
| 75 | } else if (isset($address['postal_code'])) { |
| 76 | $this->data['postal_code'] = $address['postal_code']; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Set first name |
| 82 | * |
| 83 | * @param string $firstName |
| 84 | * @return Address |
| 85 | */ |
| 86 | public function setFirstName(string $firstName): Address |
| 87 | { |
| 88 | $this->data['first_name'] = $firstName; |
| 89 | return $this; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Get first name |
| 94 | * |
| 95 | * @return mixed |
| 96 | */ |
| 97 | public function getFirstName(): mixed |
| 98 | { |
| 99 | return $this->data['first_name'] ?? null; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Has first name |
| 104 | * |
| 105 | * @return bool |
| 106 | */ |
| 107 | public function hasFirstName(): bool |
| 108 | { |
| 109 | return !empty($this->data['first_name']); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Set last name |
| 114 | * |
| 115 | * @param string $lastName |
| 116 | * @return Address |
| 117 | */ |
| 118 | public function setLastName(string $lastName): Address |
| 119 | { |
| 120 | $this->data['last_name'] = $lastName; |
| 121 | return $this; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Get last name |
| 126 | * |
| 127 | * @return mixed |
| 128 | */ |
| 129 | public function getLastName(): mixed |
| 130 | { |
| 131 | return $this->data['last_name'] ?? null; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Has last name |
| 136 | * |
| 137 | * @return bool |
| 138 | */ |
| 139 | public function hasLastName(): bool |
| 140 | { |
| 141 | return !empty($this->data['last_name']); |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Set company |
| 146 | * |
| 147 | * @param string $company |
| 148 | * @return Address |
| 149 | */ |
| 150 | public function setCompany(string $company): Address |
| 151 | { |
| 152 | $this->data['company'] = $company; |
| 153 | return $this; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Get company |
| 158 | * |
| 159 | * @return mixed |
| 160 | */ |
| 161 | public function getCompany(): mixed |
| 162 | { |
| 163 | return $this->data['company'] ?? null; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Has company |
| 168 | * |
| 169 | * @return bool |
| 170 | */ |
| 171 | public function hasCompany(): bool |
| 172 | { |
| 173 | return !empty($this->data['company']); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Set address 1 |
| 178 | * |
| 179 | * @param string $address1 |
| 180 | * @return Address |
| 181 | */ |
| 182 | public function setAddress1(string $address1): Address |
| 183 | { |
| 184 | $this->data['address1'] = $address1; |
| 185 | return $this; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Get address 1 |
| 190 | * |
| 191 | * @return mixed |
| 192 | */ |
| 193 | public function getAddress1(): mixed |
| 194 | { |
| 195 | return $this->data['address1'] ?? null; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Has address 1 |
| 200 | * |
| 201 | * @return bool |
| 202 | */ |
| 203 | public function hasAddress1(): bool |
| 204 | { |
| 205 | return !empty($this->data['address1']); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Set address 2 |
| 210 | * |
| 211 | * @param string $address2 |
| 212 | * @return Address |
| 213 | */ |
| 214 | public function setAddress2(string $address2): Address |
| 215 | { |
| 216 | $this->data['address2'] = $address2; |
| 217 | return $this; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Get address 2 |
| 222 | * |
| 223 | * @return mixed |
| 224 | */ |
| 225 | public function getAddress2(): mixed |
| 226 | { |
| 227 | return $this->data['address2'] ?? null; |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Has address 2 |
| 232 | * |
| 233 | * @return bool |
| 234 | */ |
| 235 | public function hasAddress2(): bool |
| 236 | { |
| 237 | return !empty($this->data['address2']); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Set city |
| 242 | * |
| 243 | * @param string $city |
| 244 | * @return Address |
| 245 | */ |
| 246 | public function setCity(string $city): Address |
| 247 | { |
| 248 | $this->data['city'] = $city; |
| 249 | return $this; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Get city |
| 254 | * |
| 255 | * @return mixed |
| 256 | */ |
| 257 | public function getCity(): mixed |
| 258 | { |
| 259 | return $this->data['city'] ?? null; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Has city |
| 264 | * |
| 265 | * @return bool |
| 266 | */ |
| 267 | public function hasCity(): bool |
| 268 | { |
| 269 | return !empty($this->data['city']); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Set state |
| 274 | * |
| 275 | * @param string $state |
| 276 | * @return Address |
| 277 | */ |
| 278 | public function setState(string $state): Address |
| 279 | { |
| 280 | $this->data['state'] = $state; |
| 281 | return $this; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Get state |
| 286 | * |
| 287 | * @return mixed |
| 288 | */ |
| 289 | public function getState(): mixed |
| 290 | { |
| 291 | return $this->data['state'] ?? null; |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Has state |
| 296 | * |
| 297 | * @return bool |
| 298 | */ |
| 299 | public function hasState(): bool |
| 300 | { |
| 301 | return !empty($this->data['state']); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Set postal code |
| 306 | * |
| 307 | * @param string $postalCode |
| 308 | * @return Address |
| 309 | */ |
| 310 | public function setPostalCode(string $postalCode): Address |
| 311 | { |
| 312 | $this->data['postal_code'] = $postalCode; |
| 313 | return $this; |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Get postal code |
| 318 | * |
| 319 | * @return mixed |
| 320 | */ |
| 321 | public function getPostalCode(): mixed |
| 322 | { |
| 323 | return $this->data['postal_code'] ?? null; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Has postal code |
| 328 | * |
| 329 | * @return bool |
| 330 | */ |
| 331 | public function hasPostalCode(): bool |
| 332 | { |
| 333 | return !empty($this->data['postal_code']); |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Set country |
| 338 | * |
| 339 | * @param string $country |
| 340 | * @return Address |
| 341 | */ |
| 342 | public function setCountry(string $country): Address |
| 343 | { |
| 344 | $this->data['country'] = $country; |
| 345 | return $this; |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Get country |
| 350 | * |
| 351 | * @return mixed |
| 352 | */ |
| 353 | public function getCountry(): mixed |
| 354 | { |
| 355 | return $this->data['country'] ?? null; |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * Has country |
| 360 | * |
| 361 | * @return bool |
| 362 | */ |
| 363 | public function hasCountry(): bool |
| 364 | { |
| 365 | return !empty($this->data['country']); |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Set phone |
| 370 | * |
| 371 | * @param string $phone |
| 372 | * @return Address |
| 373 | */ |
| 374 | public function setPhone(string $phone): Address |
| 375 | { |
| 376 | $this->data['phone'] = $phone; |
| 377 | return $this; |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Get phone |
| 382 | * |
| 383 | * @return mixed |
| 384 | */ |
| 385 | public function getPhone(): mixed |
| 386 | { |
| 387 | return $this->data['phone'] ?? null; |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Has phone |
| 392 | * |
| 393 | * @return bool |
| 394 | */ |
| 395 | public function hasPhone(): bool |
| 396 | { |
| 397 | return !empty($this->data['phone']); |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Set residential |
| 402 | * |
| 403 | * @param bool $residential |
| 404 | * @return Address |
| 405 | */ |
| 406 | public function setResidential(bool $residential): Address |
| 407 | { |
| 408 | $this->data['residential'] = $residential; |
| 409 | return $this; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Is residential |
| 414 | * |
| 415 | * @return bool |
| 416 | */ |
| 417 | public function isResidential(): bool |
| 418 | { |
| 419 | return (array_key_exists('residential', $this->data) ? $this->data['residential'] : false); |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Address to array |
| 424 | * |
| 425 | * @return array |
| 426 | */ |
| 427 | public function toArray(): array |
| 428 | { |
| 429 | return $this->data; |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Magic method to set the property to the value of $this->rowGateway[$name] |
| 434 | * |
| 435 | * @param string $name |
| 436 | * @param mixed $value |
| 437 | * @return void |
| 438 | */ |
| 439 | public function __set(string $name, mixed $value) |
| 440 | { |
| 441 | if ($name == 'zip') { |
| 442 | $name = 'postal_code'; |
| 443 | } else if ($name == 'province') { |
| 444 | $name = 'state'; |
| 445 | } |
| 446 | |
| 447 | if (array_key_exists($name, $this->data)) { |
| 448 | $this->data[$name] = $value; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Magic method to return the value of $this->rowGateway[$name] |
| 454 | * |
| 455 | * @param string $name |
| 456 | * @return mixed |
| 457 | */ |
| 458 | public function __get(string $name): mixed |
| 459 | { |
| 460 | if ($name == 'zip') { |
| 461 | $name = 'postal_code'; |
| 462 | } else if ($name == 'province') { |
| 463 | $name = 'state'; |
| 464 | } |
| 465 | return $this->data[$name] ?? null; |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * Magic method to return the isset value of $this->rowGateway[$name] |
| 470 | * |
| 471 | * @param string $name |
| 472 | * @return bool |
| 473 | */ |
| 474 | public function __isset(string $name): bool |
| 475 | { |
| 476 | if ($name == 'zip') { |
| 477 | $name = 'postal_code'; |
| 478 | } else if ($name == 'province') { |
| 479 | $name = 'state'; |
| 480 | } |
| 481 | |
| 482 | return !empty($this->data[$name]); |
| 483 | } |
| 484 | |
| 485 | /** |
| 486 | * Magic method to unset $this->rowGateway[$name] |
| 487 | * |
| 488 | * @param string $name |
| 489 | * @return void |
| 490 | */ |
| 491 | public function __unset(string $name): void |
| 492 | { |
| 493 | if ($name == 'zip') { |
| 494 | $name = 'postal_code'; |
| 495 | } else if ($name == 'province') { |
| 496 | $name = 'state'; |
| 497 | } |
| 498 | |
| 499 | if (array_key_exists($name, $this->data)) { |
| 500 | $this->data[$name] = null; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * ArrayAccess offsetExists |
| 506 | * |
| 507 | * @param mixed $offset |
| 508 | * @return bool |
| 509 | */ |
| 510 | public function offsetExists(mixed $offset): bool |
| 511 | { |
| 512 | return $this->__isset($offset); |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * ArrayAccess offsetGet |
| 517 | * |
| 518 | * @param mixed $offset |
| 519 | * @return mixed |
| 520 | */ |
| 521 | public function offsetGet(mixed $offset): mixed |
| 522 | { |
| 523 | return $this->__get($offset); |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * ArrayAccess offsetSet |
| 528 | * |
| 529 | * @param mixed $offset |
| 530 | * @param mixed $value |
| 531 | * @return void |
| 532 | */ |
| 533 | public function offsetSet(mixed $offset, mixed $value): void |
| 534 | { |
| 535 | $this->__set($offset, $value); |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * ArrayAccess offsetUnset |
| 540 | * |
| 541 | * @param mixed $offset |
| 542 | * @return void |
| 543 | */ |
| 544 | public function offsetUnset(mixed $offset): void |
| 545 | { |
| 546 | $this->__unset($offset); |
| 547 | } |
| 548 | |
| 549 | } |