Updated PaidMedia objects

This commit is contained in:
netkas 2024-10-04 00:48:28 -04:00
parent 2405873510
commit 46d6cdf124
4 changed files with 24 additions and 7 deletions

View file

@ -31,8 +31,13 @@ abstract class PaidMedia implements ObjectTypeInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function fromArray(array $data): PaidMedia public static function fromArray(?array $data): ?PaidMedia
{ {
if($data === null)
{
return null;
}
if(!isset($data['type'])) if(!isset($data['type']))
{ {
throw new InvalidArgumentException('Paid media type is required'); throw new InvalidArgumentException('Paid media type is required');

View file

@ -48,10 +48,14 @@ class PaidMediaPhoto extends PaidMedia implements ObjectTypeInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function fromArray(array $data): PaidMediaPhoto public static function fromArray(?array $data): ?PaidMediaPhoto
{ {
$object = new self(); if($data === null)
{
return null;
}
$object = new self();
$object->type = PaidMediaType::PHOTO; $object->type = PaidMediaType::PHOTO;
$object->photo = array_map(fn(array $photo) => PhotoSize::fromArray($photo), $data['photo']); $object->photo = array_map(fn(array $photo) => PhotoSize::fromArray($photo), $data['photo']);

View file

@ -58,10 +58,14 @@ class PaidMediaPreview extends PaidMedia implements ObjectTypeInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function fromArray(array $data): PaidMediaPreview public static function fromArray(?array $data): ?PaidMediaPreview
{ {
$object = new self(); if($data === null)
{
return null;
}
$object = new self();
$object->type = PaidMediaType::PREVIEW; $object->type = PaidMediaType::PREVIEW;
$object->width = $data['width'] ?? null; $object->width = $data['width'] ?? null;
$object->height = $data['height'] ?? null; $object->height = $data['height'] ?? null;

View file

@ -35,10 +35,14 @@ class PaidMediaVideo extends PaidMedia implements ObjectTypeInterface
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function fromArray(array $data): PaidMediaVideo public static function fromArray(?array $data): ?PaidMediaVideo
{ {
$object = new self(); if($data === null)
{
return null;
}
$object = new self();
$object->type = PaidMediaType::VIDEO; $object->type = PaidMediaType::VIDEO;
$object->video = Video::fromArray($data['video']); $object->video = Video::fromArray($data['video']);