Test Failed
Pull Request — main (#15)
by
unknown
02:14
created

InvoiceConfig::getCallbackUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightning\Invoice;
6
7
use Gacela\Framework\AbstractConfig;
8
use PhpLightning\Shared\Value\SendableRange;
9
use RuntimeException;
10
11
final class InvoiceConfig extends AbstractConfig
12
{
13 3
    public function getCallback(): string
14
    {
15 3
        return $this->getCallbackUrl();
16
    }
17
18 4
    public function getLnAddress(): string
19
    {
20 4
        return sprintf('%s@%s', $this->getReceiver(), $this->getDomain());
21
    }
22
23
    /**
24
     * @return array{
0 ignored issues
show
Documentation Bug introduced by
The doc comment array{ at position 2 could not be parsed: the token is null at position 2.
Loading history...
25
     *     api_endpoint: string,
26
     *     api_key: string,
27
     * }
28
     */
29 1
    public function getBackendOptionsFor(string $backend): array
30
    {
31
        /** @var  array{api_endpoint?: string, api_key?: string} $result */
32 1
        $result = $this->get('backends')[$backend] ?? []; // @phpstan-ignore-line
33
34 1
        if (!isset($result['api_endpoint'], $result['api_key'])) {
35
            throw new RuntimeException('Missing backend options for ' . $backend);
36
        }
37
38 1
        return $result;
39
    }
40
41 4
    public function getSendableRange(): SendableRange
42
    {
43 4
        return $this->get('sendable-range', SendableRange::default());
44
    }
45
46 4
    private function getDomain(): string
47
    {
48 4
        return (string)$this->get('domain', $_SERVER['HTTP_HOST'] ?? 'localhost');
49
    }
50
51 4
    private function getReceiver(): string
52
    {
53 4
        return (string)$this->get('receiver', $_SERVER['REQUEST_URI'] ?? 'unknown-receiver');
54
    }
55
56
    private function getCallbackUrl(): string
57
    {
58
        return (string)$this->get('callback-url');
59
    }
60
}
61