Skip to content

Commit 186c159

Browse files
committed
Fix syntax and tests
1 parent d4d7b67 commit 186c159

File tree

4 files changed

+55
-36
lines changed

4 files changed

+55
-36
lines changed

src/DB.php

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ public static function insertUser(User $user, $date, Chat $chat = null)
164164
}
165165

166166
$user_id = $user->getId();
167+
$username = $user->getUsername();
168+
$first_name = $user->getFirstName();
169+
$last_name = $user->getLastName();
167170

168171
try {
169172
//Users table
@@ -179,9 +182,9 @@ public static function insertUser(User $user, $date, Chat $chat = null)
179182
');
180183

181184
$sth1->bindParam(':id', $user_id, \PDO::PARAM_INT);
182-
$sth1->bindParam(':username', $user->getUsername(), \PDO::PARAM_STR, 255);
183-
$sth1->bindParam(':first_name', $user->getFirstName(), \PDO::PARAM_STR, 255);
184-
$sth1->bindParam(':last_name', $user->getLastName(), \PDO::PARAM_STR, 255);
185+
$sth1->bindParam(':username', $username, \PDO::PARAM_STR, 255);
186+
$sth1->bindParam(':first_name', $first_name, \PDO::PARAM_STR, 255);
187+
$sth1->bindParam(':last_name', $last_name, \PDO::PARAM_STR, 255);
185188
$sth1->bindParam(':date', $date, \PDO::PARAM_STR);
186189

187190
$status = $sth1->execute();
@@ -192,6 +195,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
192195
}
193196
//insert also the relationship to the chat
194197
if (!is_null($chat)) {
198+
$chat_id = $chat->getId();
195199
try {
196200
//user_chat table
197201
$sth3 = self::$pdo->prepare('INSERT IGNORE INTO `'.TB_USERS_CHATS.'`
@@ -202,7 +206,7 @@ public static function insertUser(User $user, $date, Chat $chat = null)
202206
');
203207

204208
$sth3->bindParam(':user_id', $user_id, \PDO::PARAM_INT);
205-
$sth3->bindParam(':chat_id', $chat->getId(), \PDO::PARAM_INT);
209+
$sth3->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT);
206210

207211
$status = $sth3->execute();
208212

@@ -272,16 +276,14 @@ public static function insertRequest(Update $update)
272276
try {
273277
//chats table
274278
$sth2 = self::$pdo->prepare('INSERT INTO `'.TB_CHATS.'`
275-
(
276-
`id`, `title`, `created_at` ,`updated_at`
277-
)
279+
(`id`, `title`, `created_at` ,`updated_at`)
278280
VALUES (:id, :title, :date, :date)
279-
ON DUPLICATE KEY UPDATE `title`=:title, `updated_at`=:date
280-
');
281+
ON DUPLICATE KEY UPDATE `title`=:title, `updated_at`=:date');
281282

283+
$chat_title = $chat->getTitle();
282284

283285
$sth2->bindParam(':id', $chat_id, \PDO::PARAM_INT);
284-
$sth2->bindParam(':title', $chat->getTitle(), \PDO::PARAM_STR, 255);
286+
$sth2->bindParam(':title', $chat, \PDO::PARAM_STR, 255);
285287
$sth2->bindParam(':date', $date, \PDO::PARAM_STR);
286288

287289
$status = $sth2->execute();
@@ -302,18 +304,35 @@ public static function insertRequest(Update $update)
302304
:new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created
303305
)');
304306

305-
306-
$sth->bindParam(':update_id', $update->getUpdateId(), \PDO::PARAM_INT);
307-
$sth->bindParam(':message_id', $message->getMessageId(), \PDO::PARAM_INT);
308-
$sth->bindParam(':user_id', $from->getId(), \PDO::PARAM_INT);
307+
$update_id = $update->getUpdateId();
308+
$message_id = $message->getMessageId();
309+
$from_id = $from->getId();
310+
$reply_to_message = $message->getReplyToMessage();
311+
$text = $message->getText();
312+
$audio = $message->getAudio();
313+
$document = $message->getDocument();
314+
$sticker = $message->getSticker();
315+
$video = $message->getVideo();
316+
$voice = $message->getVoice();
317+
$caption = $message->getCaption();
318+
$contanc = $message->getContact();
319+
$location = $message->getLocation();
320+
$new_chat_title = $message->getNewChatTitle();
321+
$delete_chat_photo = $message->getDeleteChatPhoto();
322+
$group_chat_created = $message->getGroupChatCreated();
323+
324+
325+
$sth->bindParam(':update_id', $update_id, \PDO::PARAM_INT);
326+
$sth->bindParam(':message_id', $message_id, \PDO::PARAM_INT);
327+
$sth->bindParam(':user_id', $from_id, \PDO::PARAM_INT);
309328
$sth->bindParam(':date', $date, \PDO::PARAM_STR);
310329
$sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_STR);
311330
$sth->bindParam(':forward_from', $forward_from, \PDO::PARAM_STR);
312331
$sth->bindParam(':forward_date', $forward_date, \PDO::PARAM_STR);
313-
$sth->bindParam(':reply_to_message', $message->getReplyToMessage(), \PDO::PARAM_STR);
314-
$sth->bindParam(':text', $message->getText(), \PDO::PARAM_STR);
315-
$sth->bindParam(':audio', $message->getAudio(), \PDO::PARAM_STR);
316-
$sth->bindParam(':document', $message->getDocument(), \PDO::PARAM_STR);
332+
$sth->bindParam(':reply_to_message', $reply_to_message, \PDO::PARAM_STR);
333+
$sth->bindParam(':text', $text, \PDO::PARAM_STR);
334+
$sth->bindParam(':audio', $audio, \PDO::PARAM_STR);
335+
$sth->bindParam(':document', $document, \PDO::PARAM_STR);
317336
//Try with to magic shoud work
318337
$var = [];
319338
if (is_array($photo)) {
@@ -327,15 +346,15 @@ public static function insertRequest(Update $update)
327346
}
328347

329348
$sth->bindParam(':photo', $photo, \PDO::PARAM_STR);
330-
$sth->bindParam(':sticker', $message->getSticker(), \PDO::PARAM_STR);
331-
$sth->bindParam(':video', $message->getVideo(), \PDO::PARAM_STR);
332-
$sth->bindParam(':voice', $message->getVoice(), \PDO::PARAM_STR);
333-
$sth->bindParam(':caption', $message->getCaption(), \PDO::PARAM_STR);
334-
$sth->bindParam(':contact', $message->getContact(), \PDO::PARAM_STR);
335-
$sth->bindParam(':location', $message->getLocation(), \PDO::PARAM_STR);
349+
$sth->bindParam(':sticker', $sticker, \PDO::PARAM_STR);
350+
$sth->bindParam(':video', $video, \PDO::PARAM_STR);
351+
$sth->bindParam(':voice', $voice, \PDO::PARAM_STR);
352+
$sth->bindParam(':caption', $caption, \PDO::PARAM_STR);
353+
$sth->bindParam(':contact', $contanct, \PDO::PARAM_STR);
354+
$sth->bindParam(':location', $location, \PDO::PARAM_STR);
336355
$sth->bindParam(':new_chat_participant', $new_chat_paticipant, \PDO::PARAM_STR);
337356
$sth->bindParam(':left_chat_participant', $left_chat_paticipant, \PDO::PARAM_STR);
338-
$sth->bindParam(':new_chat_title', $message->getNewChatTitle(), \PDO::PARAM_STR);
357+
$sth->bindParam(':new_chat_title', $new_chat_title, \PDO::PARAM_STR);
339358
//Array of Photosize
340359

341360
$var = [];
@@ -350,8 +369,8 @@ public static function insertRequest(Update $update)
350369
}
351370

352371
$sth->bindParam(':new_chat_photo', $new_chat_photo, \PDO::PARAM_STR);
353-
$sth->bindParam(':delete_chat_photo', $message->getDeleteChatPhoto(), \PDO::PARAM_STR);
354-
$sth->bindParam(':group_chat_created', $message->getGroupChatCreated(), \PDO::PARAM_STR);
372+
$sth->bindParam(':delete_chat_photo', $delete_chat_photo, \PDO::PARAM_STR);
373+
$sth->bindParam(':group_chat_created', $group_chat_created, \PDO::PARAM_STR);
355374

356375
$status = $sth->execute();
357376

src/Request.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static function executeCurl($action, array $data)
128128
$curlConfig[CURLOPT_POSTFIELDS] = $data;
129129
}
130130

131-
if ( self::$telegram->getLogVerbosity() >= 3) {
131+
if (self::$telegram->getLogVerbosity() >= 3) {
132132
$curlConfig[CURLOPT_VERBOSE] = true;
133133
$verbose = fopen('php://temp', 'w+');
134134
curl_setopt($ch, CURLOPT_STDERR, $verbose);
@@ -141,19 +141,19 @@ public static function executeCurl($action, array $data)
141141
curl_setopt_array($ch, $curlConfig);
142142
$result = curl_exec($ch);
143143

144-
//Logging curl requests
145-
if ( self::$telegram->getLogVerbosity() >= 3) {
144+
//Logging curl requests
145+
if (self::$telegram->getLogVerbosity() >= 3) {
146146
rewind($verbose);
147147
$verboseLog = stream_get_contents($verbose);
148148
self::log("Verbose curl output:\n". htmlspecialchars($verboseLog). "\n");
149149
}
150150

151-
//Logging getUpdates Updates
152-
//Logging curl updates
153-
if ($action == 'getUpdates' & self::$telegram->getLogVerbosity() >= 1 | self::$telegram->getLogVerbosity() >= 3) {
151+
//Logging getUpdates Update
152+
//Logging curl updates
153+
if ($action == 'getUpdates' & self::$telegram->getLogVerbosity() >=1 | self::$telegram->getLogVerbosity() >=3) {
154154
self::setInputRaw($result);
155155
self::log($result);
156-
}
156+
}
157157

158158
if ($result === false) {
159159
throw new TelegramException(curl_error($ch), curl_errno($ch));

src/Telegram.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function getLogPath()
276276
*/
277277
public function setLogVerbosity($log_verbosity)
278278
{
279-
$this->log_verbosity = $log_verbosity;;
279+
$this->log_verbosity = $log_verbosity;
280280
return $this;
281281
}
282282

tests/Unit/Entities/ServerResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function getUpdatesEmpty()
221221
public function testGetUpdatesEmpty() {
222222
$result = $this->getUpdatesEmpty();
223223
$this->server = new ServerResponse(json_decode($result, true), 'testbot');
224-
$this->assertNull(0, $this->server->getResult());
224+
$this->assertNull($this->server->getResult());
225225
}
226226

227227
/**

0 commit comments

Comments
 (0)