Invoice::__get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
// ---------------------------------------------------------------------
4
//
5
//  Copyright (C) 2018-2024 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <https://opensource.org/licenses/MIT>.
9
//
10
// ---------------------------------------------------------------------
11
12
namespace Linode\Account;
13
14
use Linode\Account\Repository\InvoiceItemRepository;
15
use Linode\Entity;
16
17
/**
18
 * Account Invoice object.
19
 *
20
 * @property int                            $id             The Invoice's unique ID.
21
 * @property string                         $date           When this Invoice was generated.
22
 * @property string                         $label          The Invoice's display label.
23
 * @property string                         $billing_source `akamai`: This Invoice was generated according to the terms of an agreement
24
 *                                                          between the customer and Akamai.
25
 *                                                          `linode`: This Invoice was generated according to the default terms, prices, and
26
 *                                                          discounts.
27
 * @property float                          $subtotal       The amount of the Invoice before taxes in US Dollars.
28
 * @property float                          $tax            The amount of tax levied on the Invoice in US Dollars.
29
 * @property float                          $total          The amount of the Invoice after taxes in US Dollars.
30
 * @property Tax[]                          $tax_summary    The amount of tax broken down into subtotals by source.
31
 * @property InvoiceItemRepositoryInterface $items          Invoice items.
32
 */
33
class Invoice extends Entity
34
{
35
    // Available fields.
36
    public const FIELD_ID             = 'id';
37
    public const FIELD_DATE           = 'date';
38
    public const FIELD_LABEL          = 'label';
39
    public const FIELD_BILLING_SOURCE = 'billing_source';
40
    public const FIELD_SUBTOTAL       = 'subtotal';
41
    public const FIELD_TAX            = 'tax';
42
    public const FIELD_TOTAL          = 'total';
43
    public const FIELD_TAX_SUMMARY    = 'tax_summary';
44
45
    // `FIELD_BILLING_SOURCE` values.
46
    public const BILLING_SOURCE_AKAMAI = 'akamai';
47
    public const BILLING_SOURCE_LINODE = 'linode';
48
49
    /**
50
     * @codeCoverageIgnore This method was autogenerated.
51
     */
52
    public function __get(string $name): mixed
53
    {
54
        return match ($name) {
55
            self::FIELD_TAX_SUMMARY => array_map(fn ($data) => new Tax($this->client, $data), $this->data[$name]),
56
            'items'                 => new InvoiceItemRepository($this->client, $this->id),
57
            default                 => parent::__get($name),
58
        };
59
    }
60
}
61