Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial update #528

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/Model/News/NewsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

/**
* Class NewsList
*
* @package Jikan\Model\News\NewsList
*/
class NewsList extends Results implements Pagination
{
Expand All @@ -23,29 +21,38 @@ class NewsList extends Results implements Pagination
*/
private $lastVisiblePage = 1;


/**
* @param Parser\News\NewsListParser $parser
*
* @return NewsList
* @throws \Exception
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @return static
*/
public static function fromParser(Parser\News\NewsListParser $parser): self
{
$instance = new self();

$instance->results = $parser->getResults();
$instance->lastVisiblePage = $parser->getLastVisiblePage();
$instance->hasNextPage = $parser->getHasNextPage();

return $instance;
}

/**
* @return static
*/
public static function mock() : self
{
return new self();
}

/**
* @return array
*/
public function getResults(): array
{
return $this->results;
}

/**
* @return bool
*/
Expand All @@ -61,12 +68,4 @@ public function getLastVisiblePage(): int
{
return $this->lastVisiblePage;
}

/**
* @return array
*/
public function getResults(): array
{
return $this->results;
}
}
114 changes: 21 additions & 93 deletions src/Model/News/NewsListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Jikan\Model\News;

use Jikan\Model\Resource\NewsImageResource\NewsImageResource;
use Jikan\Model\Resource\WrapImageResource\WrapImageResource;
use Jikan\Parser\News\NewsListItemParser;
use Jikan\Parser\News\ResourceNewsListItemParser;

/**
* Class AnimeParser
Expand All @@ -15,60 +17,65 @@ class NewsListItem
/**
* @var int|null
*/
private $malId;
private int|null $malId;

/**
* @var string
*/
private $url;
private string $url;

/**
* @var string
*/
private $title;
private string $title;

/**
* @var \DateTimeImmutable
*/
private $date;
private \DateTimeImmutable $date;

/**
* @var string
*/
private $authorUsername;
private string $authorUsername;

/**
* @var string
*/
private $authorUrl;
private string $authorUrl;

/**
* @var string
*/
private $forumUrl;
private string $forumUrl;

/**
* @var WrapImageResource
* @var NewsImageResource
*/
private $images;
private NewsImageResource $images;

/**
* @var int
*/
private $comments;
private int $comments;

/**
* @var string
*/
private $excerpt;
private string $excerpt;

/**
* @var array
*/
private array $tags;

/**
* @param NewsListItemParser $parser
*
* @return NewsListItem
* @throws \InvalidArgumentException
*/
public static function fromParser(NewsListItemParser $parser): self
public static function fromParser(NewsListItemParser $parser): NewsListItem
{
$instance = new self();
$instance->malId = $parser->getMalId();
Expand All @@ -78,90 +85,11 @@ public static function fromParser(NewsListItemParser $parser): self
$instance->authorUsername = $parser->getAuthor()->getName();
$instance->authorUrl = $parser->getAuthor()->getUrl();
$instance->forumUrl = $parser->getDiscussionLink();
$instance->images = WrapImageResource::factory($parser->getImage());
$instance->images = NewsImageResource::factory($parser->getImageUrl());
$instance->comments = $parser->getComments();
$instance->excerpt = $parser->getIntro();
$instance->excerpt = $parser->getExcerpt();

return $instance;
}

/**
* @return int|null
*/
public function getMalId(): ?int
{
return $this->malId;
}

/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}

/**
* @return string
*/
public function getTitle(): string
{
return $this->title;
}

/**
* @return \DateTimeImmutable
*/
public function getDate(): \DateTimeImmutable
{
return $this->date;
}

/**
* @return string
*/
public function getAuthorUsername(): string
{
return $this->authorUsername;
}

/**
* @return string
*/
public function getAuthorUrl(): string
{
return $this->authorUrl;
}

/**
* @return string
*/
public function getForumUrl(): string
{
return $this->forumUrl;
}

/**
* @return WrapImageResource
*/
public function getImages(): WrapImageResource
{
return $this->images;
}

/**
* @return int
*/
public function getComments(): int
{
return $this->comments;
}

/**
* @return string
*/
public function getExcerpt(): string
{
return $this->excerpt;
}
}
72 changes: 72 additions & 0 deletions src/Model/News/ResourceNewsList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Jikan\Model\News;

use Jikan\Model\Common\Collection\Pagination;
use Jikan\Model\Common\Collection\Results;
use Jikan\Parser;

/**
* Class ResourceNewsList
*
* @package Jikan\Model\News\ResourceNewsList
*/
class ResourceNewsList extends Results implements Pagination
{
/**
* @var bool
*/
private $hasNextPage = false;

/**
* @var int
*/
private $lastVisiblePage = 1;

/**
* @param Parser\News\ResourceNewsListParser $parser
*
* @return ResourceNewsList
* @throws \Exception
* @throws \RuntimeException
* @throws \InvalidArgumentException
*/
public static function fromParser(Parser\News\ResourceNewsListParser $parser): self
{
$instance = new self();

$instance->results = $parser->getResults();
$instance->hasNextPage = $parser->getHasNextPage();

return $instance;
}

public static function mock() : self
{
return new self();
}

/**
* @return bool
*/
public function hasNextPage(): bool
{
return $this->hasNextPage;
}

/**
* @return int
*/
public function getLastVisiblePage(): int
{
return $this->lastVisiblePage;
}

/**
* @return array
*/
public function getResults(): array
{
return $this->results;
}
}
Loading