Customer::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 5

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
nc 5
nop 2
dl 0
loc 14
rs 10
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
9
/**
10
 * An entity representing a customer.
11
 */
12
class Customer extends BaseResource
13
{
14
  //--------------------------------------------------------------------------------------------------------------------
15
  /**
16
   * @var CustomerAddress
17
   */
18
  public $address;
19
20
  /**
21
   * @var CustomerEmail
22
   */
23
  public $email;
24
25
  /**
26
   * @var CustomerName
27
   */
28
  public $name;
29
30
  /**
31
   * @var CustomerPhone
32
   */
33
  public $phone;
34
35
  //--------------------------------------------------------------------------------------------------------------------
36
  /**
37
   * Object constructor.
38
   *
39
   * @param ClubCollectApiClient $client   The API client.
40
   * @param array                $response The API response.
41
   *
42
   * @throws ClubCollectApiException
43
   */
44
  public function __construct(ClubCollectApiClient $client, array $response)
45
  {
46
    parent::__construct($client);
47
48
    try
49
    {
50
      $this->address = new CustomerAddress($client, $response['address']);
51
      $this->email   = new CustomerEmail($client, $response['email']);
52
      $this->name    = new CustomerName($client, $response['name']);
53
      $this->phone   = new CustomerPhone($client, $response['phone']);
54
    }
55
    catch (\Throwable $exception)
56
    {
57
      throw new ClubCollectApiException([$exception], 'Failed to create a customer email address');
58
    }
59
  }
60
61
  //--------------------------------------------------------------------------------------------------------------------
62
}
63
64
//----------------------------------------------------------------------------------------------------------------------
65