More error checking
All checks were successful
timw4mail/HummingBirdAnimeClient/develop This commit looks good
All checks were successful
timw4mail/HummingBirdAnimeClient/develop This commit looks good
This commit is contained in:
parent
580dbb5993
commit
87ecc0dce4
@ -125,7 +125,10 @@ final class Model
|
||||
*/
|
||||
public function createListItem(array $data, string $type = 'anime'): ?Request
|
||||
{
|
||||
$createData = [];
|
||||
if ($data['mal_id'] === NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$mediaId = $this->getMediaIdFromMalId($data['mal_id'], mb_strtoupper($type));
|
||||
|
||||
@ -134,6 +137,8 @@ final class Model
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$createData = [];
|
||||
|
||||
if ($type === 'ANIME')
|
||||
{
|
||||
$createData = [
|
||||
|
@ -869,9 +869,14 @@ final class Model {
|
||||
* @return Request
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function createListItem(array $data): Request
|
||||
public function createListItem(array $data): ?Request
|
||||
{
|
||||
$data['user_id'] = $this->getUserIdByUsername($this->getUsername());
|
||||
if ($data['id'] === NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $this->listItem->create($data);
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,8 @@ use Aviat\AnimeClient\API\Anilist\Transformer\{
|
||||
AnimeListTransformer as AALT,
|
||||
MangaListTransformer as AMLT
|
||||
};
|
||||
use Aviat\AnimeClient\API\Anilist\Model as AnilistModel;
|
||||
use Aviat\AnimeClient\API\Kitsu\Model as KitsuModel;
|
||||
use Aviat\AnimeClient\API\Mapping\{AnimeWatchingStatus, MangaReadingStatus};
|
||||
use Aviat\AnimeClient\Types\FormItem;
|
||||
use Aviat\Ion\Di\Exception\ContainerException;
|
||||
@ -40,13 +42,13 @@ final class SyncLists extends BaseCommand {
|
||||
|
||||
/**
|
||||
* Model for making requests to Anilist API
|
||||
* @var \Aviat\AnimeClient\API\Anilist\Model
|
||||
* @var AnilistModel
|
||||
*/
|
||||
protected $anilistModel;
|
||||
|
||||
/**
|
||||
* Model for making requests to Kitsu API
|
||||
* @var \Aviat\AnimeClient\API\Kitsu\Model
|
||||
* @var KitsuModel
|
||||
*/
|
||||
protected $kitsuModel;
|
||||
|
||||
@ -602,6 +604,12 @@ final class SyncLists extends BaseCommand {
|
||||
}
|
||||
else if ($action === 'create')
|
||||
{
|
||||
$maybeRequest = $this->kitsuModel->createListItem($item);
|
||||
if ($maybeRequest === NULL)
|
||||
{
|
||||
$this->echoBox("Skipped creating Kitsu {$type} due to missing id ¯\_(ツ)_/¯");
|
||||
continue;
|
||||
}
|
||||
$requester->addRequest($this->kitsuModel->createListItem($item));
|
||||
}
|
||||
}
|
||||
@ -682,7 +690,6 @@ final class SyncLists extends BaseCommand {
|
||||
|
||||
$responseData = Json::decode($response);
|
||||
|
||||
// $id = $itemsToUpdate[$key]['id'];
|
||||
if ( ! array_key_exists('errors', $responseData))
|
||||
{
|
||||
$verb = ($action === 'update') ? 'updated' : 'created';
|
||||
|
@ -63,9 +63,7 @@ abstract class AbstractType implements ArrayAccess, Countable {
|
||||
*/
|
||||
public function __isset($name): bool
|
||||
{
|
||||
// This returns the expected results because unset
|
||||
// properties no longer exist on the class
|
||||
return property_exists($this, $name);
|
||||
return property_exists($this, $name) && isset($this->$name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user