Completed
Push — master ( b6f7ca...4aea47 )
by Olivier
03:30
created

LastPaymentError::createFromArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 9.7
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 12
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\PaymentIntent;
11
12
use Shapin\Stripe\Model\CreatableFromArray;
13
use Shapin\Stripe\Model\Source\Source;
14
15
final class LastPaymentError implements CreatableFromArray
16
{
17
    const TYPE_API_CONNECTION_ERROR = 'api_connection_error';
18
    const TYPE_API_ERROR = 'api_error';
19
    const TYPE_AUTHENTICATION_ERROR = 'authentication_error';
20
    const TYPE_CARD_ERROR = 'card_error';
21
    const TYPE_IDEMPOTENCY_ERROR = 'idempotency_error';
22
    const TYPE_INVALID_REQUEST_ERROR = 'invalid_request_error';
23
    const TYPE_RATE_LIMIT_ERROR = 'rate_limit_error';
24
25
    /**
26
     * @var string
27
     */
28
    private $type;
29
30
    /**
31
     * @var ?string
32
     */
33
    private $chargeId;
34
35
    /**
36
     * @var ?string
37
     */
38
    private $code;
39
40
    /**
41
     * @var ?string
42
     */
43
    private $declineCode;
44
45
    /**
46
     * @var string
47
     */
48
    private $docUrl;
49
50
    /**
51
     * @var ?string
52
     */
53
    private $param;
54
55
    /**
56
     * @var ?PaymentIntent
57
     */
58
    private $paymentIntent;
59
60
    /**
61
     * @var ?PaymentMethod
62
     */
63
    private $paymentMethod;
64
65
    /**
66
     * @var ?Source
67
     */
68
    private $source;
69
70
    public static function createFromArray(array $data): self
71
    {
72
        $model = new self();
73
        $model->type = $data['type'];
74
        $model->chargeId = $data['charge_id'];
75
        $model->code = $data['code'];
76
        $model->declineCode = $data['decline_code'];
77
        $model->docUrl = $data['doc_url'];
78
        $model->message = $data['message'];
0 ignored issues
show
Bug introduced by
The property message 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...
79
        $model->param = $data['param'];
80
        $model->paymentIntent = isset($data['payment_intent']) ? PaymentIntent::createFromArray($data['payment_method']) : null;
81
        // TODO: Deal with payment methods
82
        //$model->paymentMethod = isset($data['payment_method']) ? PaymentMethod::createFromArray($data['payment_method']) : null;
83
        $model->source = isset($data['source']) ? Source::createFromArray($data['source']) : null;
84
85
        return $model;
86
    }
87
88
    public function getType(): string
89
    {
90
        return $this->type;
91
    }
92
93
    public function getChargeId(): ?string
94
    {
95
        return $this->charge;
0 ignored issues
show
Bug introduced by
The property charge does not seem to exist. Did you mean chargeId?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
96
    }
97
98
    public function getCode(): ?string
99
    {
100
        return $this->code;
101
    }
102
103
    public function getDeclineCode(): ?string
104
    {
105
        return $this->declineCode;
106
    }
107
108
    public function getDocUrl(): ?string
109
    {
110
        return $this->docUrl;
111
    }
112
113
    public function getMessage(): string
114
    {
115
        return $this->message;
116
    }
117
118
    public function getParam(): ?string
119
    {
120
        return $this->param;
121
    }
122
123
    public function getPaymentIntent(): ?PaymentIntent
124
    {
125
        return $this->paymentIntent;
126
    }
127
128
    public function getPaymentMethod(): ?PaymentMethod
129
    {
130
        return $this->paymentMethod;
131
    }
132
133
    public function getSource(): ?Source
134
    {
135
        return $this->source;
136
    }
137
}
138