Passed
Pull Request — main (#11)
by Jesús
02:37
created

InvoiceFactory::createLnBitsBackendInvoice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpLightning\Invoice;
6
7
use Gacela\Framework\AbstractFactory;
8
use PhpLightning\Http\HttpFacadeInterface;
9
use PhpLightning\Invoice\Domain\BackendInvoice\BackendInvoiceInterface;
10
use PhpLightning\Invoice\Domain\BackendInvoice\EmptyBackendInvoice;
11
use PhpLightning\Invoice\Domain\BackendInvoice\LnbitsBackendInvoice;
12
use PhpLightning\Invoice\Domain\CallbackUrl\CallbackUrl;
13
use PhpLightning\Invoice\Domain\CallbackUrl\CallbackUrlInterface;
14
use PhpLightning\Invoice\Domain\LnAddress\InvoiceGenerator;
15
16
/**
17
 * @method InvoiceConfig getConfig()
18
 */
19
final class InvoiceFactory extends AbstractFactory
20
{
21 2
    public function createCallbackUrl(): CallbackUrlInterface
22
    {
23 2
        return new CallbackUrl(
24 2
            $this->getConfig()->getSendableRange(),
25 2
            $this->getConfig()->getLnAddress(),
26 2
            $this->getConfig()->getCallback(),
27 2
        );
28
    }
29
30 1
    public function createInvoiceGenerator(string $backend): InvoiceGenerator
31
    {
32 1
        return new InvoiceGenerator(
33 1
            $this->createBackend($backend),
34 1
            $this->getConfig()->getSendableRange(),
35 1
            $this->getConfig()->getLnAddress(),
36 1
        );
37
    }
38
39 1
    private function createBackend(string $backend): BackendInvoiceInterface
40
    {
41 1
        return match ($backend) {
42 1
            'lnbits' => $this->createLnBitsBackendInvoice(),
43 1
            default => $this->createEmptyBackendInvoice($backend),
44 1
        };
45
    }
46
47 1
    private function createLnBitsBackendInvoice(): LnbitsBackendInvoice
48
    {
49 1
        return new LnbitsBackendInvoice(
50 1
            $this->getHttpFacade(),
51 1
            $this->getConfig()->getBackendOptionsFor('lnbits'),
52 1
        );
53
    }
54
55
    private function createEmptyBackendInvoice(string $backend): EmptyBackendInvoice
56
    {
57
        return new EmptyBackendInvoice($backend);
58
    }
59
60 1
    private function getHttpFacade(): HttpFacadeInterface
61
    {
62 1
        return $this->getProvidedDependency(InvoiceDependencyProvider::FACADE_HTTP);
63
    }
64
}
65