Ticket   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 53
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 2
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 ticket.
12
 */
13
class Ticket extends BaseResource
14
{
15
  //--------------------------------------------------------------------------------------------------------------------
16
  /**
17
   * @var \DateTime
18
   */
19
  public $date;
20
21
  /**
22
   * @var string
23
   */
24
  public $invoiceId;
25
26
  /**
27
   * @var string
28
   */
29
  public $message;
30
31
  /**
32
   * @var string
33
   */
34
  public $sender;
35
36
  /**
37
   * @var string
38
   */
39
  public $ticketId;
40
41
  //--------------------------------------------------------------------------------------------------------------------
42
  /**
43
   * Object constructor.
44
   *
45
   * @param ClubCollectApiClient $client    The API client.
46
   * @param array                $response  The API response.
47
   * @param string|null          $invoiceId The Id of the current invoice for which we are manipulating tickets
48
   *
49
   * @throws ClubCollectApiException
50
   */
51
  public function __construct(ClubCollectApiClient $client, array $response, ?string $invoiceId)
52
  {
53
    parent::__construct($client);
54
55
    try
56
    {
57
      $this->date      = Cast::toManDateTime($response['date']);
58
      $this->invoiceId = Cast::toOptString($response['invoice_id'] ?? null, $invoiceId);
59
      $this->message   = Cast::toManString($response['message']);
60
      $this->sender    = Cast::toManString($response['sender']);
61
      $this->ticketId  = Cast::toManString($response['ticket_id']);
62
    }
63
    catch (\Throwable $exception)
64
    {
65
      throw new ClubCollectApiException([$exception], 'Failed to create a ticket');
66
    }
67
  }
68
69
  //--------------------------------------------------------------------------------------------------------------------
70
}
71
72
//----------------------------------------------------------------------------------------------------------------------
73