CustomerName::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 6

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
nc 6
nop 2
dl 0
loc 15
rs 9.9666
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 name of a customer.
12
 */
13
class CustomerName extends BaseResource
14
{
15
  //--------------------------------------------------------------------------------------------------------------------
16
  /**
17
   * @var string|null
18
   */
19
  public $firstName;
20
21
  /**
22
   * @var string|null
23
   */
24
  public $infix;
25
26
  /**
27
   * @var string
28
   */
29
  public $lastName;
30
31
  /**
32
   * @var string|null
33
   */
34
  public $organization;
35
36
  /**
37
   * @var string|null
38
   */
39
  public $prefix;
40
41
  //--------------------------------------------------------------------------------------------------------------------
42
  /**
43
   * Object constructor.
44
   *
45
   * @param ClubCollectApiClient $client   The API client.
46
   * @param array                $response The API response.
47
   *
48
   * @throws ClubCollectApiException
49
   */
50
  public function __construct(ClubCollectApiClient $client, array $response)
51
  {
52
    parent::__construct($client);
53
54
    try
55
    {
56
      $this->firstName    = Cast::toOptString($response['first_name']);
57
      $this->infix        = Cast::toOptString($response['infix']);
58
      $this->lastName     = Cast::toManString($response['last_name']);
59
      $this->organization = Cast::toOptString($response['organization']);
60
      $this->prefix       = Cast::toOptString($response['prefix']);
61
    }
62
    catch (\Throwable $exception)
63
    {
64
      throw new ClubCollectApiException([$exception], 'Failed to create a customer name');
65
    }
66
  }
67
68
  //--------------------------------------------------------------------------------------------------------------------
69
}
70
71
//----------------------------------------------------------------------------------------------------------------------
72