Completed
Push — master ( abb491...352f9f )
by Olivier
01:38
created

SetupIntent   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 5
dl 0
loc 160
ccs 43
cts 43
cp 1
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromArray() 0 22 3
A getId() 0 4 1
A getApplicationId() 0 4 1
A getCancellationReason() 0 4 1
A getClientSecret() 0 4 1
A getCreatedAt() 0 4 1
A getCustomerId() 0 4 1
A getDescription() 0 4 1
A getLastSetupError() 0 4 1
A getOnBehalfOfId() 0 4 1
A getPaymentMethodId() 0 4 1
A getPaymentMethodTypes() 0 4 1
A getUsage() 0 4 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\SetupIntent;
11
12
use Shapin\Stripe\Model\ContainsMetadata;
13
use Shapin\Stripe\Model\CreatableFromArray;
14
use Shapin\Stripe\Model\Intent;
15
use Shapin\Stripe\Model\IntentNextAction;
16
use Shapin\Stripe\Model\LivemodeTrait;
17
use Shapin\Stripe\Model\MetadataTrait;
18
use Shapin\Stripe\Model\MetadataCollection;
19
20
final class SetupIntent extends Intent implements CreatableFromArray, ContainsMetadata
21
{
22
    use LivemodeTrait;
23
    use MetadataTrait;
24
25
    const CANCELLATION_REASON_ABANDONED = 'abandoned';
26
    const CANCELLATION_REASON_REQUESTED_BY_CUSTOMER = 'requested_by_customer';
27
    const CANCELLATION_REASON_DUPLICATE = 'duplicate';
28
29
    const USAGE_ON_SESSION = 'on_session';
30
    const USAGE_OFF_SESSION = 'off_session';
31
32
    /**
33
     * @var string
34
     */
35
    private $id;
36
37
    /**
38
     * @var ?string
39
     */
40
    private $applicationId;
41
42
    /**
43
     * @var ?string
44
     */
45
    private $cancellationReason;
46
47
    /**
48
     * @var ?string
49
     */
50
    private $clientSecret;
51
52
    /**
53
     * @var string
54
     */
55
    private $confirmationMethod;
56
57
    /**
58
     * @var \DateTimeImmutable
59
     */
60
    private $createdAt;
61
62
    /**
63
     * @var string
64
     */
65
    private $customerId;
66
67
    /**
68
     * @var string
69
     */
70
    private $description;
71
72
    /**
73
     * @var ?LastSetupError
74
     */
75
    private $lastSetupError;
76
77
    /**
78
     * @var ?string
79
     */
80
    private $onBehalfOfId;
81
82
    /**
83
     * @var ?string
84
     */
85
    private $paymentMethodId;
86
87
    /**
88
     * @var array
89
     */
90
    private $setupMethodTypes;
91
92
    /**
93
     * @var string
94
     */
95
    private $usage;
96
97 3
    public static function createFromArray(array $data): self
98
    {
99 3
        $model = new self();
100 3
        $model->id = $data['id'];
101 3
        $model->applicationId = $data['application'];
102 3
        $model->cancellationReason = $data['cancellation_reason'] ?? null;
103 3
        $model->clientSecret = $data['client_secret'];
104 3
        $model->createdAt = new \DateTimeImmutable('@'.$data['created']);
105 3
        $model->customerId = $data['customer'];
106 3
        $model->description = $data['description'];
107 3
        $model->lastSetupError = isset($data['last_setup_error']) ? LastSetupError::createFromArray($data['last_setup_error']) : null;
108 3
        $model->live = $data['livemode'];
109 3
        $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...
110 3
        $model->nextAction = isset($data['next_action']) ? IntentNextAction::createFromArray($data['next_action']) : null;
111 3
        $model->onBehalfOfId = $data['on_behalf_of'];
112 3
        $model->paymentMethodId = $data['payment_method'];
113 3
        $model->paymentMethodTypes = $data['payment_method_types'];
0 ignored issues
show
Bug introduced by
The property paymentMethodTypes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
114 3
        $model->status = $data['status'];
115 3
        $model->usage = $data['usage'];
116
117 3
        return $model;
118
    }
119
120 1
    public function getId(): string
121
    {
122 1
        return $this->id;
123
    }
124
125 1
    public function getApplicationId(): ?string
126
    {
127 1
        return $this->applicationId;
128
    }
129
130 1
    public function getCancellationReason(): ?string
131
    {
132 1
        return $this->cancellationReason;
133
    }
134
135 1
    public function getClientSecret(): ?string
136
    {
137 1
        return $this->clientSecret;
138
    }
139
140 1
    public function getCreatedAt(): \DateTimeInterface
141
    {
142 1
        return $this->createdAt;
143
    }
144
145 1
    public function getCustomerId(): ?string
146
    {
147 1
        return $this->customerId;
148
    }
149
150 1
    public function getDescription(): ?string
151
    {
152 1
        return $this->description;
153
    }
154
155 1
    public function getLastSetupError(): ?LastSetupError
156
    {
157 1
        return $this->lastSetupError;
158
    }
159
160 1
    public function getOnBehalfOfId(): ?string
161
    {
162 1
        return $this->onBehalfOfId;
163
    }
164
165 1
    public function getPaymentMethodId(): ?string
166
    {
167 1
        return $this->paymentMethodId;
168
    }
169
170 1
    public function getPaymentMethodTypes(): array
171
    {
172 1
        return $this->paymentMethodTypes;
173
    }
174
175 1
    public function getUsage(): string
176
    {
177 1
        return $this->usage;
178
    }
179
}
180