Passed
Push — main ( 0b1f45...3b8d3e )
by Chema
02:32 queued 12s
created

InvoiceConfig   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 61.53%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 38
ccs 8
cts 13
cp 0.6153
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getBackendOptionsFor() 0 10 2
A getLnAddress() 0 3 1
A getCallback() 0 3 1
A getDomain() 0 3 1
A getReceiver() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightning\Invoice;
6
7
use Gacela\Framework\AbstractConfig;
8
use RuntimeException;
9
10
final class InvoiceConfig extends AbstractConfig
11
{
12 1
    public function getCallback(): string
13
    {
14 1
        return sprintf('https://%s/%s', $this->getDomain(), $this->getReceiver());
15
    }
16
17 1
    public function getLnAddress(): string
18
    {
19 1
        return sprintf('%s@%s', $this->getReceiver(), $this->getDomain());
20
    }
21
22
    /**
23
     * @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...
24
     *     api_endpoint: string,
25
     *     api_key: string,
26
     * }
27
     */
28
    public function getBackendOptionsFor(string $backend): array
29
    {
30
        /** @var  array{api_endpoint?: string, api_key?: string} $result */
31
        $result = $this->get('backends')[$backend] ?? []; // @phpstan-ignore-line
32
33
        if (!isset($result['api_endpoint'], $result['api_key'])) {
34
            throw new RuntimeException('Missing backend options for ' . $backend);
35
        }
36
37
        return $result;
38
    }
39
40 1
    private function getDomain(): string
41
    {
42 1
        return (string)$this->get('domain', $_SERVER['HTTP_HOST'] ?? 'localhost');
43
    }
44
45 1
    private function getReceiver(): string
46
    {
47 1
        return (string)$this->get('receiver', $_SERVER['REQUEST_URI'] ?? '"no REQUEST_URI found?"');
48
    }
49
}
50