Completed
Push — master ( 410ea8...0c9ae2 )
by thomas
105:23 queued 33:17
created

OutPoint   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 6
c 2
b 0
f 2
lcom 0
cbo 4
dl 0
loc 61
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 3
A getTxId() 0 4 1
A getVout() 0 4 1
A getBuffer() 0 4 1
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction;
4
5
use BitWasp\Bitcoin\Serializable;
6
use BitWasp\Bitcoin\Serializer\Transaction\OutPointSerializer;
7
use BitWasp\Buffertools\Buffer;
8
use BitWasp\CommonTrait\FunctionAliasArrayAccess;
9
10
class OutPoint extends Serializable implements OutPointInterface
11
{
12
    use FunctionAliasArrayAccess;
13
14
    /**
15
     * @var Buffer
16
     */
17
    private $hashPrevOutput;
18
19
    /**
20
     * @var int
21
     */
22
    private $nPrevOutput;
23
24
    /**
25
     * OutPoint constructor.
26
     * @param Buffer $hashPrevOutput
27
     * @param int $nPrevOutput
28
     */
29
    public function __construct(Buffer $hashPrevOutput, $nPrevOutput)
30
    {
31
        if ($hashPrevOutput->getSize() !== 32) {
32
            throw new \InvalidArgumentException('OutPoint: hashPrevOut must be a 32-byte Buffer');
33
        }
34
35
        if (!is_numeric($nPrevOutput)) {
36
            throw new \InvalidArgumentException('OutPoint: nPrevOut must be numeric');
37
        }
38
39
        $this->hashPrevOutput = $hashPrevOutput;
40
        $this->nPrevOutput = $nPrevOutput;
0 ignored issues
show
Documentation Bug introduced by
It seems like $nPrevOutput can also be of type double or string. However, the property $nPrevOutput is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
41
42
        $this
43
            ->initFunctionAlias('txid', 'getTxId')
44
            ->initFunctionAlias('vout', 'getVout');
45
    }
46
47
    /**
48
     * @return Buffer
49
     */
50
    public function getTxId()
51
    {
52
        return $this->hashPrevOutput;
53
    }
54
55
    /**
56
     * @return int
57
     */
58
    public function getVout()
59
    {
60
        return $this->nPrevOutput;
61
    }
62
63
    /**
64
     * @return Buffer
65
     */
66
    public function getBuffer()
67
    {
68
        return (new OutPointSerializer())->serialize($this);
69
    }
70
}
71