Code fixes in \TgBotLib\Objects\Telegram\InlineQueryResult > InlineQueryResultLocation

This commit is contained in:
Netkas 2023-08-09 18:25:42 -04:00
parent 8e45540d78
commit 96c3e190cb
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
2 changed files with 200 additions and 30 deletions

View file

@ -31,7 +31,7 @@
*/ */
public function toArray(): array public function toArray(): array
{ {
throw new NotImplementedException(sprintf('This object is abstract, you can\'t use it directly, try constructing one of the child classes with fromArray()')); throw new NotImplementedException('This object is abstract, you can\'t use it directly, try constructing one of the child classes with fromArray()');
} }
/** /**
@ -47,34 +47,21 @@
throw new InvalidArgumentException('The type of the InlineQueryResult is not set, this is required!'); throw new InvalidArgumentException('The type of the InlineQueryResult is not set, this is required!');
} }
switch(strtolower($data['type'])) return match (strtolower($data['type']))
{ {
case InlineQueryResultType::ARTICLE: InlineQueryResultType::ARTICLE => InlineQueryResultArticle::fromArray($data),
return InlineQueryResultArticle::fromArray($data); InlineQueryResultType::PHOTO => InlineQueryResultPhoto::fromArray($data),
case InlineQueryResultType::PHOTO: InlineQueryResultType::GIF => InlineQueryResultGif::fromArray($data),
return InlineQueryResultPhoto::fromArray($data); InlineQueryResultType::MPEG_4_GIF => InlineQueryResultMpeg4Gif::fromArray($data),
case InlineQueryResultType::GIF: InlineQueryResultType::VIDEO => InlineQueryResultVideo::fromArray($data),
return InlineQueryResultGif::fromArray($data); InlineQueryResultType::AUDIO => InlineQueryResultAudio::fromArray($data),
case InlineQueryResultType::MPEG_4_GIF: InlineQueryResultType::VOICE => InlineQueryResultVoice::fromArray($data),
return InlineQueryResultMpeg4Gif::fromArray($data); InlineQueryResultType::DOCUMENT => InlineQueryResultDocument::fromArray($data),
case InlineQueryResultType::VIDEO: InlineQueryResultType::LOCATION => InlineQueryResultLocation::fromArray($data),
return InlineQueryResultVideo::fromArray($data); InlineQueryResultType::VENUE => InlineQueryResultVenue::fromArray($data),
case InlineQueryResultType::AUDIO: InlineQueryResultType::CONTACT => InlineQueryResultContact::fromArray($data),
return InlineQueryResultAudio::fromArray($data); InlineQueryResultType::GAME => InlineQueryResultGame::fromArray($data),
case InlineQueryResultType::VOICE: default => throw new InvalidArgumentException(sprintf('The type of the InlineQueryResult is invalid, got "%s", expected one of "%s"', $data['type'], implode('", "', InlineQueryResultType::ALL))),
return InlineQueryResultVoice::fromArray($data); };
case InlineQueryResultType::DOCUMENT:
return InlineQueryResultDocument::fromArray($data);
case InlineQueryResultType::LOCATION:
return InlineQueryResultLocation::fromArray($data);
case InlineQueryResultType::VENUE:
return InlineQueryResultVenue::fromArray($data);
case InlineQueryResultType::CONTACT:
return InlineQueryResultContact::fromArray($data);
case InlineQueryResultType::GAME:
return InlineQueryResultGame::fromArray($data);
default:
throw new InvalidArgumentException(sprintf('The type of the InlineQueryResult is invalid, got "%s", expected one of "%s"', $data['type'], implode('", "', InlineQueryResultType::ALL)));
}
} }
} }

View file

@ -4,6 +4,7 @@
namespace TgBotLib\Objects\Telegram\InlineQueryResult; namespace TgBotLib\Objects\Telegram\InlineQueryResult;
use InvalidArgumentException;
use TgBotLib\Interfaces\ObjectTypeInterface; use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\Telegram\InlineKeyboardMarkup; use TgBotLib\Objects\Telegram\InlineKeyboardMarkup;
use TgBotLib\Objects\Telegram\InputMessageContent\InputContactMessageContent; use TgBotLib\Objects\Telegram\InputMessageContent\InputContactMessageContent;
@ -112,6 +113,23 @@
return $this->id; return $this->id;
} }
/**
* Sets a unique identifier for this result, 1-64 Bytes
*
* @param string $id
* @return $this
*/
public function setId(string $id): InlineQueryResultLocation
{
if(strlen($id) > 64)
{
throw new InvalidArgumentException('id should be less than 64 characters');
}
$this->id = $id;
return $this;
}
/** /**
* Location latitude in degrees * Location latitude in degrees
* *
@ -122,6 +140,18 @@
return $this->latitude; return $this->latitude;
} }
/**
* Sets the location latitude in degrees
*
* @param float $latitude
* @return $this
*/
public function setLatitude(float $latitude): InlineQueryResultLocation
{
$this->latitude = $latitude;
return $this;
}
/** /**
* Location longitude in degrees * Location longitude in degrees
* *
@ -132,6 +162,18 @@
return $this->longitude; return $this->longitude;
} }
/**
* Sets the location longitude in degrees
*
* @param float $longitude
* @return $this
*/
public function setLongitude(float $longitude): InlineQueryResultLocation
{
$this->longitude = $longitude;
return $this;
}
/** /**
* Location title * Location title
* *
@ -142,6 +184,18 @@
return $this->title; return $this->title;
} }
/**
* Sets the location title
*
* @param string $title
* @return $this
*/
public function setTitle(string $title): InlineQueryResultLocation
{
$this->title = $title;
return $this;
}
/** /**
* Optional. The radius of uncertainty for the location, measured in meters; 0-1500 * Optional. The radius of uncertainty for the location, measured in meters; 0-1500
* *
@ -153,7 +207,25 @@
} }
/** /**
* Optional. Period in seconds for which the location can be updated should be between 60 and 86400. * Sets the radius of uncertainty for the location, measured in meters; 0-1500
*
* @param float|null $horizontal_accuracy
* @return $this
*/
public function setHorizontalAccuracy(?float $horizontal_accuracy): InlineQueryResultLocation
{
if($horizontal_accuracy < 0 || $horizontal_accuracy > 1500)
{
throw new InvalidArgumentException('horizontal_accuracy should be between 0 and 1500');
}
$this->horizontal_accuracy = $horizontal_accuracy;
return $this;
}
/**
* Optional. The Period in seconds for which the location can be updated should be between 60 and 86400.
* *
* @return int|null * @return int|null
*/ */
@ -162,6 +234,23 @@
return $this->live_period; return $this->live_period;
} }
/**
* Sets the period in seconds for which the location can be updated should be between 60 and 86400.
*
* @param int|null $live_period
* @return $this
*/
public function setLivePeriod(?int $live_period): InlineQueryResultLocation
{
if($live_period < 60 || $live_period > 86400)
{
throw new InvalidArgumentException('live_period should be between 60 and 86400');
}
$this->live_period = $live_period;
return $this;
}
/** /**
* Optional. For live locations, the direction in which the user is moving, in degrees. It Must be between 1 and 360 if specified. * Optional. For live locations, the direction in which the user is moving, in degrees. It Must be between 1 and 360 if specified.
* *
@ -172,6 +261,23 @@
return $this->heading; return $this->heading;
} }
/**
* Sets the direction in which the user is moving, in degrees. It Must be between 1 and 360 if specified.
*
* @param int|null $heading
* @return $this
*/
public function setHeading(?int $heading): InlineQueryResultLocation
{
if($heading < 1 || $heading > 360)
{
throw new InvalidArgumentException('heading should be between 1 and 360');
}
$this->heading = $heading;
return $this;
}
/** /**
* Optional. For live locations, a maximum distance for proximity alerts about * Optional. For live locations, a maximum distance for proximity alerts about
* approaching another chat member, in meters. It Must be between 1 and 100000 if specified. * approaching another chat member, in meters. It Must be between 1 and 100000 if specified.
@ -183,6 +289,23 @@
return $this->proximity_alert_radius; return $this->proximity_alert_radius;
} }
/**
* Sets the maximum distance for proximity alerts about approaching another chat member, in meters.
*
* @param int|null $proximity_alert_radius
* @return $this
*/
public function setProximityAlertRadius(?int $proximity_alert_radius): InlineQueryResultLocation
{
if($proximity_alert_radius < 1 || $proximity_alert_radius > 100000)
{
throw new InvalidArgumentException('proximity_alert_radius should be between 1 and 100000');
}
$this->proximity_alert_radius = $proximity_alert_radius;
return $this;
}
/** /**
* Optional. Inline keyboard attached to the message * Optional. Inline keyboard attached to the message
* *
@ -193,6 +316,18 @@
return $this->reply_markup; return $this->reply_markup;
} }
/**
* Sets the inline keyboard attached to the message
*
* @param InlineKeyboardMarkup|null $reply_markup
* @return $this
*/
public function setReplyMarkup(?InlineKeyboardMarkup $reply_markup): InlineQueryResultLocation
{
$this->reply_markup = $reply_markup;
return $this;
}
/** /**
* Optional. Content of the message to be sent instead of the location * Optional. Content of the message to be sent instead of the location
* *
@ -203,6 +338,18 @@
return $this->input_message_content; return $this->input_message_content;
} }
/**
* Sets the content of the message to be sent instead of the location
*
* @param InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent|null $input_message_content
* @return $this
*/
public function setInputMessageContent(null|InputVenueMessageContent|InputTextMessageContent|InputContactMessageContent|InputLocationMessageContent|InputInvoiceMessageContent $input_message_content): InlineQueryResultLocation
{
$this->input_message_content = $input_message_content;
return $this;
}
/** /**
* Optional. Url of the thumbnail for the result * Optional. Url of the thumbnail for the result
* *
@ -213,6 +360,18 @@
return $this->thumbnail_url; return $this->thumbnail_url;
} }
/**
* Sets the url of the thumbnail for the result
*
* @param string|null $thumbnail_url
* @return $this
*/
public function setThumbnailUrl(?string $thumbnail_url): InlineQueryResultLocation
{
$this->thumbnail_url = $thumbnail_url;
return $this;
}
/** /**
* Optional. Thumbnail width * Optional. Thumbnail width
* *
@ -223,6 +382,18 @@
return $this->thumbnail_width; return $this->thumbnail_width;
} }
/**
* Sets the thumbnail width
*
* @param int|null $thumbnail_width
* @return $this
*/
public function setThumbnailWidth(?int $thumbnail_width): InlineQueryResultLocation
{
$this->thumbnail_width = $thumbnail_width;
return $this;
}
/** /**
* Optional. Thumbnail height * Optional. Thumbnail height
* *
@ -233,6 +404,18 @@
return $this->thumbnail_height; return $this->thumbnail_height;
} }
/**
* Sets the thumbnail height
*
* @param int|null $thumbnail_height
* @return $this
*/
public function setThumbnailHeight(?int $thumbnail_height): InlineQueryResultLocation
{
$this->thumbnail_height = $thumbnail_height;
return $this;
}
/** /**
* Returns an array representation of the object * Returns an array representation of the object
* *