Completed
Pull Request — master (#28)
by Nikolay
11:57
created

GetMethodTrait::getMyCommands()   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
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TgBotApi\BotApiBase\Traits;
6
7
use TgBotApi\BotApiBase\Exception\ResponseException;
8
use TgBotApi\BotApiBase\Method\GetChatAdministratorsMethod;
9
use TgBotApi\BotApiBase\Method\GetChatMemberMethod;
10
use TgBotApi\BotApiBase\Method\GetChatMembersCountMethod;
11
use TgBotApi\BotApiBase\Method\GetChatMethod;
12
use TgBotApi\BotApiBase\Method\GetFileMethod;
13
use TgBotApi\BotApiBase\Method\GetGameHighScoresMethod;
14
use TgBotApi\BotApiBase\Method\GetMeMethod;
15
use TgBotApi\BotApiBase\Method\GetMyCommandsMethod;
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\Method\Interfaces\MethodInterface;
21
use TgBotApi\BotApiBase\Type\BotCommandType;
22
use TgBotApi\BotApiBase\Type\ChatMemberType;
23
use TgBotApi\BotApiBase\Type\ChatType;
24
use TgBotApi\BotApiBase\Type\FileType;
25
use TgBotApi\BotApiBase\Type\GameHighScoreType;
26
use TgBotApi\BotApiBase\Type\StickerSetType;
27
use TgBotApi\BotApiBase\Type\UpdateType;
28
use TgBotApi\BotApiBase\Type\UserProfilePhotosType;
29
use TgBotApi\BotApiBase\Type\UserType;
30
use TgBotApi\BotApiBase\Type\WebhookInfoType;
31
32
trait GetMethodTrait
33
{
34
    /**
35
     * @param $type
36
     *
37
     * @throws ResponseException
38
     *
39
     * @return mixed
40
     */
41
    abstract public function call(MethodInterface $method, string $type = null);
42
43
    /**
44
     * @throws ResponseException
45
     *
46
     * @return UpdateType[]
47
     */
48 6
    public function getUpdates(GetUpdatesMethod $method): array
49
    {
50 6
        return $this->call($method, UpdateType::class . '[]');
51
    }
52
53
    /**
54
     * @throws ResponseException
55
     */
56 6
    public function getMe(GetMeMethod $method): UserType
57
    {
58 6
        return $this->call($method, UserType::class);
59
    }
60
61
    /**
62
     * @throws ResponseException
63
     *
64
     * @return mixed
65
     */
66 3
    public function getMyCommands(GetMyCommandsMethod $method)
67
    {
68 3
        return $this->call($method, BotCommandType::class);
69
    }
70
71
    /**
72
     * @throws ResponseException
73
     */
74 6
    public function getUserProfilePhotos(GetUserProfilePhotosMethod $method): UserProfilePhotosType
75
    {
76 6
        return $this->call($method, UserProfilePhotosType::class);
77
    }
78
79
    /**
80
     * @throws ResponseException
81
     */
82 3
    public function getWebhookInfo(GetWebhookInfoMethod $method): WebhookInfoType
83
    {
84 3
        return $this->call($method, WebhookInfoType::class);
85
    }
86
87
    /**
88
     * @throws ResponseException
89
     */
90 3
    public function getChatMembersCount(GetChatMembersCountMethod $method): int
91
    {
92 3
        return $this->call($method);
93
    }
94
95
    /**
96
     * @throws ResponseException
97
     */
98 6
    public function getChat(GetChatMethod $method): ChatType
99
    {
100 6
        return $this->call($method, ChatType::class);
101
    }
102
103
    /**
104
     * @throws ResponseException
105
     *
106
     * @return ChatMemberType[]
107
     */
108 6
    public function getChatAdministrators(GetChatAdministratorsMethod $method): array
109
    {
110 6
        return $this->call($method, ChatMemberType::class . '[]');
111
    }
112
113
    /**
114
     * @throws ResponseException
115
     */
116 6
    public function getChatMember(GetChatMemberMethod $method): ChatMemberType
117
    {
118 6
        return $this->call($method, ChatMemberType::class);
119
    }
120
121
    /**
122
     * @throws ResponseException
123
     *
124
     * @return GameHighScoreType[]
125
     */
126 6
    public function getGameHighScores(GetGameHighScoresMethod $method): array
127
    {
128 6
        return $this->call($method, GameHighScoreType::class . '[]');
129
    }
130
131
    /**
132
     * @throws ResponseException
133
     */
134 3
    public function getStickerSet(GetStickerSetMethod $method): StickerSetType
135
    {
136 3
        return $this->call($method, StickerSetType::class);
137
    }
138
139
    /**
140
     * @throws ResponseException
141
     */
142 6
    public function getFile(GetFileMethod $method): FileType
143
    {
144 6
        return $this->call($method, FileType::class);
145
    }
146
}
147