8000 RC blockers: nullable getters, getMembers() null, review scores by irfan-dahir · Pull Request #658 · jikan-me/jikan · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ which changes a consumer can see.

## Unreleased

### Breaking
- **31 model getters can now return `null`**, where they used to throw a `TypeError` on pages that don't show the field. **You must** handle `null` from these getters; code that only ran on pages with the field present sees no difference.
- `Anime::getDuration()`
- `EpisodeListItem::getScore()`, `getUrl()`, `getForumUrl()`
- `StreamEpisodeListItem::getMalId()`
- `ResourceArticle::getDate()`
- `NewsMeta::getDate()`, `getMalId()`
- `NewsListItem::getDate()`, `ResourceNews::getDate()`, `ResourceNewsListItem::getDate()`
- `getMalId()` on `AnimeGenreListItem`, `MangaGenreListItem`, `MagazineListItem` and `ProducerListItem`
- `Person::getMemberFavorites()`
- `VoiceActingRole::getRole()`
- `UserSearchListItem::getLastOnline()`
- `AnimeStats`: `getDaysWatched()`, `getEpisodesWatched()`, `getMeanScore()`, `getRewatched()`, `getTotalEntries()`
- `MangaStats`: `getChaptersRead()`, `getDaysRead()`, `getMeanScore()`, `getReread()`, `getTotalEntries()`, `getVolumesRead()`
- `Profile::getLocation()`
- `UserReviews::getLastVisiblePage()`

Each was declared non-null while its parser already returned `null` when MyAnimeList leaves the field out, for example an episode nobody has voted on, or a profile without a location.
- **`AnimeCard::getMembers()` returns `?int`**: `null` when a card shows no member count. In beta.2 it raised `ParserException`, which failed the whole page. **You must** handle `null`.

### Fixed
- `getAnimeScores()` and `getMangaScores()` on anime reviews, manga reviews and reviewers return the reviewer's overall rating. They always failed: the anime one called a parser that had been deleted, and the manga one read a score table that no longer exists. MyAnimeList's 2022 review redesign dropped the per-category ratings, so `getOverall()` is the "Reviewer's Rating" and the category getters (`getStory()`, `getAnimation()`, `getArt()` and so on) return `null`. `AnimeReviewScores`/`MangaReviewScores` are built with `fromOverall()`; their `fromParser()` and `Jikan\Parser\Manga\MangaReviewScoresParser`, which could not work, are removed.

---

## v5.0.0-beta.2 — 2026-10-15
Expand Down
66 changes: 0 additions & 66 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,6 @@ parameters:
count: 1
path: src/Http/HttpClientWrapper.php

-
message: '#^Call to method getAnimationScore\(\) on an unknown class Jikan\\Parser\\Reviews\\AnimeReviewScoresParser\.$#'
identifier: class.notFound
count: 1
path: src/Model/Anime/AnimeReviewScores.php

-
message: '#^Call to method getCharacterScore\(\) on an unknown class Jikan\\Parser\\Reviews\\AnimeReviewScoresParser\.$#'
identifier: class.notFound
count: 1
path: src/Model/Anime/AnimeReviewScores.php

-
message: '#^Call to method getEnjoymentScore\(\) on an unknown class Jikan\\Parser\\Reviews\\AnimeReviewScoresParser\.$#'
identifier: class.notFound
count: 1
path: src/Model/Anime/AnimeReviewScores.php

-
message: '#^Call to method getOverallScore\(\) on an unknown class Jikan\\Parser\\Reviews\\AnimeReviewScoresParser\.$#'
identifier: class.notFound
count: 1
path: src/Model/Anime/AnimeReviewScores.php

-
message: '#^Call to method getSoundScore\(\) on an unknown class Jikan\\Parser\\Reviews\\AnimeReviewScoresParser\.$#'
identifier: class.notFound
count: 1
path: src/Model/Anime/AnimeReviewScores.php

-
message: '#^Call to method getStoryScore\(\) on an unknown class Jikan\\Parser\\Reviews\\AnimeReviewScoresParser\.$#'
identifier: class.notFound
count: 1
path: src/Model/Anime/AnimeReviewScores.php

-
message: '#^Parameter \$parser of method Jikan\\Model\\Anime\\AnimeReviewScores\:\:fromParser\(\) has invalid type Jikan\\Parser\\Reviews\\AnimeReviewScoresParser\.$#'
identifier: class.notFound
count: 2
path: src/Model/Anime/AnimeReviewScores.php

-
message: '#^Method Jikan\\Model\\Anime\\AnimeReviews\:\:getResults\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down Expand Up @@ -1866,18 +1824,6 @@ parameters:
count: 1
path: src/Parser/Recommendations/UserRecommendationsParser.php

-
message: '#^Call to method getModel\(\) on an unknown class Jikan\\Parser\\Reviews\\AnimeReviewScoresParser\.$#'
identifier: class.notFound
count: 1
path: src/Parser/Reviews/AnimeReviewParser.php

-
message: '#^Instantiated class Jikan\\Parser\\Reviews\\AnimeReviewScoresParser not found\.$#'
identifier: class.notFound
count: 1
path: src/Parser/Reviews/AnimeReviewParser.php

-
message: '#^Method Jikan\\Parser\\Reviews\\AnimeReviewParser\:\:getReviewTag\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
Expand Down Expand Up @@ -1908,18 +1854,6 @@ parameters:
count: 1
path: src/Parser/Reviews/ReactionsParser.php

-
message: '#^Call to method getModel\(\) on an unknown class Jikan\\Parser\\Reviews\\AnimeReviewScoresParser\.$#'
identifier: class.notFound
count: 1
path: src/Parser/Reviews/ReviewerParser.php

-
message: '#^Instantiated class Jikan\\Parser\\Reviews\\AnimeReviewScoresParser not found\.$#'
identifier: class.notFound
count: 1
path: src/Parser/Reviews/ReviewerParser.php

-
message: '#^Method Jikan\\Parser\\Reviews\\ReviewerParser\:\:getModel\(\) has no return type specified\.$#'
identifier: missingType.return
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Anime/Anime.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ public function getAired(): DateRange
}

/**
* @return string
* @return string|null
*/
public function getDuration(): string
public function getDuration(): ?string
{
return $this->duration;
}
Expand Down
83 changes: 22 additions & 61 deletions src/Model/Anime/AnimeReviewScores.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,110 +2,71 @@

namespace Jikan\Model\Anime;

use Jikan\Parser;

/**
* Class AnimeReviewScores
*
* MyAnimeList's review redesign (2022) dropped the per-category ratings; a review now shows one overall
* "Reviewer's Rating". The category getters stay for compatibility and return null.
*
* @package Jikan\Model
*/
class AnimeReviewScores
{
/**
* @var int
*/
private $overall;

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

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

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

/**
* @var int
*/
private $character;
private int $overall;

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

/**
* @param Parser\Reviews\AnimeReviewScoresParser $parser
*
* @return AnimeReviewScores
* @throws \InvalidArgumentException
*/
public static function fromParser(Parser\Reviews\AnimeReviewScoresParser $parser): AnimeReviewScores
public static function fromOverall(int $overall): AnimeReviewScores
{
$instance = new self();

$instance->overall = $parser->getOverallScore();
$instance->story = $parser->getStoryScore();
$instance->animation = $parser->getAnimationScore();
$instance->sound = $parser->getSoundScore();
$instance->character = $parser->getCharacterScore();
$instance->enjoyment = $parser->getEnjoymentScore();
$instance->overall = $overall;

return $instance;
}

/**
* @return int
* The reviewer's overall rating, 1 to 10.
*/
public function getOverall(): int
{
return $this->overall;
}

/**
* @return int
* @return null MyAnimeList no longer shows category ratings.
*/
public function getStory(): int
public function getStory(): ?int
{
return $this->story;
return null;
}

/**
* @return int
* @return null MyAnimeList no longer shows category ratings.
*/
public function getAnimation(): int
public function getAnimation(): ?int
{
return $this->animation;
return null;
}

/**
* @return int
* @return null MyAnimeList no longer shows category ratings.
*/
public function getSound(): int
public function getSound(): ?int
{
return $this->sound;
return null;
}

/**
* @return int
* @return null MyAnimeList no longer shows category ratings.
*/
public function getCharacter(): int
public function getCharacter(): ?int
{
return $this->character;
return null;
}

/**
* @return int
* @return null MyAnimeList no longer shows category ratings.
*/
public function getEnjoyment(): int
public function getEnjoyment(): ?int
{
return $this->enjoyment;
return null;
}
}
12 changes: 6 additions & 6 deletions src/Model/Anime/EpisodeListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ public function getAired()
}

/**
* @return float
* @return float|null
*/
public function getScore(): float
public function getScore(): ?float
{
return $this->score;
}
Expand All @@ -150,17 +150,17 @@ public function isRecap(): bool
}

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

/**
* @return string
* @return string|null
*/
public function getForumUrl(): string
public function getForumUrl(): ?string
{
return $this->forumUrl;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Anime/StreamEpisodeListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public static function fromParser(StreamEpisodeListItemParser $parser): self
}

/**
* @return int
* @return int|null
*/
public function getMalId(): int
public function getMalId(): ?int
{
return $this->malId;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Article/ResourceArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ResourceArticle
/**
* @var \DateTimeImmutable
*/
private \DateTimeImmutable $date;
private ?\DateTimeImmutable $date;

/**
* @var string
Expand Down Expand Up @@ -107,9 +107,9 @@ public function getExcerpt(): string
}

/**
* @return \DateTimeImmutable
* @return \DateTimeImmutable|null
*/
public function getDate(): \DateTimeImmutable
public function getDate(): ?\DateTimeImmutable
{
return $this->date;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Common/AnimeCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AnimeCard
protected $episodes;

/**
* @var int
* @var int|null
*/
protected $members;

Expand Down Expand Up @@ -243,9 +243,9 @@ public function getEpisodes(): ?int
}

/**
* @return int
* @return int|null null when the card shows no member count
*/
public function getMembers(): int
public function getMembers(): ?int
{
return $this->members;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Model/Common/NewsMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NewsMeta
/**
* @var int
*/
private int $malId;
private ?int $malId;

/**
* @var string
Expand All @@ -30,7 +30,7 @@ class NewsMeta
/**
* @var \DateTimeImmutable
*/
private \DateTimeImmutable $date;
private ?\DateTimeImmutable $date;

/**
* @var string
Expand Down Expand Up @@ -87,9 +87,9 @@ public function __toString()
}

/**
* @return int
* @return int|null
*/
public function getMalId(): int
public function getMalId(): ?int
{
return $this->malId;
}
Expand All @@ -111,9 +111,9 @@ public function getTitle(): string
}

/**
* @return \DateTimeImmutable
* @return \DateTimeImmutable|null
*/
public function getDate(): \DateTimeImmutable
public function getDate(): ?\DateTimeImmutable
{
return $this->date;
}
Expand Down
Loading
0