Completed
Push — bot_api_3.0 ( 36731b...b0a20f )
by Armando
12s
created

CallbackqueryCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 53
ccs 0
cts 7
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addCallbackHandler() 0 4 1
A execute() 0 14 2
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\Commands\SystemCommands;
12
13
use Longman\TelegramBot\Commands\SystemCommand;
14
use Longman\TelegramBot\Request;
15
16
/**
17
 * Callback query command
18
 */
19
class CallbackqueryCommand extends SystemCommand
20
{
21
    /**
22
     * @var callable[]
23
     */
24
    protected static $callbacks = [];
25
26
    /**
27
     * @var string
28
     */
29
    protected $name = 'callbackquery';
30
31
    /**
32
     * @var string
33
     */
34
    protected $description = 'Reply to callback query';
35
36
    /**
37
     * @var string
38
     */
39
    protected $version = '1.0.0';
40
41
    /**
42
     * Command execute method
43
     *
44
     * @return mixed
45
     * @throws \Longman\TelegramBot\Exception\TelegramException
46
     */
47
    public function execute()
48
    {
49
        //$callback_query = $this->getUpdate()->getCallbackQuery();
50
        //$user_id        = $callback_query->getFrom()->getId();
51
        //$query_id       = $callback_query->getId();
52
        //$query_data     = $callback_query->getData();
53
54
        // Call all registered callbacks.
55
        foreach (self::$callbacks as $callback) {
56
            $callback($this->getUpdate()->getCallbackQuery());
57
        }
58
59
        return Request::answerCallbackQuery(['callback_query_id' => $this->getUpdate()->getCallbackQuery()->getId()]);
60
    }
61
62
    /**
63
     * Add a new callback handler for callback queries.
64
     *
65
     * @param $callback
66
     */
67
    public static function addCallbackHandler($callback)
68
    {
69
        self::$callbacks[] = $callback;
70
    }
71
}
72