Test Failed
Push — main ( 60b477...a1ddf7 )
by Chema
14:12 queued 10:45
created

InvoiceTransfer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 48
rs 10
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B fromArray() 0 23 9
A __construct() 0 21 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightning\Shared\Transfer;
6
7
use function array_key_exists;
8
use function is_array;
9
10
final class InvoiceTransfer
11
{
12
    public function __construct(
13
        public string $checkingId = '',
14
        public string $paymentHash = '',
15
        public string $walletId = '',
16
        public int $amount = 0,
17
        public int $fee = 0,
18
        public string $bolt11 = '',
19
        public string $status = 'OK',
20
        public string $memo = '',
21
        public ?string $expiry = null,
22
        public ?string $webhook = null,
23
        public ?string $webhookStatus = null,
24
        public ?string $preimage = null,
25
        public ?string $tag = null,
26
        public ?string $extension = null,
27
        public string $time = '',
28
        public string $createdAt = '',
29
        public string $updatedAt = '',
30
        public ?string $error = null,
31
        public ?InvoiceExtraTransfer $extra = null,
32
    ) {
33
    }
34
35
    public static function fromArray(array $array): self
36
    {
37
        return new self(
38
            checkingId: (string) ($array['checking_id'] ?? ''),
39
            paymentHash: (string) ($array['payment_hash'] ?? ''),
40
            walletId: (string) ($array['wallet_id'] ?? ''),
41
            amount: (int) ($array['amount'] ?? 0),
42
            fee: (int) ($array['fee'] ?? 0),
43
            bolt11: (string) ($array['bolt11'] ?? ''),
44
            status: (string) ($array['status'] ?? ''),
45
            memo: (string) ($array['memo'] ?? ''),
46
            expiry: array_key_exists('expiry', $array) ? (string) $array['expiry'] : null,
47
            webhook: array_key_exists('webhook', $array) ? (string) $array['webhook'] : null,
48
            webhookStatus: array_key_exists('webhook_status', $array) ? (string) $array['webhook_status'] : null,
49
            preimage: array_key_exists('preimage', $array) ? (string) $array['preimage'] : null,
50
            tag: array_key_exists('tag', $array) ? (string) $array['tag'] : null,
51
            extension: array_key_exists('extension', $array) ? (string) $array['extension'] : null,
52
            time: (string) ($array['time'] ?? ''),
53
            createdAt: (string) ($array['created_at'] ?? ''),
54
            updatedAt: (string) ($array['updated_at'] ?? ''),
55
            extra: isset($array['extra']) && is_array($array['extra'])
56
                ? InvoiceExtraTransfer::fromArray($array['extra'])
57
                : null,
58
        );
59
    }
60
}
61