Completed
Push — master ( 23095d...54d687 )
by Danilo
02:12
created

Bot::processUpdate()   D

Complexity

Conditions 22
Paths 22

Size

Total Lines 157
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 157
rs 4.6625
c 0
b 0
f 0
cc 22
eloc 56
nc 22
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PhpBotFramework;
4
5
use PhpBotFramework\Exceptions\BotException;
6
7
use PhpBotFramework\Entities\InlineKeyboard;
8
9
class Bot extends Core\BaseBot {
10
11
    use Commands\CommandHandler,
12
        Commands\MessageCommand,
13
        Commands\MessageRegexCommand,
14
        Commands\CallbackCommand,
15
        Database\LongPolling,
16
        Database\DatabaseHandler,
17
        Utilities\BotState,
18
        Utilities\Localization;
19
20
    /**
21
     * \addtogroup Bot Bot
22
     * \brief Properties and methods to handle the TelegramBot.
23
     * \details Here are listed all the properties and methods that will help the developer create the basic bot functions.
24
     * @{
25
     */
26
27
    /** \brief Store the inline keyboard */
28
    public $keyboard;
29
30
    /** \brief Pdo reference */
31
    public $pdo;
32
33
    /** \brief Redis connection */
34
    public $redis;
35
36
    /**
37
     * \brief Construct an empty bot.
38
     * \details Construct a bot that can handle updates, localization, database connection and handling, redis database.
39
     */
40
    public function __construct(string $token) {
41
42
        // Parent constructor
43
        parent::__construct($token);
44
45
        // Initialize to an empty array
46
        $this->_message_commands = [];
47
        $this->_callback_commands = [];
48
49
        $this->keyboard = new InlineKeyboard($this);
50
51
    }
52
53
    /** \brief Descruct the bot. */
54
    public function __destruct() {
55
56
        // Close redis connection if it is open
57
        if (isset($this->redis)) {
58
59
            $this->redis->close();
60
61
        }
62
63
        // Close database connection if it is open
64
        if (isset($this->pdo)) {
65
66
            $this->pdo = null;
67
68
        }
69
70
    }
71
72
    /**
73
     * \addtogroup Core Core(Internal)
74
     * @{
75
     */
76
77
    /**
78
     * \brief Init variables to skip parsing commands if there aren't any.
79
     * \details Called internnaly by
80
     * - <code>getUpdatesLocal</code>
81
     * - <code>getUpdatesRedis</code>
82
     * - <code>getUpdatesDatabase</code>
83
     * - <code>processWebhookUpdate</code>
84
     */
85
    private function initBot() {
86
87
        // Are there message commands?
88
        $this->_message_commands_set = !empty($this->_message_commands);
0 ignored issues
show
Bug introduced by
The property _message_commands_set does not seem to exist. Did you mean _message_commands?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
89
90
        // Are there callback commands?
91
        $this->_callback_commands_set = !empty($this->_callback_commands);
0 ignored issues
show
Bug introduced by
The property _callback_commands_set does not seem to exist. Did you mean _callback_commands?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
92
93
    }
94
95
}
96