InvoiceConfig   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 62
rs 10
c 2
b 0
f 0
ccs 16
cts 17
cp 0.9412
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getBackends() 0 4 1
A getDefaultLnAddress() 0 3 1
A getBackendOptionsFor() 0 10 2
A getSendableRange() 0 3 1
A getCallback() 0 3 1
A getSuccessMessage() 0 3 1
A getDescriptionTemplate() 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 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...
9
use RuntimeException;
10
11
use function sprintf;
12
13 1
final class InvoiceConfig extends AbstractConfig
14
{
15 1
    public function getCallback(): string
16
    {
17
        return (string)$this->get('callback-url', 'undefined:callback-url');
18 2
    }
19
20 2
    public function getDefaultLnAddress(): string
21
    {
22
        return sprintf('%s@%s', $this->getReceiver(), $this->getDomain());
23
    }
24
25
    /**
26 2
     * @return array<string,array>
27
     */
28
    public function getBackends(): array
29 2
    {
30
        /** @psalm-suppress MixedReturnTypeCoercion */
31
        return (array)$this->get('backends'); // @phpstan-ignore-line
32
    }
33
34
    /**
35
     * @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...
36
     *     api_endpoint: string,
37
     *     api_key: string,
38 2
     * }
39
     */
40
    public function getBackendOptionsFor(string $username): array
41 2
    {
42
        /** @var  array{api_endpoint?: string, api_key?: string} $result */
43 2
        $result = $this->getBackends()[$username] ?? [];
44
45
        if (!isset($result['api_endpoint'], $result['api_key'])) {
46
            throw new RuntimeException('Missing backend options for ' . $username);
47 2
        }
48
49
        return $result;
50 2
    }
51
52 2
    public function getSendableRange(): SendableRange
53
    {
54
        return $this->get('sendable-range', SendableRange::default());
55 2
    }
56
57 2
    public function getDescriptionTemplate(): string
58
    {
59
        return (string)$this->get('description-template', 'Pay to %s');
60 2
    }
61
62 2
    public function getSuccessMessage(): string
63
    {
64
        return (string)$this->get('success-message', 'Payment received!');
65
    }
66
67
    public function getDomain(): string
68
    {
69
        return (string)$this->get('domain', $_SERVER['HTTP_HOST'] ?? 'localhost');
70
    }
71
72
    private function getReceiver(): string
73
    {
74
        return (string)$this->get('receiver', $_SERVER['REQUEST_URI'] ?? 'unknown-receiver');
75
    }
76
}
77