Completed
Push — master ( ce2be0...7bcb9a )
by Olivier
02:08
created

LineItem::getAmount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace Shapin\Stripe\Model\Invoice;
11
12
use Shapin\Stripe\Model\ContainsMetadata;
13
use Shapin\Stripe\Model\CreatableFromArray;
14
use Shapin\Stripe\Model\LivemodeTrait;
15
use Shapin\Stripe\Model\MetadataTrait;
16
use Shapin\Stripe\Model\MetadataCollection;
17
use Money\Currency;
18
use Money\Money;
19
20
final class LineItem implements CreatableFromArray, ContainsMetadata
21
{
22
    use LivemodeTrait, MetadataTrait;
23
24
    const TYPE_INVOICE_ITEM = 'invoiceitem';
25
    const TYPE_SUBSCRIPTION = 'subscription';
26
27
    /**
28
     * @var string
29
     */
30
    private $id;
31
32
    /**
33
     * @var Money
34
     */
35
    private $amount;
36
37
    /**
38
     * @var Currency
39
     */
40
    private $currency;
41
42
    /**
43
     * @var string
44
     */
45
    private $description;
46
47
    /**
48
     * @var bool
49
     */
50
    private $discountable;
51
52
    /**
53
     * @var ?string
54
     */
55
    private $hydraId;
56
57
    /**
58
     * @var ?string
59
     */
60
    private $invoiceItem;
61
62
    /**
63
     * @var Period
64
     */
65
    private $period;
66
67
    /**
68
     * @var ?string
69
     */
70
    private $plan;
71
72
    /**
73
     * @var bool
74
     */
75
    private $proration;
76
77
    /**
78
     * @var int
79
     */
80
    private $quantity;
81
82
    /**
83
     * @var ?string
84
     */
85
    private $subscription;
86
87
    /**
88
     * @var ?string
89
     */
90
    private $subscriptionItem;
91
92
    /**
93
     * @var ?string
94
     */
95
    private $type;
96
97 15
    public static function createFromArray(array $data): self
98
    {
99 15
        $currency = new Currency(strtoupper($data['currency']));
100
101 15
        $model = new self();
102 15
        $model->id = $data['id'];
103 15
        $model->amount = new Money($data['amount'], $currency);
104 15
        $model->currency = $currency;
105 15
        $model->description = $data['description'];
106 15
        $model->discountable = (bool) $data['discountable'];
107 15
        $model->hydraId = $data['hydra_id'] ?? null;
108 15
        $model->invoiceItem = $data['invoice_item'] ?? null;
109 15
        $model->live = $data['livemode'];
110 15
        $model->metadata = MetadataCollection::createFromArray($data['metadata']);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Shapin\Stripe\Model\Met...rray($data['metadata']) of type object<self> is incompatible with the declared type object<Shapin\Stripe\Model\MetadataCollection> of property $metadata.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
111 15
        $model->period = Period::createFromArray($data['period']);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Shapin\Stripe\Model\Inv...mArray($data['period']) of type object<self> is incompatible with the declared type object<Shapin\Stripe\Model\Invoice\Period> of property $period.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
112 15
        $model->plan = $data['plan'];
113 15
        $model->proration = (bool) $data['proration'];
114 15
        $model->quantity = (int) $data['quantity'];
115 15
        $model->subscription = $data['subscription'];
116 15
        $model->subscriptionItem = $data['subscription_item'] ?? null;
117 15
        $model->type = $data['type'] ?? null;
118
119 15
        return $model;
120
    }
121
122 1
    public function getId(): string
123
    {
124 1
        return $this->id;
125
    }
126
127 1
    public function getAmount(): Money
128
    {
129 1
        return $this->amount;
130
    }
131
132 1
    public function getCurrency(): Currency
133
    {
134 1
        return $this->currency;
135
    }
136
137 1
    public function getDescription()
138
    {
139 1
        return $this->description;
140
    }
141
142 1
    public function isDiscountable(): bool
143
    {
144 1
        return $this->discountable;
145
    }
146
147 1
    public function getHydraId(): ?string
148
    {
149 1
        return $this->hydraId;
150
    }
151
152 1
    public function getInvoiceItem(): ?string
153
    {
154 1
        return $this->invoiceItem;
155
    }
156
157 1
    public function getPeriod(): Period
158
    {
159 1
        return $this->period;
160
    }
161
162 1
    public function getPlan(): ?string
163
    {
164 1
        return $this->plan;
165
    }
166
167 1
    public function isProration(): bool
168
    {
169 1
        return $this->proration;
170
    }
171
172 1
    public function getQuantity(): int
173
    {
174 1
        return $this->quantity;
175
    }
176
177 1
    public function getSubscription(): ?string
178
    {
179 1
        return $this->subscription;
180
    }
181
182 1
    public function getSubscriptionItem(): ?string
183
    {
184 1
        return $this->subscriptionItem;
185
    }
186
187 1
    public function getType(): ?string
188
    {
189 1
        return $this->type;
190
    }
191
}
192