NGUtech /
lightning-interop
| 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\FloatValue; |
||
| 16 | use Daikon\ValueObject\Text; |
||
| 17 | use Daikon\ValueObject\Timestamp; |
||
| 18 | use NGUtech\Bitcoin\ValueObject\Hash; |
||
| 19 | use NGUtech\Bitcoin\ValueObject\Bitcoin; |
||
| 20 | use NGUtech\Lightning\ValueObject\PaymentState; |
||
| 21 | use NGUtech\Lightning\ValueObject\Request; |
||
| 22 | |||
| 23 | final class LightningPayment 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('feeLimit', FloatValue::class), |
||
| 35 | Attribute::define('feeEstimate', Bitcoin::class), |
||
| 36 | Attribute::define('feeSettled', Bitcoin::class), |
||
| 37 | Attribute::define('label', Text::class), |
||
| 38 | Attribute::define('description', Text::class), |
||
| 39 | Attribute::define('state', PaymentState::class), |
||
| 40 | Attribute::define('createdAt', Timestamp::class), |
||
| 41 | ]); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function getIdentity(): Hash |
||
| 45 | { |
||
| 46 | return $this->getPreimageHash(); |
||
| 47 | } |
||
| 48 | |||
| 49 | public function getPreimage(): Hash |
||
| 50 | { |
||
| 51 | return $this->get('preimage') ?? Hash::makeEmpty(); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 52 | } |
||
| 53 | |||
| 54 | public function getPreimageHash(): Hash |
||
| 55 | { |
||
| 56 | return $this->get('preimageHash') ?? Hash::makeEmpty(); |
||
|
0 ignored issues
–
show
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...
|
|||
| 57 | } |
||
| 58 | |||
| 59 | public function getRequest(): Request |
||
| 60 | { |
||
| 61 | return $this->get('request') ?? Request::makeEmpty(); |
||
|
0 ignored issues
–
show
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...
|
|||
| 62 | } |
||
| 63 | |||
| 64 | public function getDestination(): Text |
||
| 65 | { |
||
| 66 | return $this->get('destination') ?? Text::makeEmpty(); |
||
|
0 ignored issues
–
show
|
|||
| 67 | } |
||
| 68 | |||
| 69 | public function getAmount(): Bitcoin |
||
| 70 | { |
||
| 71 | return $this->get('amount') ?? Bitcoin::makeEmpty(); |
||
|
0 ignored issues
–
show
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...
|
|||
| 72 | } |
||
| 73 | |||
| 74 | public function getAmountPaid(): Bitcoin |
||
| 75 | { |
||
| 76 | return $this->get('amountPaid') ?? Bitcoin::makeEmpty(); |
||
|
0 ignored issues
–
show
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...
|
|||
| 77 | } |
||
| 78 | |||
| 79 | public function getFeeLimit(): FloatValue |
||
| 80 | { |
||
| 81 | return $this->get('feeLimit') ?? FloatValue::zero(); |
||
|
0 ignored issues
–
show
|
|||
| 82 | } |
||
| 83 | |||
| 84 | public function getFeeEstimate(): Bitcoin |
||
| 85 | { |
||
| 86 | return $this->get('feeEstimate') ?? Bitcoin::makeEmpty(); |
||
|
0 ignored issues
–
show
The expression
return $this->get('feeEs...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...
|
|||
| 87 | } |
||
| 88 | |||
| 89 | public function getFeeSettled(): Bitcoin |
||
| 90 | { |
||
| 91 | return $this->get('feeSettled') ?? Bitcoin::makeEmpty(); |
||
|
0 ignored issues
–
show
The expression
return $this->get('feeSe...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...
|
|||
| 92 | } |
||
| 93 | |||
| 94 | public function getFeeRefund(): Bitcoin |
||
| 95 | { |
||
| 96 | return $this->getFeeEstimate()->subtract($this->getFeeSettled()); |
||
| 97 | } |
||
| 98 | |||
| 99 | public function getLabel(): Text |
||
| 100 | { |
||
| 101 | return $this->get('label') ?? Text::makeEmpty(); |
||
|
0 ignored issues
–
show
|
|||
| 102 | } |
||
| 103 | |||
| 104 | public function getDescription(): Text |
||
| 105 | { |
||
| 106 | return $this->get('description') ?? Text::makeEmpty(); |
||
|
0 ignored issues
–
show
|
|||
| 107 | } |
||
| 108 | |||
| 109 | public function getState(): PaymentState |
||
| 110 | { |
||
| 111 | return $this->get('state') ?? PaymentState::makeEmpty(); |
||
|
0 ignored issues
–
show
The expression
return $this->get('state...ymentState::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return NGUtech\Lightning\ValueObject\PaymentState. Consider adding an additional type-check to rule them out.
Loading history...
|
|||
| 112 | } |
||
| 113 | |||
| 114 | public function getCreatedAt(): Timestamp |
||
| 115 | { |
||
| 116 | return $this->get('createdAt') ?? Timestamp::makeEmpty(); |
||
|
0 ignored issues
–
show
|
|||
| 117 | } |
||
| 118 | } |
||
| 119 |