Passed
Push — master ( 45bce2...5a8248 )
by Nikolay
03:20
created

GetMethodTrait::getChatMembersCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Helper;
6
7
use TgBotApi\BotApiBase\Exception\NormalizationException;
8
use TgBotApi\BotApiBase\Exception\ResponseException;
9
use TgBotApi\BotApiBase\Method\GetChatAdministratorsMethod;
10
use TgBotApi\BotApiBase\Method\GetChatMemberMethod;
11
use TgBotApi\BotApiBase\Method\GetChatMembersCountMethod;
12
use TgBotApi\BotApiBase\Method\GetChatMethod;
13
use TgBotApi\BotApiBase\Method\GetFileMethod;
14
use TgBotApi\BotApiBase\Method\GetGameHighScoresMethod;
15
use TgBotApi\BotApiBase\Method\GetMeMethod;
16
use TgBotApi\BotApiBase\Method\GetStickerSetMethod;
17
use TgBotApi\BotApiBase\Method\GetUpdatesMethod;
18
use TgBotApi\BotApiBase\Method\GetUserProfilePhotosMethod;
19
use TgBotApi\BotApiBase\Method\GetWebhookInfoMethod;
20
use TgBotApi\BotApiBase\Type\ChatMemberType;
21
use TgBotApi\BotApiBase\Type\ChatType;
22
use TgBotApi\BotApiBase\Type\FileType;
23
use TgBotApi\BotApiBase\Type\GameHighScoreType;
24
use TgBotApi\BotApiBase\Type\StickerSetType;
25
use TgBotApi\BotApiBase\Type\UpdateType;
26
use TgBotApi\BotApiBase\Type\UserProfilePhotosType;
27
use TgBotApi\BotApiBase\Type\UserType;
28
use TgBotApi\BotApiBase\Type\WebhookInfoType;
29
30
trait GetMethodTrait
31
{
32
    /**
33
     * @param $method
34
     * @param $type
35
     *
36
     * @throws ResponseException
37
     * @throws NormalizationException
38
     *
39
     * @return mixed
40
     */
41
    abstract public function call($method, $type = null);
42
43
    /**
44
     * @param GetUpdatesMethod $method
45
     *
46
     * @throws ResponseException
47
     * @throws NormalizationException
48
     *
49
     * @return UpdateType[]
50
     */
51 6
    public function getUpdates(GetUpdatesMethod $method): array
52
    {
53 6
        return $this->call($method, UpdateType::class . '[]');
54
    }
55
56
    /**
57
     * @param GetMeMethod $method
58
     *
59
     * @throws ResponseException
60
     * @throws NormalizationException
61
     *
62
     * @return UserType
63
     */
64 6
    public function getMe(GetMeMethod $method): UserType
65
    {
66 6
        return $this->call($method, UserType::class);
67
    }
68
69
    /**
70
     * @param GetUserProfilePhotosMethod $method
71
     *
72
     * @throws ResponseException
73
     * @throws NormalizationException
74
     *
75
     * @return UserProfilePhotosType
76
     */
77 6
    public function getUserProfilePhotos(GetUserProfilePhotosMethod $method): UserProfilePhotosType
78
    {
79 6
        return $this->call($method, UserProfilePhotosType::class);
80
    }
81
82
    /**
83
     * @param GetWebhookInfoMethod $method
84
     *
85
     * @throws ResponseException
86
     * @throws NormalizationException
87
     *
88
     * @return WebhookInfoType
89
     */
90 3
    public function getWebhookInfo(GetWebhookInfoMethod $method): WebhookInfoType
91
    {
92 3
        return $this->call($method, WebhookInfoType::class);
93
    }
94
95
    /**
96
     * @param GetChatMembersCountMethod $method
97
     *
98
     * @throws ResponseException
99
     * @throws NormalizationException
100
     *
101
     * @return int
102
     */
103 3
    public function getChatMembersCount(GetChatMembersCountMethod $method): int
104
    {
105 3
        return $this->call($method);
106
    }
107
108
    /**
109
     * @param GetChatMethod $method
110
     *
111
     * @throws ResponseException
112
     * @throws NormalizationException
113
     *
114
     * @return ChatType
115
     */
116 6
    public function getChat(GetChatMethod $method): ChatType
117
    {
118 6
        return $this->call($method, ChatType::class);
119
    }
120
121
    /**
122
     * @param GetChatAdministratorsMethod $method
123
     *
124
     * @throws ResponseException
125
     * @throws NormalizationException
126
     *
127
     * @return ChatMemberType[]
128
     */
129 6
    public function getChatAdministrators(GetChatAdministratorsMethod $method): array
130
    {
131 6
        return $this->call($method, ChatMemberType::class . '[]');
132
    }
133
134
    /**
135
     * @param GetChatMemberMethod $method
136
     *
137
     * @throws ResponseException
138
     * @throws NormalizationException
139
     *
140
     * @return ChatMemberType
141
     */
142 6
    public function getChatMember(GetChatMemberMethod $method): ChatMemberType
143
    {
144 6
        return $this->call($method, ChatMemberType::class);
145
    }
146
147
    /**
148
     * @param GetGameHighScoresMethod $method
149
     *
150
     * @throws NormalizationException
151
     * @throws ResponseException
152
     *
153
     * @return GameHighScoreType[]
154
     */
155 6
    public function getGameHighScores(GetGameHighScoresMethod $method): array
156
    {
157 6
        return $this->call($method, GameHighScoreType::class . '[]');
158
    }
159
160
    /**
161
     * @param GetStickerSetMethod $method
162
     *
163
     * @throws NormalizationException
164
     * @throws ResponseException
165
     *
166
     * @return StickerSetType
167
     */
168 3
    public function getStickerSet(GetStickerSetMethod $method): StickerSetType
169
    {
170 3
        return $this->call($method, StickerSetType::class);
171
    }
172
173
    /**
174
     * @param GetFileMethod $method
175
     *
176
     * @throws ResponseException
177
     * @throws NormalizationException
178
     *
179
     * @return FileType
180
     */
181 6
    public function getFile(GetFileMethod $method): FileType
182
    {
183 6
        return $this->call($method, FileType::class);
184
    }
185
}
186