php-lightning /
lnaddress
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace PhpLightning\Config; |
||
| 6 | |||
| 7 | use JsonSerializable; |
||
| 8 | use PhpLightning\Config\Backend\LnBitsBackendConfig; |
||
| 9 | use PhpLightning\Shared\Value\SendableRange; |
||
|
0 ignored issues
–
show
|
|||
| 10 | use RuntimeException; |
||
| 11 | |||
| 12 | final class LightningConfig implements JsonSerializable |
||
| 13 | { |
||
| 14 | private ?BackendsConfig $backends = null; |
||
| 15 | private ?string $domain = null; |
||
| 16 | private ?string $receiver = null; |
||
| 17 | private ?SendableRange $sendableRange = null; |
||
| 18 | private ?string $callbackUrl = null; |
||
| 19 | private ?string $descriptionTemplate = null; |
||
| 20 | 4 | private ?string $successMessage = null; |
|
| 21 | |||
| 22 | 4 | public function setDomain(string $domain): self |
|
| 23 | 4 | { |
|
| 24 | 4 | $parseUrl = parse_url($domain); |
|
| 25 | $this->domain = $parseUrl['host'] ?? $domain; |
||
| 26 | return $this; |
||
| 27 | 3 | } |
|
| 28 | |||
| 29 | 3 | public function setReceiver(string $receiver): self |
|
| 30 | 3 | { |
|
| 31 | $this->receiver = $receiver; |
||
| 32 | return $this; |
||
| 33 | 3 | } |
|
| 34 | |||
| 35 | 3 | public function setSendableRange(int $min, int $max): self |
|
| 36 | 3 | { |
|
| 37 | $this->sendableRange = SendableRange::withMinMax($min, $max); |
||
| 38 | return $this; |
||
| 39 | 2 | } |
|
| 40 | |||
| 41 | 2 | public function setCallbackUrl(string $callbackUrl): self |
|
| 42 | 2 | { |
|
| 43 | $this->callbackUrl = $callbackUrl; |
||
| 44 | return $this; |
||
| 45 | 2 | } |
|
| 46 | |||
| 47 | 2 | public function setDescriptionTemplate(string $template): self |
|
| 48 | { |
||
| 49 | 2 | $this->descriptionTemplate = $template; |
|
| 50 | return $this; |
||
| 51 | } |
||
| 52 | |||
| 53 | public function setSuccessMessage(string $message): self |
||
| 54 | { |
||
| 55 | $this->successMessage = $message; |
||
| 56 | 2 | return $this; |
|
| 57 | } |
||
| 58 | 2 | ||
| 59 | 2 | public function addBackendsFile(string $path): self |
|
| 60 | { |
||
| 61 | $this->backends ??= new BackendsConfig(); |
||
| 62 | |||
| 63 | 2 | $jsonAsString = (string)file_get_contents($path); |
|
| 64 | 2 | /** @var array<string, array{ |
|
| 65 | 2 | * type: ?string, |
|
| 66 | 2 | * api_endpoint?: string, |
|
| 67 | 2 | * api_key?: string, |
|
| 68 | 2 | * }> $json |
|
| 69 | 2 | */ |
|
| 70 | 2 | $json = json_decode($jsonAsString, true); |
|
| 71 | |||
| 72 | foreach ($json as $user => $settings) { |
||
| 73 | if (!isset($settings['type'])) { |
||
| 74 | 2 | throw new RuntimeException('"type" missing'); |
|
| 75 | } |
||
| 76 | |||
| 77 | 7 | if ($settings['type'] === 'lnbits') { // TODO: refactor |
|
| 78 | $this->backends->add( |
||
| 79 | 7 | $user, |
|
| 80 | 7 | LnBitsBackendConfig::withEndpointAndKey( |
|
| 81 | 2 | $settings['api_endpoint'] ?? '', |
|
| 82 | $settings['api_key'] ?? '', |
||
| 83 | 7 | ), |
|
| 84 | 4 | ); |
|
| 85 | } |
||
| 86 | 7 | } |
|
| 87 | 3 | ||
| 88 | return $this; |
||
| 89 | 7 | } |
|
| 90 | 3 | ||
| 91 | public function jsonSerialize(): array |
||
| 92 | 7 | { |
|
| 93 | 2 | $result = []; |
|
| 94 | if ($this->backends instanceof BackendsConfig) { |
||
| 95 | $result['backends'] = $this->backends->jsonSerialize(); |
||
| 96 | 7 | } |
|
| 97 | if ($this->domain !== null) { |
||
| 98 | $result['domain'] = $this->domain; |
||
| 99 | } |
||
| 100 | if ($this->receiver !== null) { |
||
| 101 | $result['receiver'] = $this->receiver; |
||
| 102 | } |
||
| 103 | if ($this->sendableRange instanceof SendableRange) { |
||
| 104 | $result['sendable-range'] = $this->sendableRange; |
||
| 105 | } |
||
| 106 | if ($this->callbackUrl !== null) { |
||
| 107 | $result['callback-url'] = $this->callbackUrl; |
||
| 108 | } |
||
| 109 | if ($this->descriptionTemplate !== null) { |
||
| 110 | $result['description-template'] = $this->descriptionTemplate; |
||
| 111 | } |
||
| 112 | if ($this->successMessage !== null) { |
||
| 113 | $result['success-message'] = $this->successMessage; |
||
| 114 | } |
||
| 115 | |||
| 116 | return $result; |
||
| 117 | } |
||
| 118 | } |
||
| 119 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths