CustomerAddress::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 9

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
nc 9
nop 2
dl 0
loc 18
rs 9.8666
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace SetBased\ClubCollect\Resource;
5
6
use SetBased\ClubCollect\ClubCollectApiClient;
7
use SetBased\ClubCollect\Exception\ClubCollectApiException;
8
use SetBased\ClubCollect\Helper\Cast;
9
10
/**
11
 * An entity representing the address of a customer.
12
 */
13
class CustomerAddress extends BaseResource
14
{
15
  //--------------------------------------------------------------------------------------------------------------------
16
  /**
17
   * @var string|null
18
   */
19
  public $address1;
20
21
  /**
22
   * @var string|null
23
   */
24
  public $address2;
25
26
  /**
27
   * @var string|null
28
   */
29
  public $city;
30
31
  /**
32
   * @var string|null
33
   */
34
  public $countryCode;
35
36
  /**
37
   * @var string|null
38
   */
39
  public $houseNumber;
40
41
  /**
42
   * @var string|null
43
   */
44
  public $locality;
45
46
  /**
47
   * @var string|null
48
   */
49
  public $state;
50
51
  /**
52
   * @var string|null
53
   */
54
  public $zipCode;
55
56
  //--------------------------------------------------------------------------------------------------------------------
57
  /**
58
   * Object constructor.
59
   *
60
   * @param ClubCollectApiClient $client   The API client.
61
   * @param array                $response The API response.
62
   *
63
   * @throws ClubCollectApiException
64
   */
65
  public function __construct(ClubCollectApiClient $client, array $response)
66
  {
67
    parent::__construct($client);
68
69
    try
70
    {
71
      $this->address1    = Cast::toOptString($response['address1']);
72
      $this->address2    = Cast::toOptString($response['address2']);
73
      $this->city        = Cast::toOptString($response['city']);
74
      $this->countryCode = Cast::toOptString($response['country_code']);
75
      $this->houseNumber = Cast::toOptString($response['house_number']);
76
      $this->locality    = Cast::toOptString($response['locality']);
77
      $this->state       = Cast::toOptString($response['state']);
78
      $this->zipCode     = Cast::toOptString($response['zipcode']);
79
    }
80
    catch (\Throwable $exception)
81
    {
82
      throw new ClubCollectApiException([$exception], 'Failed to create a customer address');
83
    }
84
  }
85
86
  //--------------------------------------------------------------------------------------------------------------------
87
}
88
89
//----------------------------------------------------------------------------------------------------------------------
90