Passed
Push — master ( 5c16df...1eb25c )
by Mr
02:34
created

BitcoinTransaction::getFeeEstimate()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the ngutech/bitcoin-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\Bitcoin\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\BoolValue;
16
use Daikon\ValueObject\FloatValue;
17
use Daikon\ValueObject\IntValue;
18
use Daikon\ValueObject\Text;
19
use NGUtech\Bitcoin\ValueObject\Bitcoin;
20
use NGUtech\Bitcoin\ValueObject\Hash;
21
use NGUtech\Bitcoin\ValueObject\OutputList;
22
23
final class BitcoinTransaction extends Entity implements TransactionInterface
24
{
25
    public static function getAttributeMap(): AttributeMap
26
    {
27
        return new AttributeMap([
28
            Attribute::define('id', Hash::class),
29
            Attribute::define('label', Text::class),
30
            Attribute::define('amount', Bitcoin::class),
31
            Attribute::define('outputs', OutputList::class),
32
            Attribute::define('feeRate', FloatValue::class),
33
            Attribute::define('feeEstimate', Bitcoin::class),
34
            Attribute::define('feeSettled', Bitcoin::class),
35
            Attribute::define('comment', Text::class),
36
            Attribute::define('confTarget', IntValue::class),
37
            Attribute::define('confirmations', IntValue::class),
38
            Attribute::define('rbf', BoolValue::class),
39
        ]);
40
    }
41
42
    public function getIdentity(): Hash
43
    {
44
        return $this->getId();
45
    }
46
47
    public function getId(): Hash
48
    {
49
        return $this->get('id') ?? Hash::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('id') ...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...
50
    }
51
52
    public function getLabel(): Text
53
    {
54
        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...
55
    }
56
57
    public function getAmount(): Bitcoin
58
    {
59
        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...
60
    }
61
62
    public function getOutputs(): OutputList
63
    {
64
        return $this->get('outputs') ?? OutputList::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('outpu...OutputList::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which is incompatible with the type-hinted return NGUtech\Bitcoin\ValueObject\OutputList. Consider adding an additional type-check to rule them out.
Loading history...
65
    }
66
67
    public function getFeeRate(): FloatValue
68
    {
69
        return $this->get('feeRate') ?? FloatValue::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('feeRa...FloatValue::makeEmpty() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return Daikon\ValueObject\FloatValue. Consider adding an additional type-check to rule them out.
Loading history...
70
    }
71
72
    public function getFeeEstimate(): Bitcoin
73
    {
74
        return $this->get('feeEstimate') ?? Bitcoin::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
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...
75
    }
76
77
    public function getFeeSettled(): Bitcoin
78
    {
79
        return $this->get('feeSettled') ?? Bitcoin::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
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...
80
    }
81
82
    public function getFeeRefund(): Bitcoin
83
    {
84
        return $this->getFeeEstimate()->subtract($this->getFeeSettled());
85
    }
86
87
    public function getComment(): Text
88
    {
89
        return $this->get('comment') ?? Text::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('comme...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...
90
    }
91
92
    public function getConfTarget(): IntValue
93
    {
94
        return $this->get('confTarget') ?? IntValue::fromNative(3);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('confT...IntValue::fromNative(3) could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return Daikon\ValueObject\IntValue. Consider adding an additional type-check to rule them out.
Loading history...
95
    }
96
97
    public function getConfirmations(): IntValue
98
    {
99
        return $this->get('confirmations') ?? IntValue::zero();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('confi...Object\IntValue::zero() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return Daikon\ValueObject\IntValue. Consider adding an additional type-check to rule them out.
Loading history...
100
    }
101
102
    public function getRbf(): BoolValue
103
    {
104
        return $this->get('rbf') ?? BoolValue::false();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('rbf')...ject\BoolValue::false() could return the type Daikon\ValueObject\ValueObjectInterface which includes types incompatible with the type-hinted return Daikon\ValueObject\BoolValue. Consider adding an additional type-check to rule them out.
Loading history...
105
    }
106
}
107