Completed
Push — master ( 989005...ce143f )
by Camilo
04:43
created

AnswerShippingQuery   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 46
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMandatoryFields() 0 16 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\Telegram\Methods;
6
7
use unreal4u\TelegramAPI\Abstracts\TelegramMethods;
8
9
/**
10
 * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will
11
 * send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. On success, True
12
 * is returned.
13
 *
14
 * Objects defined as-is May 2017
15
 *
16
 * @see https://core.telegram.org/bots/api#answershippingquery
17
 */
18
class AnswerShippingQuery extends TelegramMethods
19
{
20
    /**
21
     * Unique identifier for the query to be answered
22
     * @var string
23
     */
24
    public $shipping_query_id = '';
25
26
    /**
27
     * Specify True if delivery to the specified address is possible and False if there are any problems (for example,
28
     * if delivery to the specified address is not possible)
29
     * @var bool
30
     */
31
    public $ok;
32
33
    /**
34
     * Required if ok is True. A JSON-serialized array of available shipping options
35
     * @var ShippingOption[]
36
     */
37
    public $shipping_options = [];
38
39
    /**
40
     * Required if ok is False. Error message in human readable form that explains why it is impossible to complete the
41
     * order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the
42
     * user
43
     * @var string
44
     */
45
    public $error_message = '';
46
47
    public function getMandatoryFields(): array
48
    {
49
        $return = [
50
            'shipping_query_id',
51
            'ok',
52
        ];
53
54
        // Shipping options are mandatory if ok is set to true, otherwise, error_message is
55
        if ($this->ok === true) {
56
            $return[] = 'shipping_options';
57
        } else {
58
            $return[] = 'error_message';
59
        }
60
61
        return $return;
62
    }
63
}
64