From 881ecce21dd29408853eaa231c0eee45a85537fc Mon Sep 17 00:00:00 2001 From: Irfan Date: Thu, 14 Jan 2021 07:50:32 +0500 Subject: [PATCH] Update Watch Models [ci skip] --- src/Model/Watch/EpisodeListItem.php | 60 ++++---------------- src/Model/Watch/PromotionalVideoListItem.php | 9 +-- src/Parser/Watch/EpisodeListItemParser.php | 10 ++++ 3 files changed, 25 insertions(+), 54 deletions(-) diff --git a/src/Model/Watch/EpisodeListItem.php b/src/Model/Watch/EpisodeListItem.php index f2fcf1cc..b282b4d0 100644 --- a/src/Model/Watch/EpisodeListItem.php +++ b/src/Model/Watch/EpisodeListItem.php @@ -2,6 +2,7 @@ namespace Jikan\Model\Watch; +use Jikan\Model\Common\AnimeMeta; use Jikan\Model\Resource\CommonImageResource\CommonImageResource; use Jikan\Parser\Watch\EpisodeListItemParser; @@ -14,24 +15,9 @@ class EpisodeListItem { /** - * @var int + * @var AnimeMeta */ - private $malId; - - /** - * @var string - */ - private $url; - - /** - * @var string - */ - private $name; - - /** - * @var CommonImageResource - */ - private $images; + private $entry; /** * @var RecentEpisodeListItem @@ -52,10 +38,7 @@ class EpisodeListItem public static function fromParser(EpisodeListItemParser $parser): EpisodeListItem { $instance = new self(); - $instance->malId = $parser->getId(); - $instance->url = $parser->getUrl(); - $instance->name = $parser->getTitle(); - $instance->images = CommonImageResource::factory($parser->getImages()); + $instance->entry = $parser->getAnimeMeta(); $instance->episodes = $parser->getEpisodes(); $instance->regionLocked = $parser->getRegionLocked(); @@ -63,41 +46,17 @@ public static function fromParser(EpisodeListItemParser $parser): EpisodeListIte } /** - * @return int + * @return AnimeMeta */ - public function getMalId(): int + public function getEntry(): AnimeMeta { - return $this->malId; + return $this->entry; } /** - * @return string + * @return RecentEpisodeListItem */ - public function getUrl(): string - { - return $this->url; - } - - /** - * @return string - */ - public function getName(): string - { - return $this->name; - } - - /** - * @return AnimeResourceImages - */ - public function getImages(): AnimeResourceImages - { - return $this->images; - } - - /** - * @return NewEpisodeListItem - */ - public function getEpisodes(): NewEpisodeListItem + public function getEpisodes(): RecentEpisodeListItem { return $this->episodes; } @@ -109,4 +68,5 @@ public function isRegionLocked(): bool { return $this->regionLocked; } + } diff --git a/src/Model/Watch/PromotionalVideoListItem.php b/src/Model/Watch/PromotionalVideoListItem.php index c3c6a49b..e24860d7 100644 --- a/src/Model/Watch/PromotionalVideoListItem.php +++ b/src/Model/Watch/PromotionalVideoListItem.php @@ -23,7 +23,7 @@ class PromotionalVideoListItem /** * @var AnimeMeta */ - private $anime; + private $entry; /** * @var YoutubeMeta @@ -39,7 +39,7 @@ class PromotionalVideoListItem public static function fromParser(PromotionalVideoListItemParser $parser): self { $instance = new self(); - $instance->anime = new AnimeMeta( + $instance->entry = new AnimeMeta( $parser->getTitle(), $parser->getUrl(), $parser->getImages() @@ -61,9 +61,9 @@ public function getTitle(): string /** * @return AnimeMeta */ - public function getAnime(): AnimeMeta + public function getEntry(): AnimeMeta { - return $this->anime; + return $this->entry; } /** @@ -74,4 +74,5 @@ public function getTrailer(): YoutubeMeta return $this->trailer; } + } diff --git a/src/Parser/Watch/EpisodeListItemParser.php b/src/Parser/Watch/EpisodeListItemParser.php index f6102db4..9a1bdab6 100644 --- a/src/Parser/Watch/EpisodeListItemParser.php +++ b/src/Parser/Watch/EpisodeListItemParser.php @@ -4,6 +4,7 @@ use Jikan\Helper\JString; use Jikan\Helper\Parser; +use Jikan\Model\Common\AnimeMeta; use Jikan\Model\Watch\EpisodeListItem; use Jikan\Model\Watch\RecentEpisodeListItem; use Jikan\Parser\ParserInterface; @@ -126,4 +127,13 @@ public function getRegionLocked() : bool return $node->count(); } + + public function getAnimeMeta() : AnimeMeta + { + return new AnimeMeta( + $this->getTitle(), + $this->getUrl(), + $this->getImageUrl() + ); + } }