Passed
Push — main ( 36fa87...8ed71a )
by Chema
01:06 queued 13s
created

CallbackUrl   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 30
ccs 13
cts 13
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCallbackUrl() 0 19 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightning\Invoice\Domain\CallbackUrl;
6
7
use PhpLightning\Invoice\Domain\Transfer\SendableRange;
8
9
final class CallbackUrl implements CallbackUrlInterface
10
{
11
    private const TAG_PAY_REQUEST = 'payRequest';
12
13 3
    public function __construct(
14
        private SendableRange $sendableRange,
15
        private string $lnAddress,
16
        private string $callback,
17
    ) {
18 3
    }
19
20 3
    public function getCallbackUrl(): array
21
    {
22
        // Modify the description if you want to custom it
23
        // This will be the description on the wallet that pays your ln address
24
        // TODO: Make this customizable from some external configuration file
25 3
        $description = 'Pay to ' . $this->lnAddress;
26
27
        // TODO: images not implemented yet; `',["image/jpeg;base64","' . base64_encode($response) . '"]';`
28 3
        $imageMetadata = '';
29 3
        $metadata = '[["text/plain","' . $description . '"],["text/identifier","' . $this->lnAddress . '"]' . $imageMetadata . ']';
30
31
        // payRequest json data, spec : https://github.com/lnurl/luds/blob/luds/06.md
32 3
        return [
33 3
            'callback' => $this->callback,
34 3
            'maxSendable' => $this->sendableRange->max(),
35 3
            'minSendable' => $this->sendableRange->min(),
36 3
            'metadata' => $metadata,
37 3
            'tag' => self::TAG_PAY_REQUEST,
38 3
            'commentAllowed' => false, // TODO: Not implemented yet
39 3
        ];
40
    }
41
}
42