InvoiceLine::__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 a line in an invoice.
12
 */
13
class InvoiceLine extends BaseResource
14
{
15
  //--------------------------------------------------------------------------------------------------------------------
16
  /**
17
   * @var int
18
   */
19
  public $amountCents;
20
21
  /**
22
   * @var \DateTime
23
   */
24
  public $date;
25
26
  /**
27
   * @var string
28
   */
29
  public $description;
30
31
  /**
32
   * @var string
33
   */
34
  public $invoiceLineId;
35
36
  /**
37
   * @var string
38
   */
39
  public $type;
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->amountCents   = Cast::toManInt($response['amount_cents']);
57
      $this->date          = Cast::toManDateTime($response['date']);
58
      $this->description   = Cast::toOptString($response['description']);
59
      $this->invoiceLineId = Cast::toManString($response['invoice_line_id']);
60
      $this->type          = Cast::toManString($response['type']);
61
    }
62
    catch (\Throwable $exception)
63
    {
64
      throw new ClubCollectApiException([$exception], 'Failed to create an invoice line');
65
    }
66
  }
67
68
  //--------------------------------------------------------------------------------------------------------------------
69
}
70
71
//----------------------------------------------------------------------------------------------------------------------
72