Passed
Push — master ( 0eceda...005e86 )
by Mr
02:33
created

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