UpdateTypes   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 34
c 1
b 0
f 1
dl 0
loc 93
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllTypes() 0 3 1
A getAllowedTypes() 0 9 3
1
<?php
2
3
4
namespace Sysbot\Telegram\Constants;
5
6
7
/**
8
 * Class UpdateTypes
9
 * @package Sysbot\Telegram\Constants
10
 */
11
class UpdateTypes
12
{
13
14
    /**
15
     * New incoming message of any kind — text, photo, sticker, etc.
16
     */
17
    public const MESSAGE = 1;
18
    /**
19
     * New version of a message that is known to the bot and was edited.
20
     */
21
    public const EDITED_MESSAGE = 2;
22
    /**
23
     * New incoming channel post of any kind — text, photo, sticker, etc.
24
     */
25
    public const CHANNEL_POST = 4;
26
    /**
27
     * New version of a channel post that is known to the bot and was edited.
28
     */
29
    public const EDITED_CHANNEL_POST = 8;
30
    /**
31
     * New incoming inline query.
32
     */
33
    public const INLINE_QUERY = 16;
34
    /**
35
     * The result of an inline query that was chosen by a user and sent to their chat partner.
36
     */
37
    public const CHOSEN_INLINE_RESULT = 32;
38
    /**
39
     * New incoming callback query.
40
     */
41
    public const CALLBACK_QUERY = 64;
42
    /**
43
     * New incoming shipping query. Only for invoices with flexible price.
44
     */
45
    public const SHIPPING_QUERY = 128;
46
    /**
47
     * New incoming pre-checkout query. Contains full information about checkout.
48
     */
49
    public const PRE_CHECKOUT_QUERY = 256;
50
    /**
51
     * New poll state. Bots receive only updates about stopped polls and polls, which are sent by the bot.
52
     */
53
    public const POLL = 512;
54
    /**
55
     * A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.
56
     */
57
    public const POLL_ANSWER = 1024;
58
    /**
59
     * The bot's chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user.
60
     */
61
    public const MY_CHAT_MEMBER = 2048;
62
    /**
63
     * A chat member's status was updated in a chat.
64
     */
65
    public const CHAT_MEMBER = 4096;
66
67
    /**
68
     * All update types.
69
     */
70
    public const TYPES_MAP = [
71
        self::MESSAGE => 'message',
72
        self::EDITED_MESSAGE => 'edited_message',
73
        self::CHANNEL_POST => 'channel_post',
74
        self::EDITED_CHANNEL_POST => 'edited_channel_post',
75
        self::INLINE_QUERY => 'inline_query',
76
        self::CHOSEN_INLINE_RESULT => 'chosen_inline_result',
77
        self::CALLBACK_QUERY => 'callback_query',
78
        self::SHIPPING_QUERY => 'shipping_query',
79
        self::PRE_CHECKOUT_QUERY => 'pre_checkout_query',
80
        self::POLL => 'poll',
81
        self::POLL_ANSWER => 'poll_answer',
82
        self::MY_CHAT_MEMBER => 'my_chat_member',
83
        self::CHAT_MEMBER => 'chat_member'
84
    ];
85
86
    /**
87
     * @param int $types
88
     * @return array
89
     */
90
    public static function getAllowedTypes(int $types): array
91
    {
92
        $result = [];
93
        foreach (self::TYPES_MAP as $flag => $type) {
94
            if ($types & $flag) {
95
                $result[] = $type;
96
            }
97
        }
98
        return $result;
99
    }
100
101
    public static function getAllTypes(): array
102
    {
103
        return array_values(self::TYPES_MAP);
104
    }
105
106
}