Completed
Push — master ( e9be36...9488e8 )
by Camilo
04:57
created

Update::mapSubObjects()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 8.8571
cc 6
eloc 12
nc 6
nop 2
crap 6
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\Telegram\Types;
6
7
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
8
use unreal4u\TelegramAPI\Telegram\Types\Inline\ChosenResult;
9
use unreal4u\TelegramAPI\Telegram\Types\Inline\Query;
10
11
/**
12
 * This object represents an incoming update.
13
 * Only one of the optional parameters can be present in any given update.
14
 *
15
 * Objects defined as-is july 2016
16
 *
17
 * @see https://core.telegram.org/bots/api#update
18
 */
19
class Update extends TelegramTypes
20
{
21
    /**
22
     * The update‘s unique identifier. Update identifiers start from a certain positive number and increase
23
     * sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated
24
     * updates or to restore the correct update sequence, should they get out of order.
25
     * @var int
26
     */
27
    public $update_id = 0;
28
29
    /**
30
     * Optional. New incoming message of any kind — text, photo, sticker, etc.
31
     * @var Message
32
     */
33
    public $message = null;
34
35
    /**
36
     * Optional. New version of a message that is known to the bot and was edited
37
     * @var Message
38
     */
39
    public $edited_message = null;
40
41
    /**
42
     * Optional. New incoming inline query
43
     * @var null
44
     */
45
    public $inline_query = null;
46
47
    /**
48
     * Optional. The result of a inline query that was chosen by a user and sent to their chat partner
49
     * @var null
50
     */
51
    public $chosen_inline_result = null;
52
53
    /**
54
     * Optional. New incoming callback query
55
     * @var CallbackQuery
56
     */
57
    public $callback_query = null;
58
59 3
    protected function mapSubObjects(string $key, array $data): TelegramTypes
60
    {
61
        switch ($key) {
62 3
            case 'message':
63 2
            case 'edited_message':
64 1
                return new Message($data, $this->logger);
65 2
            case 'inline_query':
66 1
                return new Query($data, $this->logger);
67 1
            case 'chosen_inline_result':
68 1
                return new ChosenResult($data, $this->logger);
69
            case 'callback_query':
70
                return new CallbackQuery($data, $this->logger);
71
        }
72
73
        return parent::mapSubObjects($key, $data);
74
    }
75
}
76