diff --git a/src/Api.php b/src/Api.php index 470ec4f..3956199 100644 --- a/src/Api.php +++ b/src/Api.php @@ -251,10 +251,10 @@ class Api try { $this->processUpdatesBatch($handlers, $timeout, $marker); } catch (NetworkException $e) { - error_log("Network error: " . $e->getMessage()); + error_log('Network error: ' . $e->getMessage()); sleep(5); } catch (\Exception $e) { - error_log("An error occurred: " . $e->getMessage()); + error_log('An error occurred: ' . $e->getMessage()); sleep(1); } } diff --git a/src/ModelFactory.php b/src/ModelFactory.php index 5af3988..1da8031 100644 --- a/src/ModelFactory.php +++ b/src/ModelFactory.php @@ -15,6 +15,7 @@ use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\AbstractInlin use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\CallbackButton; use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\ChatButton; use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\LinkButton; +use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\OpenAppButton; use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestContactButton; use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Inline\RequestGeoLocationButton; use BushlanovDev\MaxMessengerBot\Models\Attachments\Buttons\Reply\AbstractReplyButton; @@ -224,7 +225,7 @@ class ModelFactory AttachmentType::InlineKeyboard => InlineKeyboardAttachment::fromArray($data), AttachmentType::ReplyKeyboard => ReplyKeyboardAttachment::fromArray($data), AttachmentType::Location => LocationAttachment::fromArray($data), - default => throw new LogicException("Unknown or unsupported attachment type: " . ($data['type'] ?? 'none')), + default => throw new LogicException('Unknown or unsupported attachment type: ' . ($data['type'] ?? 'none')), }; } @@ -265,7 +266,8 @@ class ModelFactory InlineButtonType::RequestContact => RequestContactButton::fromArray($data), InlineButtonType::RequestGeoLocation => RequestGeoLocationButton::fromArray($data), InlineButtonType::Chat => ChatButton::fromArray($data), - default => throw new LogicException("Unknown or unsupported inline button type: " . ($data['type'] ?? 'none')), + InlineButtonType::OpenApp => OpenAppButton::fromArray($data), + default => throw new LogicException('Unknown or unsupported inline button type: ' . ($data['type'] ?? 'none')), }; } diff --git a/src/Models/Image.php b/src/Models/Image.php index f833553..5e5705e 100644 --- a/src/Models/Image.php +++ b/src/Models/Image.php @@ -9,8 +9,7 @@ final readonly class Image extends AbstractModel /** * @param string $url URL of image. */ - public function __construct( - public string $url, - ) { + public function __construct(public string $url) + { } } diff --git a/tests/Models/Attachments/Buttons/Inline/OpenAppButtonTest.php b/tests/Models/Attachments/Buttons/Inline/OpenAppButtonTest.php index 10b3084..0801cdc 100644 --- a/tests/Models/Attachments/Buttons/Inline/OpenAppButtonTest.php +++ b/tests/Models/Attachments/Buttons/Inline/OpenAppButtonTest.php @@ -29,4 +29,23 @@ final class OpenAppButtonTest extends TestCase $this->assertSame($expectedArray, $resultArray); } + + #[Test] + public function fromArrayHydratesCorrectly(): void + { + $data = [ + 'type' => 'open_app', + 'text' => 'Launch', + 'web_app' => 'SomeApp', + 'contact_id' => 456, + ]; + + $button = OpenAppButton::fromArray($data); + + $this->assertInstanceOf(OpenAppButton::class, $button); + $this->assertSame(InlineButtonType::OpenApp, $button->type); + $this->assertSame('Launch', $button->text); + $this->assertSame('SomeApp', $button->webApp); + $this->assertSame(456, $button->contactId); + } }