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