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
}
// 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 {
$response = self::$client->post(
......
......@@ -21,23 +21,23 @@ class Conversation
/**
* All information fetched from the database
*
* @var array
* @var array|null
*/
protected $conversation = null;
protected $conversation;
/**
* Notes stored inside the conversation
*
* @var array
* @var mixed
*/
protected $protected_notes = null;
protected $protected_notes;
/**
* Notes to be stored
*
* @var array
* @var mixed
*/
public $notes = null;
public $notes;
/**
* Telegram user id
......@@ -66,6 +66,8 @@ class Conversation
* @param int $user_id
* @param int $chat_id
* @param string $command
*
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function __construct($user_id, $chat_id, $command = null)
{
......@@ -98,10 +100,10 @@ class Conversation
* Load the conversation from the database
*
* @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
protected function load()
{
//Select an active conversation
$conversation = ConversationDB::selectConversation($this->user_id, $this->chat_id, 1);
if (isset($conversation[0])) {
......@@ -138,11 +140,13 @@ class Conversation
* Start a new conversation if the current command doesn't have one yet
*
* @return bool
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
protected function start()
{
if (!$this->exists() && $this->command) {
if (ConversationDB::insertConversation(
if ($this->command
&& !$this->exists()
&& ConversationDB::insertConversation(
$this->user_id,
$this->chat_id,
$this->command
......@@ -150,7 +154,6 @@ class Conversation
) {
return $this->load();
}
}
return false;
}
......
......@@ -116,7 +116,7 @@ class DB
self::$pdo = $external_pdo_connection;
self::$telegram = $telegram;
self::$mysql_credentials = null;
self::$mysql_credentials = [];
self::$table_prefix = $table_prefix;
self::defineTables();
......
......@@ -22,6 +22,7 @@ use ReflectionObject;
* @link https://core.telegram.org/bots/api#available-types
*
* @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
{
......
......@@ -182,7 +182,7 @@ class Message extends Entity
$split_cmd = explode('@', $cmd);
if (isset($split_cmd[1])) {
//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];
}
} else {
......
......@@ -209,10 +209,9 @@ class Request
$data['reply_markup'] = json_encode($data['reply_markup']);
}
$result = null;
$request_params = self::setUpRequestParams($data);
$debug_handle = TelegramLog::getDebugLogTempStream();
$request_params['debug'] = $debug_handle;
$request_params['debug'] = TelegramLog::getDebugLogTempStream();
try {
$response = self::$client->post(
......
......@@ -10,10 +10,10 @@
namespace Longman\TelegramBot;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter\LineFormatter;
use Longman\TelegramBot\Exception\TelegramLogException;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
class TelegramLog
{
......@@ -55,7 +55,7 @@ class TelegramLog
/**
* Temporary stream handle for debug log
*
* @var null
* @var resource|null
*/
static protected $debug_log_temp_stream_handle;
......@@ -77,10 +77,10 @@ class TelegramLog
foreach (self::$monolog->getHandlers() as $handler) {
if ($handler->getLevel() === 400) {
self::$error_log_path = true;
self::$error_log_path = 'true';
}
if ($handler->getLevel() === 100) {
self::$debug_log_path = true;
self::$debug_log_path = 'true';
}
}
} else {
......@@ -147,11 +147,10 @@ class TelegramLog
public static function getDebugLogTempStream()
{
if (self::$debug_log_temp_stream_handle === null) {
if (self::isDebugLogActive()) {
self::$debug_log_temp_stream_handle = fopen('php://temp', 'w+');
} else {
if (!self::isDebugLogActive()) {
return false;
}
self::$debug_log_temp_stream_handle = fopen('php://temp', 'w+b');
}
return self::$debug_log_temp_stream_handle;
......@@ -164,7 +163,7 @@ class TelegramLog
*/
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);
self::debug(
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