Completed
Push — master ( f41514...1e2a43 )
by Nikolay
02:48
created

AnswerShippingQueryMethod::createFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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