From 7f7f353ed5d183bccea058016f676e3a3eda4a2f Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 4 Oct 2024 15:18:43 -0400 Subject: [PATCH] Updated ShippingOption --- .../Objects/Payments/ShippingOption.php | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/TgBotLib/Objects/Payments/ShippingOption.php b/src/TgBotLib/Objects/Payments/ShippingOption.php index ae4ab8f..0eabdf2 100644 --- a/src/TgBotLib/Objects/Payments/ShippingOption.php +++ b/src/TgBotLib/Objects/Payments/ShippingOption.php @@ -7,20 +7,12 @@ class ShippingOption implements ObjectTypeInterface { - /** - * @var string - */ - private $id; - - /** - * @var string - */ - private $title; - + private string $id; + private string $title; /** * @var LabeledPrice[] */ - private $prices; + private array $prices; /** * Shipping option identifier @@ -62,26 +54,24 @@ return [ 'id' => $this->id, 'title' => $this->title, - 'prices' => array_map(function (LabeledPrice $price) { - return $price->toArray(); - }, $this->prices) + 'prices' => array_map(fn(LabeledPrice $item) => $item->toArray(), $this->prices) ]; } /** - * Constructs object from an array representation - * - * @param array $data - * @return ShippingOption + * @inheritDoc */ - public static function fromArray(array $data): self + public static function fromArray(?array $data): ?ShippingOption { + if($data === null) + { + return null; + } + $object = new self(); $object->id = $data['id']; $object->title = $data['title']; - $object->prices = array_map(function (array $price) { - return LabeledPrice::fromArray($price); - }, $data['prices']); + $object->prices = array_map(fn($item) => LabeledPrice::fromArray($item), $data['prices']); return $object; }