Passed
Push — master ( 0df9ee...efdd9c )
by Mr
08:43
created

LightningInvoice::getRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the ngutech/lightning-interop project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace NGUtech\Lightning\Entity;
10
11
use Daikon\Entity\Attribute;
12
use Daikon\Entity\AttributeMap;
13
use Daikon\Entity\Entity;
14
use Daikon\Money\Entity\TransactionInterface;
15
use Daikon\ValueObject\Natural;
16
use Daikon\ValueObject\Text;
17
use Daikon\ValueObject\Timestamp;
0 ignored issues
show
Bug introduced by
The type Daikon\ValueObject\Timestamp 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...
18
use NGUtech\Bitcoin\ValueObject\Hash;
19
use NGUtech\Bitcoin\ValueObject\Bitcoin;
20
use NGUtech\Lightning\ValueObject\InvoiceState;
21
use NGUtech\Lightning\ValueObject\Request;
22
23
final class LightningInvoice extends Entity implements TransactionInterface
24
{
25
    public static function getAttributeMap(): AttributeMap
26
    {
27
        return new AttributeMap([
28
            Attribute::define('preimage', Hash::class),
29
            Attribute::define('preimageHash', Hash::class),
30
            Attribute::define('request', Request::class),
31
            Attribute::define('destination', Text::class),
32
            Attribute::define('amount', Bitcoin::class),
33
            Attribute::define('amountPaid', Bitcoin::class),
34
            Attribute::define('label', Text::class),
35
            Attribute::define('description', Text::class),
36
            Attribute::define('expiry', Natural::class),
37
            Attribute::define('cltvExpiry', Natural::class),
38
            Attribute::define('blockHeight', Natural::class),
39
            Attribute::define('state', InvoiceState::class),
40
            Attribute::define('createdAt', Timestamp::class),
41
            Attribute::define('settledAt', Timestamp::class),
42
        ]);
43
    }
44
45
    public function getIdentity(): Hash
46
    {
47
        return $this->getPreimageHash();
48
    }
49
50
    public function getPreimage(): Hash
51
    {
52
        return $this->get('preimage') ?? Hash::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('preim...bject\Hash::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Bitcoin\ValueObject\Hash. Consider adding an additional type-check to rule them out.
Loading history...
53
    }
54
55
    public function getPreimageHash(): Hash
56
    {
57
        return $this->get('preimageHash') ?? Hash::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('preim...bject\Hash::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Bitcoin\ValueObject\Hash. Consider adding an additional type-check to rule them out.
Loading history...
58
    }
59
60
    public function getRequest(): Request
61
    {
62
        return $this->get('request') ?? Request::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('reque...ct\Request::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Lightning\ValueObject\Request. Consider adding an additional type-check to rule them out.
Loading history...
63
    }
64
65
    public function getDestination(): Text
66
    {
67
        return $this->get('destination') ?? Text::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('desti...bject\Text::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return Daikon\ValueObject\Text. Consider adding an additional type-check to rule them out.
Loading history...
68
    }
69
70
    public function getAmount(): Bitcoin
71
    {
72
        return $this->get('amount') ?? Bitcoin::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('amoun...ct\Bitcoin::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Bitcoin\ValueObject\Bitcoin. Consider adding an additional type-check to rule them out.
Loading history...
73
    }
74
75
    public function getAmountPaid(): Bitcoin
76
    {
77
        return $this->get('amountPaid') ?? Bitcoin::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('amoun...ct\Bitcoin::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Bitcoin\ValueObject\Bitcoin. Consider adding an additional type-check to rule them out.
Loading history...
78
    }
79
80
    public function getLabel(): Text
81
    {
82
        return $this->get('label') ?? Text::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('label...bject\Text::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return Daikon\ValueObject\Text. Consider adding an additional type-check to rule them out.
Loading history...
83
    }
84
85
    public function getDescription(): Text
86
    {
87
        return $this->get('description') ?? Text::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('descr...bject\Text::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return Daikon\ValueObject\Text. Consider adding an additional type-check to rule them out.
Loading history...
88
    }
89
90
    public function getExpiry(): Natural
91
    {
92
        return $this->get('expiry') ?? Natural::fromNative(86400);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('expir...ural::fromNative(86400) could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return Daikon\ValueObject\Natural. Consider adding an additional type-check to rule them out.
Loading history...
93
    }
94
95
    public function getCltvExpiry(): Natural
96
    {
97
        return $this->get('cltvExpiry') ?? Natural::fromNative(10);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('cltvE...Natural::fromNative(10) could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return Daikon\ValueObject\Natural. Consider adding an additional type-check to rule them out.
Loading history...
98
    }
99
100
    public function getBlockHeight(): Natural
101
    {
102
        return $this->get('blockHeight') ?? Natural::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('block...ct\Natural::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return Daikon\ValueObject\Natural. Consider adding an additional type-check to rule them out.
Loading history...
103
    }
104
105
    public function getExpiryHeight(): Natural
106
    {
107
        //@todo handle error cases
108
        return $this->getBlockHeight()->add($this->getCltvExpiry());
109
    }
110
111
    public function getState(): InvoiceState
112
    {
113
        return $this->get('state') ?? InvoiceState::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('state...voiceState::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Lightning\ValueObject\InvoiceState. Consider adding an additional type-check to rule them out.
Loading history...
114
    }
115
116
    public function getCreatedAt(): Timestamp
117
    {
118
        return $this->get('createdAt') ?? Timestamp::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('creat...\Timestamp::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which is incompatible with the type-hinted return Daikon\ValueObject\Timestamp. Consider adding an additional type-check to rule them out.
Loading history...
119
    }
120
121
    public function getExpiresAt(): Timestamp
122
    {
123
        return $this->getCreatedAt()->modify("+{$this->getExpiry()} seconds");
124
    }
125
126
    public function hasExpired(Timestamp $time): bool
127
    {
128
        return $this->getExpiresAt()->isBefore($time);
129
    }
130
131
    public function getSettledAt(): Timestamp
132
    {
133
        return $this->get('settledAt') ?? Timestamp::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('settl...\Timestamp::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which is incompatible with the type-hinted return Daikon\ValueObject\Timestamp. Consider adding an additional type-check to rule them out.
Loading history...
134
    }
135
}
136