Completed
Push — master ( 3845e2...a95f7d )
by Danilo
09:37
created

Bot   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 12

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 12
dl 0
loc 59
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __destruct() 0 10 3
A __construct() 0 9 1
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 localized inline keyboard: this means you can display it in various languages.
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 Telegrams bot.
44
     * \details Here're listed all the properties and methods that offers facilities for bot's basic features.
45
     * @{
46
     */
47
48
    /** \brief Store the inline keyboard */
49
    public $keyboard;
50
51
    /** \brief Manage connection with database using PDO */
52
    public $pdo;
53
54
    /** \brief Manage connection with Redis */
55
    public $redis;
56
57
    /**
58
     * \brief Construct an empty bot.
59
     * \details Construct a complete Telegram bot which can use localization, database and more other.
60
     *
61
     * @param string $token Bot token, you can request one through **BotFather** on Telegram.
62
     */
63
    public function __construct(string $token)
64
    {
65
        parent::__construct($token);
66
67
        $this->_message_commands = [];
68
        $this->_callback_commands = [];
69
70
        $this->keyboard = new Button($this);
71
    }
72
73
    /** \brief Destroy the bot closing connections with database and Redis */
74
    public function __destruct()
75
    {
76
        if (isset($this->redis)) {
77
            $this->redis->close();
78
        }
79
80
        if (isset($this->pdo)) {
81
            $this->pdo = null;
82
        }
83
    }
84
85
    /** @} */
86
}
87