diff --git a/src/Abstracts/CustomType.php b/src/Abstracts/CustomType.php index 238713f..42efa00 100644 --- a/src/Abstracts/CustomType.php +++ b/src/Abstracts/CustomType.php @@ -12,5 +12,5 @@ */ abstract class CustomType extends TelegramTypes { - public $data = null; + public $data = []; } diff --git a/src/Abstracts/TelegramMethods.php b/src/Abstracts/TelegramMethods.php index babd5e1..2d8cacd 100644 --- a/src/Abstracts/TelegramMethods.php +++ b/src/Abstracts/TelegramMethods.php @@ -68,6 +68,7 @@ public function performSpecialConditions(): TelegramMethods * Exports the class to an array in order to send it to the Telegram servers without extra fields that we don't need * * @return array + * @throws MissingMandatoryField */ final public function export(): array { @@ -77,7 +78,7 @@ final public function export(): array $cleanObject = new $this(); foreach ($cleanObject as $fieldId => $value) { if ($this->$fieldId === $cleanObject->$fieldId) { - if (in_array($fieldId, $mandatoryFields)) { + if (in_array($fieldId, $mandatoryFields, true)) { throw new MissingMandatoryField(sprintf( 'The field "%s" is mandatory and empty, please correct', $fieldId diff --git a/src/Interfaces/CustomArrayType.php b/src/Interfaces/CustomArrayType.php index 7f7ea43..2558bc5 100644 --- a/src/Interfaces/CustomArrayType.php +++ b/src/Interfaces/CustomArrayType.php @@ -1,5 +1,7 @@ $chatMember) { $this->data[$id] = new ChatMember($chatMember, $logger); } diff --git a/src/Telegram/Types/Custom/GameHighScoreArray.php b/src/Telegram/Types/Custom/GameHighScoreArray.php index 3b250c5..5716b1f 100644 --- a/src/Telegram/Types/Custom/GameHighScoreArray.php +++ b/src/Telegram/Types/Custom/GameHighScoreArray.php @@ -15,11 +15,9 @@ */ class GameHighScoreArray extends CustomType implements CustomArrayType { - public $data = []; - public function __construct(array $data = null, LoggerInterface $logger = null) { - if (!empty($data)) { + if (count($data) !== 0) { foreach ($data as $id => $gameHighScore) { $this->data[$id] = new GameHighScore($gameHighScore, $logger); } diff --git a/src/Telegram/Types/Custom/InlineKeyboardButtonArray.php b/src/Telegram/Types/Custom/InlineKeyboardButtonArray.php index 7faa8b0..479f916 100644 --- a/src/Telegram/Types/Custom/InlineKeyboardButtonArray.php +++ b/src/Telegram/Types/Custom/InlineKeyboardButtonArray.php @@ -14,11 +14,9 @@ */ class InlineKeyboardButtonArray extends CustomType implements CustomArrayType { - public $data = []; - public function __construct(array $data = null, LoggerInterface $logger = null) { - if (!empty($data)) { + if (count($data) !== 0) { foreach ($data as $rowId => $button) { $this->data[$rowId][] = new Button($data, $logger); } diff --git a/src/Telegram/Types/Custom/InputFile.php b/src/Telegram/Types/Custom/InputFile.php index 97cf617..aacbd83 100644 --- a/src/Telegram/Types/Custom/InputFile.php +++ b/src/Telegram/Types/Custom/InputFile.php @@ -24,7 +24,7 @@ class InputFile * The actual stream to the file * @var resource */ - private $stream = null; + private $stream; public function __construct(string $path) { @@ -36,6 +36,7 @@ public function __construct(string $path) * Will setup the stream * * @return InputFile + * @throws FileNotReadable */ private function setStream(): InputFile { diff --git a/src/Telegram/Types/Custom/KeyboardButtonArray.php b/src/Telegram/Types/Custom/KeyboardButtonArray.php index ae79a30..2462711 100644 --- a/src/Telegram/Types/Custom/KeyboardButtonArray.php +++ b/src/Telegram/Types/Custom/KeyboardButtonArray.php @@ -14,11 +14,9 @@ */ class KeyboardButtonArray extends CustomType implements CustomArrayType { - public $data = []; - public function __construct(array $data = null, LoggerInterface $logger = null) { - if (!empty($data)) { + if (count($data) !== 0) { foreach ($data as $rowId => $button) { $this->data[$rowId][] = new KeyboardButton($data, $logger); } diff --git a/src/Telegram/Types/Custom/MessageEntityArray.php b/src/Telegram/Types/Custom/MessageEntityArray.php index eee329f..1d3d6c2 100644 --- a/src/Telegram/Types/Custom/MessageEntityArray.php +++ b/src/Telegram/Types/Custom/MessageEntityArray.php @@ -14,11 +14,9 @@ */ class MessageEntityArray extends CustomType implements CustomArrayType { - public $data = []; - public function __construct(array $data = null, LoggerInterface $logger = null) { - if (!empty($data)) { + if (count($data) !== 0) { foreach ($data as $id => $messageEntity) { $this->data[$id] = new MessageEntity($messageEntity, $logger); } diff --git a/src/Telegram/Types/Custom/PhotoSizeArray.php b/src/Telegram/Types/Custom/PhotoSizeArray.php index 9e5ab0d..47e8f7e 100644 --- a/src/Telegram/Types/Custom/PhotoSizeArray.php +++ b/src/Telegram/Types/Custom/PhotoSizeArray.php @@ -14,11 +14,9 @@ */ class PhotoSizeArray extends CustomType implements CustomArrayType { - public $data = []; - public function __construct(array $data = null, LoggerInterface $logger = null) { - if (!empty($data)) { + if (count($data) !== 0) { foreach ($data as $id => $photo) { $this->data[$id] = new PhotoSize($photo, $logger); } diff --git a/src/Telegram/Types/Custom/UpdatesArray.php b/src/Telegram/Types/Custom/UpdatesArray.php index 7260217..f243321 100644 --- a/src/Telegram/Types/Custom/UpdatesArray.php +++ b/src/Telegram/Types/Custom/UpdatesArray.php @@ -14,11 +14,9 @@ */ class UpdatesArray extends CustomType implements CustomArrayType { - public $data = []; - public function __construct(array $data = null, LoggerInterface $logger = null) { - if (!empty($data)) { + if (count($data) !== 0) { foreach ($data as $telegramResponse) { // Create an actual Update object and fill the array $this->data[] = new Update($telegramResponse, $logger); diff --git a/src/Telegram/Types/Custom/UserProfilePhotosArray.php b/src/Telegram/Types/Custom/UserProfilePhotosArray.php index 3a2a6b3..ce90996 100644 --- a/src/Telegram/Types/Custom/UserProfilePhotosArray.php +++ b/src/Telegram/Types/Custom/UserProfilePhotosArray.php @@ -14,12 +14,11 @@ */ class UserProfilePhotosArray extends CustomType implements CustomArrayType { - public $data = []; - public function __construct(array $data = null, LoggerInterface $logger = null) { - if (!empty($data)) { + if (count($data) !== 0) { $i = 0; + /** @var array $telegramResponse */ foreach ($data as $telegramResponse) { foreach ($telegramResponse as $photoSize) { // Create an actual PhotoSize object and fill the array diff --git a/src/Telegram/Types/Game.php b/src/Telegram/Types/Game.php index a802be5..ed0cfd0 100644 --- a/src/Telegram/Types/Game.php +++ b/src/Telegram/Types/Game.php @@ -54,7 +54,7 @@ class Game extends TelegramTypes * Optional. Animation that will be displayed in the game message in chats. Upload via BotFather * @var Animation */ - public $animation = null; + public $animation; public function mapSubObjects(string $key, array $data): TelegramTypes { diff --git a/src/Telegram/Types/GameHighScore.php b/src/Telegram/Types/GameHighScore.php index 4fdd818..dfdc0b3 100644 --- a/src/Telegram/Types/GameHighScore.php +++ b/src/Telegram/Types/GameHighScore.php @@ -5,8 +5,6 @@ namespace unreal4u\TelegramAPI\Telegram\Types; use unreal4u\TelegramAPI\Abstracts\TelegramTypes; -use unreal4u\TelegramAPI\Telegram\Types\Custom\MessageEntityArray; -use unreal4u\TelegramAPI\Telegram\Types\Custom\PhotoSizeArray; /** * This object represents one row of the high scores table for a game @@ -25,7 +23,7 @@ class GameHighScore extends TelegramTypes /** * User - * @var string + * @var User */ public $user; diff --git a/src/Telegram/Types/Inline/Query/Result.php b/src/Telegram/Types/Inline/Query/Result.php index 02ed350..43f91b3 100644 --- a/src/Telegram/Types/Inline/Query/Result.php +++ b/src/Telegram/Types/Inline/Query/Result.php @@ -55,7 +55,7 @@ abstract class Result extends TelegramTypes * Optional. Inline keyboard attached to the message * @var Markup */ - public $reply_markup = null; + public $reply_markup; protected function mapSubObjects(string $key, array $data): TelegramTypes { @@ -85,6 +85,7 @@ public function getMandatoryFields(): array * * @see TelegramMethods::export * @return array + * @throws \unreal4u\TelegramAPI\Exceptions\MissingMandatoryField */ public function export(): array { @@ -94,7 +95,7 @@ public function export(): array $cleanObject = new $this(); foreach ($cleanObject as $fieldId => $value) { if ($fieldId !== 'type' && $this->$fieldId === $cleanObject->$fieldId) { - if (in_array($fieldId, $mandatoryFields)) { + if (in_array($fieldId, $mandatoryFields, true)) { throw new MissingMandatoryField(sprintf( 'The field "%s" is mandatory and empty, please correct', $fieldId diff --git a/src/Telegram/Types/Inline/Query/Result/Article.php b/src/Telegram/Types/Inline/Query/Result/Article.php index 24aa257..3d48032 100644 --- a/src/Telegram/Types/Inline/Query/Result/Article.php +++ b/src/Telegram/Types/Inline/Query/Result/Article.php @@ -68,5 +68,5 @@ class Article extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Audio.php b/src/Telegram/Types/Inline/Query/Result/Audio.php index 0245831..4d9ed94 100644 --- a/src/Telegram/Types/Inline/Query/Result/Audio.php +++ b/src/Telegram/Types/Inline/Query/Result/Audio.php @@ -57,5 +57,5 @@ class Audio extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Cached/Audio.php b/src/Telegram/Types/Inline/Query/Result/Cached/Audio.php index 75e7031..097c7a4 100644 --- a/src/Telegram/Types/Inline/Query/Result/Cached/Audio.php +++ b/src/Telegram/Types/Inline/Query/Result/Cached/Audio.php @@ -40,5 +40,5 @@ class Audio extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Cached/Document.php b/src/Telegram/Types/Inline/Query/Result/Cached/Document.php index 61baf7d..239463a 100644 --- a/src/Telegram/Types/Inline/Query/Result/Cached/Document.php +++ b/src/Telegram/Types/Inline/Query/Result/Cached/Document.php @@ -52,5 +52,5 @@ class Document extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Cached/Gif.php b/src/Telegram/Types/Inline/Query/Result/Cached/Gif.php index faadb92..14a0f31 100644 --- a/src/Telegram/Types/Inline/Query/Result/Cached/Gif.php +++ b/src/Telegram/Types/Inline/Query/Result/Cached/Gif.php @@ -46,5 +46,5 @@ class Gif extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Cached/Mpeg4Gif.php b/src/Telegram/Types/Inline/Query/Result/Cached/Mpeg4Gif.php index 72389bf..1ea43dc 100644 --- a/src/Telegram/Types/Inline/Query/Result/Cached/Mpeg4Gif.php +++ b/src/Telegram/Types/Inline/Query/Result/Cached/Mpeg4Gif.php @@ -46,5 +46,5 @@ class Mpeg4Gif extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Cached/Photo.php b/src/Telegram/Types/Inline/Query/Result/Cached/Photo.php index a626c54..3351d95 100644 --- a/src/Telegram/Types/Inline/Query/Result/Cached/Photo.php +++ b/src/Telegram/Types/Inline/Query/Result/Cached/Photo.php @@ -52,5 +52,5 @@ class Photo extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Cached/Sticker.php b/src/Telegram/Types/Inline/Query/Result/Cached/Sticker.php index a1c8037..1ee7fae 100644 --- a/src/Telegram/Types/Inline/Query/Result/Cached/Sticker.php +++ b/src/Telegram/Types/Inline/Query/Result/Cached/Sticker.php @@ -33,5 +33,5 @@ class Sticker extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Cached/Video.php b/src/Telegram/Types/Inline/Query/Result/Cached/Video.php index a90a627..a45c3df 100644 --- a/src/Telegram/Types/Inline/Query/Result/Cached/Video.php +++ b/src/Telegram/Types/Inline/Query/Result/Cached/Video.php @@ -52,5 +52,5 @@ class Video extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Cached/Voice.php b/src/Telegram/Types/Inline/Query/Result/Cached/Voice.php index 047d87e..8f6f708 100644 --- a/src/Telegram/Types/Inline/Query/Result/Cached/Voice.php +++ b/src/Telegram/Types/Inline/Query/Result/Cached/Voice.php @@ -46,5 +46,5 @@ class Voice extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Contact.php b/src/Telegram/Types/Inline/Query/Result/Contact.php index 2e640cc..aeab5b2 100644 --- a/src/Telegram/Types/Inline/Query/Result/Contact.php +++ b/src/Telegram/Types/Inline/Query/Result/Contact.php @@ -63,5 +63,5 @@ class Contact extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Document.php b/src/Telegram/Types/Inline/Query/Result/Document.php index 32656cd..3455f70 100644 --- a/src/Telegram/Types/Inline/Query/Result/Document.php +++ b/src/Telegram/Types/Inline/Query/Result/Document.php @@ -76,5 +76,5 @@ class Document extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Gif.php b/src/Telegram/Types/Inline/Query/Result/Gif.php index 2a166ac..8221fec 100644 --- a/src/Telegram/Types/Inline/Query/Result/Gif.php +++ b/src/Telegram/Types/Inline/Query/Result/Gif.php @@ -64,5 +64,5 @@ class Gif extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Location.php b/src/Telegram/Types/Inline/Query/Result/Location.php index 81ddcb8..a1c7e52 100644 --- a/src/Telegram/Types/Inline/Query/Result/Location.php +++ b/src/Telegram/Types/Inline/Query/Result/Location.php @@ -63,5 +63,5 @@ class Location extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Mpeg4Gif.php b/src/Telegram/Types/Inline/Query/Result/Mpeg4Gif.php index 50ccc73..3425267 100644 --- a/src/Telegram/Types/Inline/Query/Result/Mpeg4Gif.php +++ b/src/Telegram/Types/Inline/Query/Result/Mpeg4Gif.php @@ -64,5 +64,5 @@ class Mpeg4Gif extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Photo.php b/src/Telegram/Types/Inline/Query/Result/Photo.php index d2293d2..16f95f8 100644 --- a/src/Telegram/Types/Inline/Query/Result/Photo.php +++ b/src/Telegram/Types/Inline/Query/Result/Photo.php @@ -69,5 +69,5 @@ class Photo extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Venue.php b/src/Telegram/Types/Inline/Query/Result/Venue.php index c6157be..1517e9a 100644 --- a/src/Telegram/Types/Inline/Query/Result/Venue.php +++ b/src/Telegram/Types/Inline/Query/Result/Venue.php @@ -75,5 +75,5 @@ class Venue extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Video.php b/src/Telegram/Types/Inline/Query/Result/Video.php index cbab75a..14e1581 100644 --- a/src/Telegram/Types/Inline/Query/Result/Video.php +++ b/src/Telegram/Types/Inline/Query/Result/Video.php @@ -82,5 +82,5 @@ class Video extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/Inline/Query/Result/Voice.php b/src/Telegram/Types/Inline/Query/Result/Voice.php index b976bb0..d6df445 100644 --- a/src/Telegram/Types/Inline/Query/Result/Voice.php +++ b/src/Telegram/Types/Inline/Query/Result/Voice.php @@ -52,5 +52,5 @@ class Voice extends Result * Optional. Content of the message to be sent instead of the audio/document/voice message/video/sticker/etc. * @var InputMessageContent */ - public $input_message_content = null; + public $input_message_content; } diff --git a/src/Telegram/Types/ResponseParameters.php b/src/Telegram/Types/ResponseParameters.php new file mode 100644 index 0000000..035b60f --- /dev/null +++ b/src/Telegram/Types/ResponseParameters.php @@ -0,0 +1,35 @@ +logger->debug('About to perform HTTP call to Telegram\'s API'); + /** @noinspection PhpMethodParametersCountMismatchInspection */ $response = $this->httpClient->post($this->composeApiMethodUrl($method), $formData); $this->logger->debug('Got response back from Telegram, applying json_decode'); return new TelegramRawData((string)$response->getBody()); @@ -162,6 +163,7 @@ private function resetObjectValues(): TgLog * * @param TelegramMethods $method * @return array + * @throws \unreal4u\TelegramAPI\Exceptions\MissingMandatoryField */ private function constructFormData(TelegramMethods $method): array {