Test Failed
Push — main ( 117601...63d9b1 )
by Chema
11:24
created

CallbackUrl::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightning\Invoice\Application;
6
7
use PhpLightning\Invoice\Domain\CallbackUrl\CallbackUrlInterface;
8
use PhpLightning\Invoice\Domain\CallbackUrl\LnAddressGeneratorInterface;
9
use PhpLightning\Shared\Value\SendableRange;
0 ignored issues
show
Bug introduced by
The type PhpLightning\Shared\Value\SendableRange was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
final class CallbackUrl implements CallbackUrlInterface
12
{
13
    private const TAG_PAY_REQUEST = 'payRequest';
14
15
    public function __construct(
16
        private SendableRange $sendableRange,
17
        private LnAddressGeneratorInterface $lnAddressGenerator,
18
        private string $callback,
19
    ) {
20
    }
21
22
    public function getCallbackUrl(string $username): array
23
    {
24
        $lnAddress = $this->lnAddressGenerator->generate($username);
25
        // Modify the description if you want to custom it
26
        // This will be the description on the wallet that pays your ln address
27
        // TODO: Make this customizable from some external configuration file
28
        $description = 'Pay to ' . $lnAddress;
29
30
        // TODO: images not implemented yet; `',["image/jpeg;base64","' . base64_encode($response) . '"]';`
31
        $imageMetadata = '';
32
        $metadata = '[["text/plain","' . $description . '"],["text/identifier","' . $lnAddress . '"]' . $imageMetadata . ']';
33
34
        // payRequest json data, spec : https://github.com/lnurl/luds/blob/luds/06.md
35
        return [
36
            'callback' => $this->callback,
37
            'maxSendable' => $this->sendableRange->max(),
38
            'minSendable' => $this->sendableRange->min(),
39
            'metadata' => $metadata,
40
            'tag' => self::TAG_PAY_REQUEST,
41
            'commentAllowed' => false, // TODO: Not implemented yet
42
        ];
43
    }
44
}
45