Test Failed
Push — master ( 6512d2...c62a67 )
by P.R.
02:58 queued 11s
created

Invoice   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 42
dl 0
loc 141
rs 10
c 1
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 40 5
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 an invoice.
12
 */
13
class Invoice extends BaseResource
14
{
15
  //--------------------------------------------------------------------------------------------------------------------
16
  /**
17
   * @var int
18
   */
19
  public $amountTotalCents;
20
21
  /**
22
   * @var string|null
23
   */
24
  public $clubMembershipNumber;
25
26
  /**
27
   * @var Customer
28
   */
29
  public $customer;
30
31
  /**
32
   * @var string|null
33
   */
34
  public $directDebitIban;
35
36
  /**
37
   * @var string|null
38
   */
39
  public $externalInvoiceNumber;
40
41
  /**
42
   * @var string|null
43
   */
44
  public $federationMembershipNumber;
45
46
  /**
47
   * Import ID, supplied by ClubCollect.
48
   *
49
   * @var string
50
   */
51
  public $importId;
52
53
  /**
54
   * Invoice ID, supplied by ClubCollect.
55
   *
56
   * @var string
57
   */
58
  public $invoiceId;
59
60
  /**
61
   * @var InvoiceLine[]
62
   */
63
  public $invoiceLines = [];
64
65
  /**
66
   * @var string
67
   */
68
  public $invoiceNumber;
69
70
  /**
71
   * @var string|null
72
   */
73
  public $locale;
74
75
  /**
76
   * @var Message[]
77
   */
78
  public $messages = [];
79
80
  /**
81
   * @var string|null
82
   */
83
  public $reference;
84
85
  /**
86
   * @var \DateTime|null
87
   */
88
  public $retractedAt;
89
90
  /**
91
   * @var string|null
92
   */
93
  public $retractionReason;
94
95
  /**
96
   * @var bool
97
   */
98
  public $showRetractionReasonToCustomer;
99
100
  /**
101
   * @var Ticket[]
102
   */
103
  public $tickets = [];
104
105
  //--------------------------------------------------------------------------------------------------------------------
106
  /**
107
   * Object constructor.
108
   *
109
   * @param ClubCollectApiClient $client   The API client.
110
   * @param array                $response The API response.
111
   *
112
   * @throws ClubCollectApiException
113
   */
114
  public function __construct(ClubCollectApiClient $client, array $response)
115
  {
116
    parent::__construct($client);
117
118
    try
119
    {
120
      $this->amountTotalCents               = Cast::toManInt($response['amount_total_cents']);
121
      $this->clubMembershipNumber           = Cast::toOptString($response['club_membership_number']);
122
      $this->directDebitIban                = Cast::toOptString($response['direct_debit_iban']);
123
      $this->externalInvoiceNumber          = Cast::toOptString($response['external_invoice_number']);
124
      $this->federationMembershipNumber     = Cast::toOptString($response['federation_membership_number']);
125
      $this->importId                       = Cast::toManString($response['import_id']);
126
      $this->invoiceId                      = Cast::toManString($response['invoice_id']);
127
      $this->invoiceNumber                  = Cast::toManString($response['invoice_number']);
128
      $this->locale                         = Cast::toOptString($response['locale']);
129
      $this->reference                      = Cast::toOptString($response['reference']);
130
      $this->retractedAt                    = Cast::toOptDateTime($response['retracted_at']);
131
      $this->retractionReason               = Cast::toOptString($response['retraction_reason']);
132
      $this->showRetractionReasonToCustomer = Cast::toManBool($response['show_retraction_reason_to_customer']);
133
134
      $this->customer = new Customer($client, $response['customer']);
135
136
      foreach ($response['invoice_lines'] as $line)
137
      {
138
        $this->invoiceLines[] = new InvoiceLine($client, $line);
139
      }
140
141
      foreach ($response['messages'] as $line)
142
      {
143
        $this->messages[] = new Message($client, $line);
144
      }
145
146
      foreach ($response['tickets'] as $line)
147
      {
148
        $this->tickets[] = new Ticket($client, $line);
149
      }
150
    }
151
    catch (\Throwable $exception)
152
    {
153
      throw new ClubCollectApiException([$exception], 'Failed to create an invoice');
154
    }
155
  }
156
157
  //--------------------------------------------------------------------------------------------------------------------
158
}
159
160
//----------------------------------------------------------------------------------------------------------------------
161