Passed
Push — master ( c05883...1d5c29 )
by Nikolay
02:30
created

AnswerShippingQueryMethod   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 72
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createFail() 0 8 1
A addShippingOption() 0 3 1
A createSuccess() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Method;
6
7
use TgBotApi\BotApiBase\Type\ShippingOption;
8
9
/**
10
 * Class AnswerShippingQueryMethod.
11
 *
12
 * @see https://core.telegram.org/bots/api#answershippingquery
13
 */
14
class AnswerShippingQueryMethod
15
{
16
    /**
17
     * Unique identifier for the query to be answered.
18
     *
19
     * @var string
20
     */
21
    public $shippingQueryId;
22
23
    /**
24
     * Specify True if delivery to the specified address is possible and False if there are any problems
25
     * (for example, if delivery to the specified address is not possible).
26
     *
27
     * @var bool
28
     */
29
    public $ok;
30
31
    /**
32
     * Optional. Required if ok is True. A JSON-serialized array of available shipping options.
33
     *
34
     * @var ShippingOption[]|null
35
     */
36
    public $shippingOptions;
37
38
    /**
39
     * Optional. Required if ok is False.
40
     * Error message in human readable form that explains why it is impossible to complete the order
41
     * (e.g. "Sorry, delivery to your desired address is unavailable').
42
     * Telegram will display this message to the user.
43
     *
44
     * @var string|null
45
     */
46
    public $errorMessage;
47
48
    /**
49
     * @param string $shippingQueryId
50
     * @param array  $shippingOptions
51
     *
52
     * @return AnswerShippingQueryMethod
53
     */
54
    public static function createSuccess(string $shippingQueryId, array $shippingOptions): AnswerShippingQueryMethod
55
    {
56
        $instance = new static();
57
        $instance->shippingQueryId = $shippingQueryId;
58
        $instance->ok = true;
59
        $instance->shippingOptions = $shippingOptions;
60
61
        return $instance;
62
    }
63
64
    /**
65
     * @param string $shippingQueryId
66
     * @param string $errorMessage
67
     *
68
     * @return AnswerShippingQueryMethod
69
     */
70
    public static function createFail(string $shippingQueryId, string $errorMessage): AnswerShippingQueryMethod
71
    {
72
        $instance = new static();
73
        $instance->shippingQueryId = $shippingQueryId;
74
        $instance->ok = false;
75
        $instance->errorMessage = $errorMessage;
76
77
        return $instance;
78
    }
79
80
    /**
81
     * @param ShippingOption $shippingOption
82
     */
83
    public function addShippingOption(ShippingOption $shippingOption)
84
    {
85
        $this->shippingOptions[] = $shippingOption;
86
    }
87
}
88