Improve 404 checks for detail pages
All checks were successful
timw4mail/HummingBirdAnimeClient/develop This commit looks good

This commit is contained in:
Timothy Warren 2019-08-10 10:09:07 -04:00
parent 3fae7fe9d6
commit 27160bda9a
5 changed files with 65 additions and 29 deletions

View File

@ -299,28 +299,40 @@ final class Anime extends BaseController {
*/
public function details(string $animeId): void
{
$data = $this->model->getAnime($animeId);
try
{
$data = $this->model->getAnime($animeId);
if (empty($data))
if ($data->isEmpty())
{
$this->notFound(
$this->config->get('whose_list') .
"'s Anime List · Anime · " .
'Anime not found',
'Anime Not Found'
);
return;
}
$this->outputHTML('anime/details', [
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Anime',
$data->title
),
'data' => $data,
]);
}
catch (\TypeError $e)
{
$this->notFound(
$this->config->get('whose_list') .
"'s Anime List · Anime · " .
'Anime not found',
"'s Anime List · Anime · " .
'Anime not found',
'Anime Not Found'
);
return;
}
$this->outputHTML('anime/details', [
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s Anime List",
'Anime',
$data->title
),
'data' => $data,
]);
}
/**

View File

@ -304,7 +304,7 @@ final class Manga extends Controller {
$staff = [];
$characters = [];
if (empty($data))
if ($data->isEmpty())
{
$this->notFound(
$this->config->get('whose_list') .

View File

@ -166,7 +166,7 @@ class Anime extends API {
$requester = new ParallelAPIRequest();
$requester->addRequest($this->kitsuModel->createListItem($data), 'kitsu');
if ($data['mal_id'] !== null && $this->anilistEnabled)
if ($this->anilistEnabled && $data['mal_id'] !== null)
{
$requester->addRequest($this->anilistModel->createListItem($data, 'ANIME'), 'anilist');
}
@ -187,9 +187,7 @@ class Anime extends API {
$requester = new ParallelAPIRequest();
$requester->addRequest($this->kitsuModel->incrementListItem($data), 'kitsu');
$array = $data->toArray();
if ($array['mal_id'] !== null && $this->anilistEnabled)
if ($this->anilistEnabled && $data['mal_id'] !== null)
{
$requester->addRequest($this->anilistModel->incrementListItem($data, 'ANIME'), 'anilist');
}
@ -216,9 +214,7 @@ class Anime extends API {
$requester = new ParallelAPIRequest();
$requester->addRequest($this->kitsuModel->updateListItem($data), 'kitsu');
$array = $data->toArray();
if ($array['mal_id'] !== null && $this->anilistEnabled)
if ($this->anilistEnabled && $data['mal_id'] !== null)
{
$requester->addRequest($this->anilistModel->updateListItem($data, 'ANIME'), 'anilist');
}
@ -246,7 +242,7 @@ class Anime extends API {
$requester = new ParallelAPIRequest();
$requester->addRequest($this->kitsuModel->deleteListItem($id), 'kitsu');
if ($malId !== null && $this->anilistEnabled)
if ($this->anilistEnabled && $malId !== null)
{
$requester->addRequest($this->anilistModel->deleteListItem($malId, 'ANIME'), 'anilist');
}

View File

@ -136,7 +136,7 @@ class Manga extends API {
$requester = new ParallelAPIRequest();
$requester->addRequest($this->kitsuModel->createListItem($data), 'kitsu');
if (array_key_exists('mal_id', $data) && $this->anilistEnabled)
if ($this->anilistEnabled && array_key_exists('mal_id', $data))
{
$requester->addRequest($this->anilistModel->createListItem($data, 'MANGA'), 'anilist');
}
@ -159,7 +159,7 @@ class Manga extends API {
$array = $data->toArray();
if (array_key_exists('mal_id', $array) && $this->anilistEnabled)
if ($this->anilistEnabled && array_key_exists('mal_id', $array))
{
$requester->addRequest($this->anilistModel->updateListItem($data, 'MANGA'), 'anilist');
}
@ -187,7 +187,7 @@ class Manga extends API {
$array = $data->toArray();
if (array_key_exists('mal_id', $array) && $this->anilistEnabled)
if ($this->anilistEnabled && array_key_exists('mal_id', $array))
{
$requester->addRequest($this->anilistModel->incrementListItem($data, 'MANGA'), 'anilist');
}
@ -214,7 +214,7 @@ class Manga extends API {
$requester = new ParallelAPIRequest();
$requester->addRequest($this->kitsuModel->deleteListItem($id), 'kitsu');
if ($malId !== null && $this->anilistEnabled)
if ($this->anilistEnabled && $malId !== null)
{
$requester->addRequest($this->anilistModel->deleteListItem($malId, 'MANGA'), 'anilist');
}

View File

@ -108,6 +108,16 @@ abstract class AbstractType implements ArrayAccess {
throw new UndefinedPropertyException("Trying to get undefined property: '$name'");
}
/**
* Create a string representation of the object for debugging
*
* @return string
*/
public function __toString(): string
{
return print_r($this, TRUE);
}
/**
* Implementing ArrayAccess
*
@ -180,4 +190,22 @@ abstract class AbstractType implements ArrayAccess {
return $output;
}
}
/**
* Determine whether the type has any properties set
*
* @return bool
*/
public function isEmpty(): bool
{
foreach ($this as $key => $value)
{
if ( ! empty($value))
{
return FALSE;
}
}
return TRUE;
}
}