BitcoinTransaction   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 14
eloc 28
c 3
b 0
f 0
dl 0
loc 85
ccs 0
cts 28
cp 0
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getAmount() 0 3 1
A getLabel() 0 3 1
A getAttributeMap() 0 14 1
A getIdentity() 0 3 1
A getConfTarget() 0 3 1
A getFeeRate() 0 3 1
A getConfirmations() 0 3 1
A getId() 0 3 1
A getOutputs() 0 3 1
A getFeeRefund() 0 3 1
A getFeeSettled() 0 3 1
A getFeeEstimate() 0 3 1
A getRbf() 0 3 1
A getComment() 0 3 1
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\Natural;
18
use Daikon\ValueObject\Text;
19
use NGUtech\Bitcoin\Service\BitcoinCurrencies;
20
use NGUtech\Bitcoin\Service\SatoshiCurrencies;
21
use NGUtech\Bitcoin\ValueObject\Bitcoin;
22
use NGUtech\Bitcoin\ValueObject\Hash;
23
use NGUtech\Bitcoin\ValueObject\OutputList;
24
25
final class BitcoinTransaction extends Entity implements TransactionInterface
26
{
27
    public const AMOUNT_MIN = '1'.SatoshiCurrencies::SAT;
28
    public const AMOUNT_MAX = '21000000'.BitcoinCurrencies::BTC;
29
30
    public static function getAttributeMap(): AttributeMap
31
    {
32
        return new AttributeMap([
33
            Attribute::define('id', Hash::class),
34
            Attribute::define('label', Text::class),
35
            Attribute::define('amount', Bitcoin::class),
36
            Attribute::define('outputs', OutputList::class),
37
            Attribute::define('feeRate', FloatValue::class),
38
            Attribute::define('feeEstimate', Bitcoin::class),
39
            Attribute::define('feeSettled', Bitcoin::class),
40
            Attribute::define('comment', Text::class),
41
            Attribute::define('confTarget', Natural::class),
42
            Attribute::define('confirmations', Natural::class),
43
            Attribute::define('rbf', BoolValue::class),
44
        ]);
45
    }
46
47
    public function getIdentity(): Hash
48
    {
49
        return $this->getId();
50
    }
51
52
    public function getId(): Hash
53
    {
54
        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...
55
    }
56
57
    public function getLabel(): Text
58
    {
59
        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...
60
    }
61
62
    public function getAmount(): Bitcoin
63
    {
64
        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...
65
    }
66
67
    public function getOutputs(): OutputList
68
    {
69
        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 includes types incompatible with the type-hinted return NGUtech\Bitcoin\ValueObject\OutputList. Consider adding an additional type-check to rule them out.
Loading history...
70
    }
71
72
    public function getFeeRate(): FloatValue
73
    {
74
        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...
75
    }
76
77
    public function getFeeEstimate(): Bitcoin
78
    {
79
        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...
80
    }
81
82
    public function getFeeSettled(): Bitcoin
83
    {
84
        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...
85
    }
86
87
    public function getFeeRefund(): Bitcoin
88
    {
89
        return $this->getFeeEstimate()->subtract($this->getFeeSettled());
90
    }
91
92
    public function getComment(): Text
93
    {
94
        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...
95
    }
96
97
    public function getConfTarget(): Natural
98
    {
99
        return $this->get('confTarget') ?? Natural::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('confT...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...
100
    }
101
102
    public function getConfirmations(): Natural
103
    {
104
        return $this->get('confirmations') ?? Natural::makeEmpty();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('confi...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...
105
    }
106
107
    public function getRbf(): BoolValue
108
    {
109
        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...
110
    }
111
}
112