Skip to content

Commit c51f8d5

Browse files
committed
Merge pull request #2 from noplanman/conversations_typos
Correct typos and minor code styling.
2 parents 4df1b58 + e02f104 commit c51f8d5

File tree

2 files changed

+37
-39
lines changed

2 files changed

+37
-39
lines changed

src/Conversation.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Conversation
4949
protected $user_id;
5050

5151
/**
52-
* Telegram chat_id
52+
* Telegram chat id
5353
*
5454
* @var int
5555
*/
@@ -59,23 +59,23 @@ class Conversation
5959
* Group name let you share the session among commands
6060
* Call this as the same name of the command if you don't need to share the conversation
6161
*
62-
* @var strint
62+
* @var string
6363
*/
6464
protected $group_name;
6565

6666
/**
67-
* Command to be execute if the conversation is active
67+
* Command to be executed if the conversation is active
6868
*
6969
* @var string
7070
*/
7171
protected $command;
7272

7373
/**
74-
* Conversation contructor initialize a new conversation
74+
* Conversation contructor to initialize a new conversation
7575
*
7676
* @param int $user_id
7777
* @param int $chat_id
78-
* @param string $name
78+
* @param string $group_name
7979
* @param string $command
8080
*/
8181
public function __construct($user_id, $chat_id, $group_name = null, $command = null)
@@ -91,7 +91,7 @@ public function __construct($user_id, $chat_id, $group_name = null, $command = n
9191
}
9292

9393
/**
94-
* Check if the conversation already exist
94+
* Check if the conversation already exists
9595
*
9696
* @return bool
9797
*/
@@ -101,7 +101,7 @@ protected function conversationExist()
101101
if ($this->is_fetched) {
102102
return true;
103103
}
104-
//select an active conversation
104+
//Select an active conversation
105105
$conversation = ConversationDB::selectConversation($this->user_id, $this->chat_id, 1);
106106
$this->is_fetched = true;
107107

@@ -114,13 +114,13 @@ protected function conversationExist()
114114
return true;
115115
}
116116

117-
//a track with the same name was already opened, store the data inside the class
117+
//A conversation with the same name was already opened, store the data inside the class
118118
if ($this->conversation['conversation_name'] == $this->group_name) {
119119
$this->data = json_decode($this->conversation['data'], true);
120120
return true;
121121
}
122122

123-
//a conversation with a differet name has been opened unsetting the DB one and reacreatea a new one
123+
//A conversation with a different name has been opened, unset the DB one and recreate a new one
124124
ConversationDB::updateConversation(['status' => 'cancelled'], ['chat_id' => $this->chat_id, 'user_id' => $this->user_id, 'status' => 'active']);
125125
return false;
126126
}
@@ -130,9 +130,7 @@ protected function conversationExist()
130130
}
131131

132132
/**
133-
* Check if the Conversation already exist
134-
*
135-
* Check if a conversation has already been created in the database. If the conversation is not found, a new conversation is created. start fetch the data stored in the database
133+
* Check if a conversation has already been created in the database. If the conversation is not found, a new conversation is created. Start fetches the data stored in the database.
136134
*
137135
* @return bool
138136
*/
@@ -148,11 +146,13 @@ public function start()
148146
/**
149147
* Store the array/variable in the database with json_encode() function
150148
*
149+
* @todo Verify the query before assigning the $data member variable
150+
*
151151
* @param array $data
152152
*/
153153
public function update($data)
154154
{
155-
//conversation must exist!
155+
//Conversation must exist!
156156
if ($this->conversationExist()) {
157157
$fields['data'] = json_encode($data);
158158

@@ -165,11 +165,9 @@ public function update($data)
165165
/**
166166
* Delete the conversation from the database
167167
*
168-
* Currently the Convevrsation is not deleted but just unsetted
168+
* Currently the Conversation is not deleted but just set to 'stopped'
169169
*
170-
* @TODO should return something
171-
*
172-
* @param array $data
170+
* @todo should return something
173171
*/
174172
public function stop()
175173
{
@@ -181,7 +179,7 @@ public function stop()
181179
/**
182180
* Retrieve the command to execute from the conversation
183181
*
184-
* @param string
182+
* @return string|null
185183
*/
186184
public function getConversationCommand()
187185
{
@@ -192,9 +190,9 @@ public function getConversationCommand()
192190
}
193191

194192
/**
195-
* Retrive the data store in the conversation
193+
* Retrieve the data stored in the conversation
196194
*
197-
* @param array $data
195+
* @return array
198196
*/
199197
public function getData()
200198
{

src/ConversationDB.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,31 @@ public static function initializeConversation()
2626
define('TB_CONVERSATION', self::$table_prefix . 'conversation');
2727
}
2828
}
29-
29+
3030
/**
31-
* Conversation contructor initialize a new conversation
31+
* Select a conversation from the DB
3232
*
3333
* @param int $user_id
3434
* @param int $chat_id
3535
* @param bool $limit
3636
*
37-
* @return array
37+
* @return array|bool
3838
*/
3939
public static function selectConversation($user_id, $chat_id, $limit = null)
4040
{
4141
if (!self::isDbConnected()) {
4242
return false;
4343
}
44-
44+
4545
try {
4646
$query = 'SELECT * FROM `' . TB_CONVERSATION . '` ';
4747
$query .= 'WHERE `status` = :status ';
4848
$query .= 'AND `chat_id` = :chat_id ';
4949
$query .= 'AND `user_id` = :user_id ';
50-
50+
5151
$tokens = [':chat_id' => $chat_id, ':user_id' => $user_id];
5252
if (!is_null($limit)) {
53-
$query .=' LIMIT :limit';
53+
$query .= ' LIMIT :limit';
5454
}
5555
$sth = self::$pdo->prepare($query);
5656

@@ -73,7 +73,7 @@ public static function selectConversation($user_id, $chat_id, $limit = null)
7373
* Insert the conversation in the database
7474
*
7575
* @param string $conversation_command
76-
* @param string $conversation_name
76+
* @param string $conversation_group_name
7777
* @param int $user_id
7878
* @param int $chat_id
7979
*
@@ -127,13 +127,13 @@ public static function updateConversation(array $fields_values, array $where_fie
127127
}
128128

129129
/**
130-
* Insert the conversation in the database
130+
* Update the conversation in the database
131131
*
132-
* @param string $table
133-
* @param array $fields_values
134-
* @param array $where_fields_values
132+
* @param string $table
133+
* @param array $fields_values
134+
* @param array $where_fields_values
135135
*
136-
* @todo this function is generic should be moved in DB.php
136+
* @todo This function is generic should be moved in DB.php
137137
*
138138
* @return bool
139139
*/
@@ -156,26 +156,26 @@ public static function update($table, array $fields_values, array $where_fields_
156156
}
157157
++$a;
158158
++$tokens_counter;
159-
$update .= '`'.$field.'` = :'.$tokens_counter;
160-
$tokens[':'.$tokens_counter] = $value;
159+
$update .= '`' . $field . '` = :' . $tokens_counter;
160+
$tokens[':' . $tokens_counter] = $value;
161161
}
162162

163163
//Where
164164
$a = 0;
165165
$where = '';
166166
foreach ($where_fields_values as $field => $value) {
167167
if ($a) {
168-
$where .= ' AND ';
168+
$where .= ' AND ';
169169
} else {
170170
++$a;
171-
$where .= 'WHERE ';
171+
$where .= 'WHERE ';
172172
}
173173
++$tokens_counter;
174-
$where .= '`'.$field .'`= :'.$tokens_counter ;
175-
$tokens[':'.$tokens_counter] = $value;
174+
$where .= '`' . $field .'`= :' . $tokens_counter ;
175+
$tokens[':' . $tokens_counter] = $value;
176176
}
177177

178-
$query = 'UPDATE `'.$table.'` SET '.$update.' '.$where;
178+
$query = 'UPDATE `' . $table . '` SET ' . $update . ' ' . $where;
179179
try {
180180
$sth = self::$pdo->prepare($query);
181181
$status = $sth->execute($tokens);

0 commit comments

Comments
 (0)