Completed
Pull Request — master (#125)
by thomas
75:30 queued 72:15
created

UTXO::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 9
dl 0
loc 21
ccs 0
cts 11
cp 0
crap 2
rs 9.584
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Blocktrail\SDK;
4
5
use BitWasp\Bitcoin\Address\AddressInterface;
6
use BitWasp\Bitcoin\Script\ScriptInterface;
7
use BitWasp\Bitcoin\Transaction\TransactionOutput;
8
9
class UTXO {
10
11
    public $hash;
12
    public $index;
13
    public $value;
14
15
    /**
16
     * @var AddressInterface
17
     */
18
    public $address;
19
20
    /**
21
     * @var ScriptInterface
22
     */
23
    public $scriptPubKey;
24
    public $path;
25
26
    /**
27
     * @var ScriptInterface
28
     */
29
    public $redeemScript;
30
31
    /**
32
     * @var ScriptInterface|null
33
     */
34
    public $witnessScript;
35
36
    /**
37
     * @var string
38
     */
39
    public $signMode;
40
41
    /**
42
     * UTXO constructor.
43
     * @param $hash
44
     * @param $index
45
     * @param null $value
46
     * @param AddressInterface|null $address
47
     * @param ScriptInterface|null $scriptPubKey
48
     * @param null $path
49
     * @param ScriptInterface|null $redeemScript
50
     * @param ScriptInterface|null $witnessScript
51
     * @param string $signMode
52
     */
53
    public function __construct(
54
        $hash,
55
        $index,
56
        $value = null,
57
        AddressInterface $address = null,
58
        ScriptInterface $scriptPubKey = null,
59
        $path = null,
60
        ScriptInterface $redeemScript = null,
61
        ScriptInterface $witnessScript = null,
62
        $signMode = SignInfo::MODE_SIGN
63
    ) {
64
        $this->hash = $hash;
65
        $this->index = $index;
66
        $this->value = $value;
67
        $this->address = $address;
68
        $this->scriptPubKey = $scriptPubKey;
69
        $this->path = $path;
70
        $this->redeemScript = $redeemScript;
71
        $this->witnessScript = $witnessScript;
72
        $this->signMode = $signMode;
73
    }
74
75
    /**
76
     * @return SignInfo
77
     */
78
    public function getSignInfo() {
79
        return new SignInfo(new TransactionOutput($this->value, $this->scriptPubKey), $this->signMode, $this->path, $this->redeemScript, $this->witnessScript);
0 ignored issues
show
Bug introduced by
It seems like $this->path can also be of type array; however, Blocktrail\SDK\SignInfo::__construct() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
80
    }
81
}
82