Get::getFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
declare(strict_types=1);
3
4
5
namespace DyarWeb;
6
7
use DyarWeb\Base;
8
9
/**
10
 * Class Get
11
 * @package DyarWeb
12
 */
13
class Get
14
{
15
    public static $message_id;
16
    //
17
    public static $from_id;
18
    public static bool $from_is_bot;
19
    public static $from_first_name;
20
    public static $from_last_name;
21
    public static $from_username;
22
    public static $language_code;
23
    //
24
    public static $chat_id;
25
    public static $chat_type;
26
    public static $chat_title;
27
    public static $chat_username;
28
    //
29
    public static $date;
30
    public static $text;
31
    public static $caption;
32
    public static $entities;
33
    //
34
    public static $new_chat_member_id;
35
    public static bool $new_chat_member_is_bot;
36
    public static $new_chat_member_first_name;
37
    public static $new_chat_member_last_name;
38
    public static $new_chat_member_username;
39
    public static $new_chat_member_language_code;
40
    public static $left_chat_member_id;
41
    //
42
    public static $forward_from_chat_id;
43
    public static $forward_from_chat_type;
44
    public static $forward_from_chat_title;
45
    public static $forward_from_chat_username;
46
    //
47
    public static $new_chat_photo_file_id;
48
    public static $new_chat_title;
49
    //
50
    public static $callback_query_data;
51
    //
52
    public static $reply_to_from_id;
53
    public static bool $reply_to_from_is_bot;
54
    public static $reply_to_from_first_name;
55
    public static $reply_to_from_last_name;
56
    public static $reply_to_from_username;
57
    public static $reply_to_from_language_code;
58
    public static $reply_to_text;
59
    public static $reply_to_caption;
60
61
62
    /**
63
     * @param $input
64
     */
65
    public static function set($input)
66
    {
67
        if (isset($input->message) || isset($input->edited_message)) {
68
            if (isset($input->message)) $type = 'message';
69
            else $type = 'edited_message';
70
            //
71
            self::$message_id = $input->$type->message_id;
72
            //
73
            self::$from_id = $input->$type->from->id;
74
            self::$from_is_bot = $input->$type->from->is_bot;
75
            self::$from_first_name = $input->$type->from->first_name ?? null;
76
            self::$from_last_name = $input->$type->from->last_name ?? null;
77
            self::$from_username = $input->$type->from->username ?? null;
78
            self::$language_code = $input->$type->from->language_code ?? null;
79
            //
80
            self::$chat_id = $input->$type->chat->id;
81
            self::$chat_type = $input->$type->chat->type ?? null;
82
            self::$chat_title = $input->$type->chat->title;
83
            self::$chat_username = $input->$type->chat->username ?? null;
84
            //
85
            self::$text = $input->$type->text ?? null;
86
            self::$caption = $input->$type->caption ?? null;
87
            self::$entities = $input->$type->entities ?? $input->$type->caption_entities ?? null;
88
            //
89
            self::$left_chat_member_id = $input->$type->left_chat_member->id ?? null;
90
            if (isset($input->$type->reply_to_message)) {
91
                self::$reply_to_from_id = $input->$type->reply_to_message->from->id;
92
                self::$reply_to_from_is_bot = $input->$type->reply_to_message->from->is_bot;
93
                self::$reply_to_from_first_name = $input->$type->reply_to_message->from->first_name ?? null;
94
                self::$reply_to_from_last_name = $input->$type->reply_to_message->from->last_name ?? null;
95
                self::$reply_to_from_username = $input->$type->reply_to_message->from->username ?? null;
96
                self::$reply_to_from_language_code = $input->$type->reply_to_message->from->language_code ?? null;
97
                self::$reply_to_text = $input->$type->reply_to_message->text ?? null;
98
                self::$reply_to_caption = $input->$type->reply_to_message->caption ?? null;
99
            } elseif(isset($input->message->new_chat_member)){
100
                self::$new_chat_member_id = $input->message->new_chat_member->id;
101
                self::$new_chat_member_is_bot = $input->message->new_chat_member->is_bot;
102
                self::$new_chat_member_first_name = $input->message->new_chat_member->first_name ?? null;
103
                self::$new_chat_member_last_name = $input->message->new_chat_member->last_name ?? null;
104
                self::$new_chat_member_username = $input->message->new_chat_member->username ?? null;
105
                self::$new_chat_member_language_code = $input->message->new_chat_member->language_code ?? null;
106
            } elseif(isset($input->message->forward_from_chat)){
107
                self::$forward_from_chat_id = $input->message->forward_from_chat->id;
108
                self::$forward_from_chat_type = $input->message->forward_from_chat->type;
109
                self::$forward_from_chat_title = $input->message->forward_from_chat->title;
110
                self::$forward_from_chat_username = $input->message->forward_from_chat->username ?? null;
111
            } elseif(isset($input->message->new_chat_photo)){
112
                self::$new_chat_photo_file_id = $input->message->new_chat_photo->file_id;
113
            } elseif(isset($input->message->new_chat_title)){
114
                self::$new_chat_title = $input->message->new_chat_title;
115
            }
116
        } elseif (isset($input->callback_query)) {
117
            self::$message_id = $input->callback_query->message->message_id;
118
            self::$from_id = $input->callback_query->from->id;
119
            self::$from_is_bot = $input->callback_query->from->is_bot;
120
            self::$from_first_name = $input->callback_query->from->first_name ?? null;
121
            self::$from_last_name = $input->callback_query->from->last_name ?? null;
122
            self::$from_username = $input->callback_query->from->username ?? null;
123
            self::$language_code = $input->callback_query->from->language_code ?? null;
124
            self::$chat_id = $input->callback_query->message->chat->id;
125
            self::$chat_type = $input->callback_query->message->chat->type ?? null;
126
            self::$chat_title = $input->callback_query->message->chat->title;
127
            self::$chat_username = $input->callback_query->message->chat->username ?? null;
128
            self::$text = $input->callback_query->message->text ?? null;
129
            self::$date = $input->callback_query->message->date ?? null;
130
            self::$callback_query_data = $input->callback_query->data ?? null;
131
        }
132
    }
133
134
    /**
135
     * @param string $file_id
136
     * @return object
137
     */
138
    public function getFile($file_id)
139
    {
140
        return Base::sendRequest('getFile', compact('file_id'));
141
    }
142
143
    /**
144
     * @param string $file_id
145
     * @param string $file_path
146
     * @return object|false
147
     */
148
    /*public function getFileData($file_id, $file_path)
149
    {
150
        return file_get_contents(Base::$baseFileURL . $file_path . '?' . http_build_query(compact('file_id')));
151
    }*/
152
153
    /**
154
     * @param int $user_id
155
     * @param int $offset
156
     * @param int $limit
157
     * @return object
158
     */
159
    public static function getUserProfilePhotos($user_id, $offset = null, $limit = null)
160
    {
161
        $params = compact('user_id', 'offset', 'limit');
162
        return Base::sendRequest('getUserProfilePhotos', $params);
163
    }
164
}
165