Completed
Push — master ( 640da7...eb7508 )
by Danilo
03:54
created

Bot::__destruct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 4
nop 0
crap 12
1
<?php
2
3
/*
4
 * This file is part of the PhpBotFramework.
5
 *
6
 * PhpBotFramework is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation, version 3.
9
 *
10
 * PhpBotFramework is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace PhpBotFramework;
20
21
use PhpBotFramework\Exceptions\BotException;
22
23
// Use inline keyboard with localizated buttons
24
use PhpBotFramework\Localization\Button;
25
26
/** \class Bot Bot class that contains all modules.
27
 */
28
class Bot extends Core\BaseBot
29
{
30
    use Commands\MessageCommand,
31
        Commands\MessageRegexCommand,
32
        Commands\CallbackCommand,
33
        Database\LongPolling,
34
        Database\Handler,
35
        Database\User,
36
        Localization\File,
37
        Localization\Language,
38
        Localization\LocalizedString,
39
        Utilities\BotState;
40
41
    /**
42
     * \addtogroup Bot Bot
43
     * \brief Properties and methods to handle your Telegram's bot.
44
     * \details Here are listed all the properties and methods that will help
45
     * the developers during creation of basic bot's features.
46
     * @{
47
     */
48
49
    /** \brief Store the inline keyboard */
50
    public $keyboard;
51
52
    /** \brief PDO reference to manage database */
53
    public $pdo;
54
55
    /** \brief Redis connection */
56
    public $redis;
57
58
    /**
59
     * \brief Construct an empty bot.
60
     * \details Construct a bot that can handle updates, localization, database
61
     * connection and handling and Redis.
62
     *
63
     * @param string $token Bot token given by BotFather.
64
     */
65
    public function __construct(string $token)
66
    {
67
        parent::__construct($token);
68
69
        $this->_message_commands = [];
70
        $this->_callback_commands = [];
71
72
        $this->keyboard = new Button($this);
73
    }
74
75
    /** \brief Destruct the bot. */
76
    public function __destruct()
77
    {
78
        if (isset($this->redis)) {
79
            $this->redis->close();
80
        }
81
82
        if (isset($this->pdo)) {
83
            $this->pdo = null;
84
        }
85
    }
86
87
    /** @} */
88
}
89