Import::isTransmitted()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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 import, which is a collection of Invoices.
12
 */
13
class Import extends BaseResource
14
{
15
  //--------------------------------------------------------------------------------------------------------------------
16
  /**
17
   * @var string
18
   */
19
  public $companyId;
20
21
  /**
22
   * @var string
23
   */
24
  public $importId;
25
26
  /**
27
   * The invoice numbers of the invoices that imported under this Import. When this Import is retrieved with
28
   * ImportEndpoint::fetch() the value will an array which might be empty. However, when this import is retrieved with
29
   * ImportEndpoint::fetchAll() the value will be null even when there are invoices under the import.
30
   *
31
   * @var string[]|null
32
   */
33
  public $invoiceIds;
34
35
  /**
36
   * @var string
37
   */
38
  public $title;
39
40
  /**
41
   * @var bool
42
   */
43
  public $transmitted;
44
45
  /**
46
   * @var \DateTime
47
   */
48
  public $transmittedAt;
49
50
  //--------------------------------------------------------------------------------------------------------------------
51
  /**
52
   * Object constructor.
53
   *
54
   * @param ClubCollectApiClient $client   The API client.
55
   * @param array                $response The API response.
56
   *
57
   * @throws ClubCollectApiException
58
   */
59
  public function __construct(ClubCollectApiClient $client, array $response)
60
  {
61
    parent::__construct($client);
62
63
    try
64
    {
65
      $this->companyId     = Cast::toManString($response['company_id']);
66
      $this->importId      = Cast::toManString($response['import_id']);
67
      $this->title         = Cast::toManString($response['title']);
68
      $this->transmitted   = Cast::toManBool($response['transmitted']);
69
      $this->transmittedAt = Cast::toOptDateTime($response['transmitted_at']);
70
71
      if (is_array($response['invoice_ids'] ?? null))
72
      {
73
        $this->invoiceIds = [];
74
        foreach ($response['invoice_ids'] as $id)
75
        {
76
          $this->invoiceIds[] = Cast::toManString($id);
77
        }
78
      }
79
      else
80
      {
81
        $this->invoiceIds = null;
82
      }
83
    }
84
    catch (\Throwable $exception)
85
    {
86
      throw new ClubCollectApiException([$exception], 'Failed to create an import');
87
    }
88
  }
89
90
  //--------------------------------------------------------------------------------------------------------------------
91
  /**
92
   * Returns true if the import has been transmitted. Otherwise, returns false.
93
   *
94
   * @return bool
95
   */
96
  public function isTransmitted(): bool
97
  {
98
    return $this->transmitted;
99
  }
100
101
  //--------------------------------------------------------------------------------------------------------------------
102
}
103
104
//----------------------------------------------------------------------------------------------------------------------
105