AddressTransactionsRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 18
rs 10

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
declare(strict_types=1);
4
5
/*
6
 * Package: PHP Bitaps API
7
 *
8
 * (c) Eldar Gazaliev <[email protected]>
9
 *
10
 *  Link: <https://github.com/MyZik>
11
 *
12
 * For the full copyright and license information, please view the LICENSE file
13
 * that was distributed with this source code.
14
 */
15
16
namespace Bitaps\WalletAPI\Request;
17
18
class AddressTransactionsRequest implements RequestInterface
19
{
20
    /**
21
     * Wallet ID
22
     *
23
     * @var string
24
     */
25
    public string $walletId;
26
27
    /**
28
     * Address
29
     *
30
     * @var string
31
     */
32
    private string $address;
33
34
    /**
35
     * Nonce used for HMAC signature
36
     *
37
     * @var float|null
38
     */
39
    public ?float $nonce;
40
41
    /**
42
     * HMAC signature
43
     *
44
     * @var string|null
45
     */
46
    public ?string $signature;
47
48
    /**
49
     * Beginning of range in unix timestamp
50
     *
51
     * @var int|null
52
     */
53
    private ?int $from;
54
55
    /**
56
     * Ending of range in unix timestamp
57
     *
58
     * @var int|null
59
     */
60
    private ?int $to;
61
62
    /**
63
     * Records on page
64
     *
65
     * @var int|null
66
     */
67
    private ?int $limit;
68
69
    /**
70
     * Page number
71
     *
72
     * @var int|null
73
     */
74
    private ?int $page;
75
76
    /**
77
     * @param string      $walletId
78
     * @param string      $address
79
     * @param float|null  $nonce
80
     * @param string|null $signature
81
     * @param int|null    $from
82
     * @param int|null    $to
83
     * @param int|null    $limit
84
     * @param int|null    $page
85
     */
86
    public function __construct(
87
        string $walletId,
88
        string $address,
89
        float $nonce = null,
90
        string $signature = null,
91
        int $from = null,
92
        int $to = null,
93
        int $limit = null,
94
        int $page = null
95
    ) {
96
        $this->walletId  = $walletId;
97
        $this->address   = $address;
98
        $this->nonce     = $nonce;
99
        $this->signature = $signature;
100
        $this->from      = $from;
101
        $this->to        = $to;
102
        $this->limit     = $limit;
103
        $this->page      = $page;
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getPathParams(): string
110
    {
111
        return sprintf(
112
            "/wallet/address/transactions/%s/%s?from=%d&to=%d&limit=%d&page=%d",
113
            $this->walletId,
114
            $this->address,
115
            $this->from,
116
            $this->to,
117
            $this->limit,
118
            $this->page
119
        );
120
    }
121
122
    /**
123
     * @return array
124
     */
125
    public function getHeaders(): array
126
    {
127
        return [
128
            'Access-Nonce' => $this->nonce,
129
            'Access-Signature' => $this->signature
130
        ];
131
    }
132
133
    /**
134
     * @return array
135
     */
136
    public function getBody(): array
137
    {
138
        return [];
139
    }
140
}
141