Skip to content

Commit

Permalink
Merge pull request #7 from NateShoffner/history-fix
Browse files Browse the repository at this point in the history
Fix: History Deserialization
  • Loading branch information
janvernieuwe authored Jan 24, 2022
2 parents e44b922 + 33d2764 commit d087e31
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 15 deletions.
10 changes: 10 additions & 0 deletions metadata/JikanPHP.Model.Common.HistoryMeta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
JikanPHP\Model\Common\HistoryMeta:
properties:
malId:
type: int
type:
type: string
name:
type: string
url:
type: string
4 changes: 2 additions & 2 deletions metadata/JikanPHP.Model.User.History.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
JikanPHP\Model\User\History:
properties:
malUrl:
type: JikanPHP\Model\Common\MalUrl
meta:
type: JikanPHP\Model\Common\HistoryMeta
increment:
type: int
date:
Expand Down
64 changes: 64 additions & 0 deletions model/Common/HistoryMeta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace JikanPHP\Model\Common;

/**
* Class HistoryMeta
*
* @package JikanPHP\Model
*/
class HistoryMeta
{

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

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

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

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

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

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

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

/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
}
23 changes: 11 additions & 12 deletions model/User/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace JikanPHP\Model\User;

use JikanPHP\Model\Common\MalUrl;
use JikanPHP\Model\Common\HistoryMeta;

/**
* Class History
Expand All @@ -11,11 +11,10 @@
*/
class History
{

/**
* @var MalUrl
* @var HistoryMeta
*/
private $malUrl;
private HistoryMeta $meta;

/**
* @var int
Expand All @@ -27,14 +26,6 @@ class History
*/
private $date;

/**
* @return MalUrl
*/
public function getMalUrl(): MalUrl
{
return $this->malUrl;
}

/**
* @return int
*/
Expand All @@ -50,4 +41,12 @@ public function getDate(): \DateTimeImmutable
{
return $this->date;
}

/**
* @return HistoryMeta
*/
public function getMeta(): HistoryMeta
{
return $this->meta;
}
}
2 changes: 1 addition & 1 deletion request/User/UserHistoryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(string $username, $type = '') // "" means empty stri
$this->username = $username;

if (null !== $type) {
if (!\in_array($type, ['anime', 'manga'])) {
if (!empty($type) && !\in_array($type, ['anime', 'manga'])) {
throw new \InvalidArgumentException(sprintf('Type %s is not valid', $type));
}

Expand Down

0 comments on commit d087e31

Please sign in to comment.