Fix "Major" issues, mainly docblock type hints.

Refactor TelegramLog a tiny bit.
parent 2ad44458
......@@ -7,10 +7,12 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Added
- Finish implementing payments, adding all missing type checks and docblock methods.
### Changed
- [:exclamation:][unreleased-bc-messagegetcommand-return-value] `Message::getCommand()` returns `null` if not a command, instead of `false`.
### Deprecated
### Removed
### Fixed
- SQL update script for version 0.44.1-0.45.0.
- Issues found by Scrutinizer (Type hints and return values).
### Security
## [0.49.0] - 2017-09-17
......@@ -169,6 +171,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Deprecated
- Move `hideKeyboard` to `removeKeyboard`.
[unreleased-bc-messagegetcommand-return-value]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#messagegetcommand-return-value
[0.48.0-sql-migration]: https://github.com/php-telegram-bot/core/tree/develop/utils/db-schema-update/0.47.1-0.48.0.sql
[0.48.0-bc-correct-printerror]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#correct-printerror
[0.47.0-bc-private-only-admin-commands]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#private-only-admin-commands
......
......@@ -452,7 +452,7 @@ class DB
$chat_id = $chat->getId();
$chat_type = $chat->getType();
if ($migrate_to_chat_id) {
if ($migrate_to_chat_id !== null) {
$chat_type = 'supergroup';
$sth->bindValue(':id', $migrate_to_chat_id);
......@@ -872,7 +872,7 @@ class DB
$sth->bindValue(':forward_date', $forward_date);
$reply_to_chat_id = null;
if ($reply_to_message_id) {
if ($reply_to_message_id !== null) {
$reply_to_chat_id = $chat_id;
}
$sth->bindValue(':reply_to_chat', $reply_to_chat_id);
......
......@@ -190,7 +190,7 @@ class Message extends Entity
$full_command = $this->getFullCommand();
if (strpos($full_command, '/') !== 0) {
return false;
return null;
}
$full_command = substr($full_command, 1);
......@@ -281,9 +281,10 @@ class Message extends Entity
'successful_payment',
];
$is_command = strlen($this->getCommand()) > 0;
foreach ($types as $type) {
if ($this->getProperty($type)) {
if ($type === 'text' && $this->getCommand()) {
if ($is_command && $type === 'text') {
return 'command';
}
......
......@@ -60,10 +60,7 @@ class TelegramLog
static protected $debug_log_temp_stream_handle;
/**
* Initialize
*
* Initilize monolog instance. Singleton
* Is possbile provide an external monolog instance
* Initialize Monolog Logger instance, optionally passing an existing one
*
* @param \Monolog\Logger
*
......@@ -76,10 +73,10 @@ class TelegramLog
self::$monolog = $external_monolog;
foreach (self::$monolog->getHandlers() as $handler) {
if ($handler->getLevel() === 400) {
if (method_exists($handler, 'getLevel') && $handler->getLevel() === 400) {
self::$error_log_path = 'true';
}
if ($handler->getLevel() === 100) {
if (method_exists($handler, 'getLevel') && $handler->getLevel() === 100) {
self::$debug_log_path = 'true';
}
}
......@@ -174,9 +171,6 @@ class TelegramLog
/**
* Initialize update log
*
* Initilize monolog instance. Singleton
* Is possbile provide an external monolog instance
*
* @param string $path
*
* @return \Monolog\Logger
......@@ -190,20 +184,17 @@ class TelegramLog
throw new TelegramLogException('Empty path for update log');
}
self::$update_log_path = $path;
if (self::$monolog_update === null) {
self::$monolog_update = new Logger('bot_update_log');
// Create a formatter
$output = '%message%' . PHP_EOL;
$formatter = new LineFormatter($output);
// Update handler
$update_handler = new StreamHandler(self::$update_log_path, Logger::INFO);
$update_handler->setFormatter($formatter);
self::$monolog_update->pushHandler($update_handler);
self::$monolog_update->pushHandler(
(new StreamHandler(self::$update_log_path, Logger::INFO))
->setFormatter(new LineFormatter('%message%' . PHP_EOL))
);
}
return self::$monolog;
return self::$monolog_update;
}
/**
......
......@@ -30,8 +30,8 @@ class MessageTest extends TestCase
// text
$message = TestHelpers::getFakeMessageObject(['text' => 'some text']);
self::assertEquals('', $message->getFullCommand());
self::assertEquals('', $message->getCommand());
self::assertNull($message->getFullCommand());
self::assertNull($message->getCommand());
self::assertEquals('some text', $message->getText());
self::assertEquals('some text', $message->getText(true));
......
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