Completed
Push — draft ( f5c2f2...2c1ae4 )
by Nikolay
02:24
created

SendInvoiceMethod::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 21
c 0
b 0
f 0
ccs 0
cts 21
cp 0
rs 9.9332
cc 2
nc 2
nop 9
crap 6

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
namespace Greenplugin\TelegramBot\Method;
6
7
use Greenplugin\TelegramBot\Method\Traits\ChatIdVariableTrait;
8
use Greenplugin\TelegramBot\Method\Traits\FillFromArrayTrait;
9
use Greenplugin\TelegramBot\Method\Traits\ReplyMarkupVariableTrait;
10
use Greenplugin\TelegramBot\Type\LabeledPriceType;
11
12
/**
13
 * Class SendInvoiceMethod.
14
 *
15
 * @see https://core.telegram.org/bots/api#sendinvoice
16
 */
17
class SendInvoiceMethod
18
{
19
    use FillFromArrayTrait;
20
    use ChatIdVariableTrait;
21
    use ReplyMarkupVariableTrait;
22
23
    /**
24
     * Product name, 1-32 characters.
25
     *
26
     * @var string
27
     */
28
    public $title;
29
30
    /**
31
     * Product description, 1-255 characters.
32
     *
33
     * @var string
34
     */
35
    public $description;
36
37
    /**
38
     * Bot-defined invoice payload, 1-128 bytes.
39
     * This will not be displayed to the user, use for your internal processes.
40
     *
41
     * @var string
42
     */
43
    public $payload;
44
45
    /**
46
     * Payments provider token, obtained via Botfather.
47
     *
48
     * @var string
49
     */
50
    public $providerToken;
51
52
    /**
53
     * Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter.
54
     *
55
     * @var string
56
     */
57
    public $startParameter;
58
59
    /**
60
     * Three-letter ISO 4217 currency code, see more on currencies.
61
     *
62
     * @var string
63
     */
64
    public $currency;
65
66
    /**
67
     * Price breakdown, a list of components
68
     * (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
69
     *
70
     * @var LabeledPriceType[]
71
     */
72
    public $prices;
73
74
    /**
75
     * Optional. JSON-encoded data about the invoice, which will be shared with the payment provider.
76
     * A detailed description of required fields should be provided by the payment provider.
77
     *
78
     * @var string|null
79
     */
80
    public $providerData;
81
82
    /**
83
     * Optional. URL of the product photo for the invoice.
84
     * Can be a photo of the goods or a marketing image for a service.
85
     * People like it better when they see what they are paying for.
86
     *
87
     * @var string|null
88
     */
89
    public $photoUrl;
90
91
    /**
92
     * Optional. Photo size.
93
     *
94
     * @var int|null
95
     */
96
    public $photoSize;
97
98
    /**
99
     * Optional. Photo width.
100
     *
101
     * @var int|null
102
     */
103
    public $photoWidth;
104
105
    /**
106
     * Optional. Photo height.
107
     *
108
     * @var int|null
109
     */
110
    public $photoHeight;
111
112
    /**
113
     * Optional. Pass True, if you require the user's full name to complete the order.
114
     *
115
     * @var bool|null
116
     */
117
    public $needName;
118
119
    /**
120
     * Optional. Pass True, if you require the user's phone number to complete the order.
121
     *
122
     * @var bool|null
123
     */
124
    public $needPhoneNumber;
125
126
    /**
127
     * Optional. Pass True, if you require the user's email address to complete the order.
128
     *
129
     * @var bool|null
130
     */
131
    public $needEmail;
132
133
    /**
134
     * Optional. Pass True, if you require the user's shipping address to complete the order.
135
     *
136
     * @var bool|null
137
     */
138
    public $needShippingAddress;
139
140
    /**
141
     * Optional. Pass True, if user's phone number should be sent to provider.
142
     *
143
     * @var bool|null
144
     */
145
    public $sendPhoneNumberToProvider;
146
147
    /**
148
     * Optional. Pass True, if user's email address should be sent to provider.
149
     *
150
     * @var bool|null
151
     */
152
    public $sendEmailToProvider;
153
154
    /**
155
     * Optional. Pass True, if the final price depends on the shipping method.
156
     *
157
     * @var bool|null
158
     */
159
    public $isFlexible;
160
161
    /**
162
     * Optional. Sends the message silently. Users will receive a notification with no sound.
163
     *
164
     * @var bool|null
165
     */
166
    public $disableNotification;
167
168
    /**
169
     * Optional. If the message is a reply, ID of the original message.
170
     *
171
     * @var int|null
172
     */
173
    public $replyToMessageId;
174
175
    /**
176
     * SendInvoiceMethod constructor.
177
     *
178
     * @param int|string $chatId
179
     * @param string     $title
180
     * @param string     $description
181
     * @param string     $payload
182
     * @param string     $providerToken
183
     * @param string     $startParameter
184
     * @param string     $currency
185
     * @param array      $prices
186
     * @param array|null $data
187
     *
188
     * @throws \Greenplugin\TelegramBot\Exception\BadArgumentException
189
     */
190
    public function __construct(
191
        $chatId,
192
        string $title,
193
        string $description,
194
        string $payload,
195
        string $providerToken,
196
        string $startParameter,
197
        string $currency,
198
        array $prices,
199
        array $data = null
200
    ) {
201
        $this->chatId = $chatId;
202
        $this->title = $title;
203
        $this->description = $description;
204
        $this->payload = $payload;
205
        $this->providerToken = $providerToken;
206
        $this->startParameter = $startParameter;
207
        $this->currency = $currency;
208
        $this->prices = $prices;
209
        if ($data) {
210
            $this->fill($data);
211
        }
212
    }
213
}
214