CallbackqueryCommand::addCallbackHandler()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the TelegramBot package.
5
 *
6
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Longman\TelegramBot\Commands\SystemCommands;
13
14
use Longman\TelegramBot\Commands\SystemCommand;
15
use Longman\TelegramBot\Entities\ServerResponse;
16
17
/**
18
 * Callback query command
19
 */
20
class CallbackqueryCommand extends SystemCommand
21
{
22
    /**
23
     * @var callable[]
24
     */
25
    protected static $callbacks = [];
26
27
    /**
28
     * @var string
29
     */
30
    protected $name = 'callbackquery';
31
32
    /**
33
     * @var string
34
     */
35
    protected $description = 'Reply to callback query';
36
37
    /**
38
     * @var string
39
     */
40
    protected $version = '1.0.0';
41
42
    /**
43
     * Command execute method
44
     *
45
     * @return ServerResponse
46
     */
47
    public function execute(): ServerResponse
48
    {
49
        //$callback_query = $this->getCallbackQuery();
50
        //$user_id        = $callback_query->getFrom()->getId();
51
        //$query_id       = $callback_query->getId();
52
        //$query_data     = $callback_query->getData();
53
54
        $answer         = null;
55
        $callback_query = $this->getCallbackQuery();
56
57
        // Call all registered callbacks.
58
        foreach (self::$callbacks as $callback) {
59
            $answer = $callback($callback_query);
60
        }
61
62
        return ($answer instanceof ServerResponse) ? $answer : $callback_query->answer();
63
    }
64
65
    /**
66
     * Add a new callback handler for callback queries.
67
     *
68
     * @param $callback
69
     */
70
    public static function addCallbackHandler($callback): void
71
    {
72
        self::$callbacks[] = $callback;
73
    }
74
}
75