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

CallbackUrl::generateImageMetadata()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4.679

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 11
ccs 3
cts 7
cp 0.4286
crap 4.679
rs 10
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