Commit 3204a0c0 authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #368 from noplanman/scrutinizer_fixes

Scrutinizer fixes
parents ad4ab40f 2036770f
...@@ -166,7 +166,9 @@ class Botan ...@@ -166,7 +166,9 @@ class Botan
} }
// In case there is no from field assign id = 0 // In case there is no from field assign id = 0
$uid = (isset($data['from']['id'])) ? $data['from']['id'] : 0; $uid = isset($data['from']['id']) ? $data['from']['id'] : 0;
$result = null;
try { try {
$response = self::$client->post( $response = self::$client->post(
......
...@@ -21,23 +21,23 @@ class Conversation ...@@ -21,23 +21,23 @@ class Conversation
/** /**
* All information fetched from the database * All information fetched from the database
* *
* @var array * @var array|null
*/ */
protected $conversation = null; protected $conversation;
/** /**
* Notes stored inside the conversation * Notes stored inside the conversation
* *
* @var array * @var mixed
*/ */
protected $protected_notes = null; protected $protected_notes;
/** /**
* Notes to be stored * Notes to be stored
* *
* @var array * @var mixed
*/ */
public $notes = null; public $notes;
/** /**
* Telegram user id * Telegram user id
...@@ -66,6 +66,8 @@ class Conversation ...@@ -66,6 +66,8 @@ class Conversation
* @param int $user_id * @param int $user_id
* @param int $chat_id * @param int $chat_id
* @param string $command * @param string $command
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct($user_id, $chat_id, $command = null) public function __construct($user_id, $chat_id, $command = null)
{ {
...@@ -98,10 +100,10 @@ class Conversation ...@@ -98,10 +100,10 @@ class Conversation
* Load the conversation from the database * Load the conversation from the database
* *
* @return bool * @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
protected function load() protected function load()
{ {
//Select an active conversation //Select an active conversation
$conversation = ConversationDB::selectConversation($this->user_id, $this->chat_id, 1); $conversation = ConversationDB::selectConversation($this->user_id, $this->chat_id, 1);
if (isset($conversation[0])) { if (isset($conversation[0])) {
...@@ -138,11 +140,13 @@ class Conversation ...@@ -138,11 +140,13 @@ class Conversation
* Start a new conversation if the current command doesn't have one yet * Start a new conversation if the current command doesn't have one yet
* *
* @return bool * @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
protected function start() protected function start()
{ {
if (!$this->exists() && $this->command) { if ($this->command
if (ConversationDB::insertConversation( && !$this->exists()
&& ConversationDB::insertConversation(
$this->user_id, $this->user_id,
$this->chat_id, $this->chat_id,
$this->command $this->command
...@@ -150,7 +154,6 @@ class Conversation ...@@ -150,7 +154,6 @@ class Conversation
) { ) {
return $this->load(); return $this->load();
} }
}
return false; return false;
} }
......
...@@ -116,7 +116,7 @@ class DB ...@@ -116,7 +116,7 @@ class DB
self::$pdo = $external_pdo_connection; self::$pdo = $external_pdo_connection;
self::$telegram = $telegram; self::$telegram = $telegram;
self::$mysql_credentials = null; self::$mysql_credentials = [];
self::$table_prefix = $table_prefix; self::$table_prefix = $table_prefix;
self::defineTables(); self::defineTables();
......
...@@ -22,6 +22,7 @@ use ReflectionObject; ...@@ -22,6 +22,7 @@ use ReflectionObject;
* @link https://core.telegram.org/bots/api#available-types * @link https://core.telegram.org/bots/api#available-types
* *
* @method array getRawData() Get the raw data passed to this entity * @method array getRawData() Get the raw data passed to this entity
* @method string getBotName() Return the bot name passed to this entity
*/ */
abstract class Entity abstract class Entity
{ {
......
...@@ -182,7 +182,7 @@ class Message extends Entity ...@@ -182,7 +182,7 @@ class Message extends Entity
$split_cmd = explode('@', $cmd); $split_cmd = explode('@', $cmd);
if (isset($split_cmd[1])) { if (isset($split_cmd[1])) {
//command is followed by name check if is addressed to me //command is followed by name check if is addressed to me
if (strtolower($split_cmd[1]) === strtolower($this->bot_name)) { if (strtolower($split_cmd[1]) === strtolower($this->getBotName())) {
return $split_cmd[0]; return $split_cmd[0];
} }
} else { } else {
......
...@@ -209,10 +209,9 @@ class Request ...@@ -209,10 +209,9 @@ class Request
$data['reply_markup'] = json_encode($data['reply_markup']); $data['reply_markup'] = json_encode($data['reply_markup']);
} }
$result = null;
$request_params = self::setUpRequestParams($data); $request_params = self::setUpRequestParams($data);
$request_params['debug'] = TelegramLog::getDebugLogTempStream();
$debug_handle = TelegramLog::getDebugLogTempStream();
$request_params['debug'] = $debug_handle;
try { try {
$response = self::$client->post( $response = self::$client->post(
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
namespace Longman\TelegramBot; namespace Longman\TelegramBot;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;
use Longman\TelegramBot\Exception\TelegramLogException; use Longman\TelegramBot\Exception\TelegramLogException;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
class TelegramLog class TelegramLog
{ {
...@@ -55,7 +55,7 @@ class TelegramLog ...@@ -55,7 +55,7 @@ class TelegramLog
/** /**
* Temporary stream handle for debug log * Temporary stream handle for debug log
* *
* @var null * @var resource|null
*/ */
static protected $debug_log_temp_stream_handle; static protected $debug_log_temp_stream_handle;
...@@ -77,10 +77,10 @@ class TelegramLog ...@@ -77,10 +77,10 @@ class TelegramLog
foreach (self::$monolog->getHandlers() as $handler) { foreach (self::$monolog->getHandlers() as $handler) {
if ($handler->getLevel() === 400) { if ($handler->getLevel() === 400) {
self::$error_log_path = true; self::$error_log_path = 'true';
} }
if ($handler->getLevel() === 100) { if ($handler->getLevel() === 100) {
self::$debug_log_path = true; self::$debug_log_path = 'true';
} }
} }
} else { } else {
...@@ -147,11 +147,10 @@ class TelegramLog ...@@ -147,11 +147,10 @@ class TelegramLog
public static function getDebugLogTempStream() public static function getDebugLogTempStream()
{ {
if (self::$debug_log_temp_stream_handle === null) { if (self::$debug_log_temp_stream_handle === null) {
if (self::isDebugLogActive()) { if (!self::isDebugLogActive()) {
self::$debug_log_temp_stream_handle = fopen('php://temp', 'w+');
} else {
return false; return false;
} }
self::$debug_log_temp_stream_handle = fopen('php://temp', 'w+b');
} }
return self::$debug_log_temp_stream_handle; return self::$debug_log_temp_stream_handle;
...@@ -164,7 +163,7 @@ class TelegramLog ...@@ -164,7 +163,7 @@ class TelegramLog
*/ */
public static function endDebugLogTempStream($message = '%s') public static function endDebugLogTempStream($message = '%s')
{ {
if (self::$debug_log_temp_stream_handle !== null) { if (is_resource(self::$debug_log_temp_stream_handle)) {
rewind(self::$debug_log_temp_stream_handle); rewind(self::$debug_log_temp_stream_handle);
self::debug( self::debug(
sprintf( sprintf(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment