Passed
Pull Request — main (#12)
by Chema
02:52
created

Lightning   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 27.27%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 11
c 3
b 0
f 0
dl 0
loc 29
ccs 3
cts 11
cp 0.2727
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateInvoice() 0 5 1
A getCallbackUrl() 0 5 1
A configFn() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightning;
6
7
use Closure;
8
use Gacela\Framework\Bootstrap\GacelaConfig;
9
use PhpLightning\Invoice\InvoiceFacade;
10
11
final class Lightning
12
{
13
    public const CONFIG_FILE = 'lightning-config.php';
14
15
    private const CONFIG_LOCAL_FILE = 'lightning-config-local.php';
16
17
    public static function getCallbackUrl(): string
18
    {
19
        $invoice = (new InvoiceFacade())->getCallbackUrl();
20
21
        return json_encode($invoice, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
22
    }
23
24 1
    public static function generateInvoice(int $amount, string $backend = 'lnbits'): string
25
    {
26 1
        $invoice = (new InvoiceFacade())->generateInvoice($amount, $backend);
27
28 1
        return json_encode($invoice, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
29
    }
30
31
    /**
32
     * @return Closure(GacelaConfig):void
33
     */
34
    public static function configFn(): Closure
35
    {
36
        return static function (GacelaConfig $config): void {
37
            $config->addAppConfig(self::CONFIG_FILE, self::CONFIG_LOCAL_FILE);
38
            $config->setFileCacheEnabled(true);
39
            $config->setFileCacheDirectory('data/.cache');
40
        };
41
    }
42
}
43