Completed
Pull Request — develop (#291)
by Armando
03:42
created

Update::getUpdateContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot\Entities;
12
13
/**
14
 * Class Update
15
 *
16
 * @link https://core.telegram.org/bots/api#update
17
 *
18
 * @method int                 getUpdateId()           The update's unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order.
19
 * @method Message             getMessage()            Optional. New incoming message of any kind — text, photo, sticker, etc.
20
 * @method Message             getEditedMessage()      Optional. New version of a message that is known to the bot and was edited
21
 * @method InlineQuery         getInlineQuery()        Optional. New incoming inline query
22
 * @method ChosenInlineResult  getChosenInlineResult() Optional. The result of an inline query that was chosen by a user and sent to their chat partner.
23
 * @method CallbackQuery       getCallbackQuery()      Optional. New incoming callback query
24
 */
25
class Update extends Entity
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30 7
    protected function subEntities()
31
    {
32
        return [
33 7
            'message'              => Message::class,
34
            'edited_message'       => EditedMessage::class,
35
            'inline_query'         => InlineQuery::class,
36
            'chosen_inline_result' => ChosenInlineResult::class,
37
            'callback_query'       => CallbackQuery::class,
38
        ];
39
    }
40
41
    /**
42
     * Get the update type based on the set properties
43
     *
44
     * @return string|null
45
     */
46
    public function getUpdateType()
47
    {
48
        $types = [
49
            'message',
50
            'edited_message',
51
            'inline_query',
52
            'chosen_inline_result',
53
            'callback_query',
54
        ];
55
        foreach ($types as $type) {
56
            if ($this->getProperty($type)) {
57
                return $type;
58
            }
59
        }
60
61
        return null;
62
    }
63
64
    /**
65
     * Get update content
66
     *
67
     * @return \Longman\TelegramBot\Entities\CallbackQuery
68
     *         |\Longman\TelegramBot\Entities\ChosenInlineResult
69
     *         |\Longman\TelegramBot\Entities\InlineQuery
70
     *         |\Longman\TelegramBot\Entities\Message
71
     */
72
    public function getUpdateContent()
73
    {
74
        if ($update_type = $this->getUpdateType()) {
75
            return $this->getProperty($update_type);
76
        }
77
78
        return null;
79
    }
80
}
81