From 5ef0ccf9a7b58e443a22093b5dd296aae8409880 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Mon, 19 Jun 2017 13:49:28 -0400 Subject: [PATCH] Some minor refactoring --- src/API/MAL/Model.php | 97 ++++++++++++++++++++------------ src/Command/SyncKitsuWithMal.php | 6 +- 2 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/API/MAL/Model.php b/src/API/MAL/Model.php index d9677769..5ce186bc 100644 --- a/src/API/MAL/Model.php +++ b/src/API/MAL/Model.php @@ -67,6 +67,13 @@ class Model { return $this->listItem->create($data, $type); } + /** + * Create a list item on MAL from a Kitsu list item + * + * @param array $data + * @param string $type "anime" or "manga" + * @return Request + */ public function createListItem(array $data, string $type = 'anime'): Request { if ($type === 'anime') @@ -91,41 +98,13 @@ class Model { return $this->listItem->create($createData, $type); } - public function getMangaList(): array - { - return $this->getList('manga'); - } - - public function getAnimeList(): array - { - return $this->getList('anime'); - } - - public function getListItem(string $listId): array - { - return []; - } - - public function updateListItem(array $data, string $type = 'anime'): Request - { - if ($type === 'anime') - { - $updateData = $this->animeListTransformer->untransform($data); - } - else if ($type === 'manga') - { - $updateData = $this->mangaListTransformer->untransform($data); - } - - return $this->listItem->update($updateData['id'], $updateData['data'], $type); - } - - public function deleteListItem(string $id, string $type = 'anime'): Request - { - return $this->listItem->delete($id, $type); - } - - private function getList(string $type): array + /** + * Get list info + * + * @param string $type "anime" or "manga" + * @return array + */ + public function getList(string $type): array { $config = $this->container->get('config'); $userName = $config->get(['mal', 'username']); @@ -140,6 +119,52 @@ class Model { ] ]); - return $list['myanimelist'][$type]; + return $list['myanimelist'][$type] ?? []; + } + + /** + * Retrieve a list item + * + * Does not apply to MAL + * + * @param string $listId + * @return array + */ + public function getListItem(string $listId): array + { + return []; + } + + /** + * Update a list item + * + * @param array $data + * @param string $type "anime" or "manga" + * @return Request + */ + public function updateListItem(array $data, string $type = 'anime'): Request + { + if ($type === 'anime') + { + $updateData = $this->animeListTransformer->untransform($data); + } + else if ($type === 'manga') + { + $updateData = $this->mangaListTransformer->untransform($data); + } + + return $this->listItem->update($updateData['id'], $updateData['data'], $type); + } + + /** + * Delete a list item + * + * @param string $id + * @param string $type "anime" or "manga" + * @return Request + */ + public function deleteListItem(string $id, string $type = 'anime'): Request + { + return $this->listItem->delete($id, $type); } } \ No newline at end of file diff --git a/src/Command/SyncKitsuWithMal.php b/src/Command/SyncKitsuWithMal.php index 99f74fad..3bcb0c4b 100644 --- a/src/Command/SyncKitsuWithMal.php +++ b/src/Command/SyncKitsuWithMal.php @@ -70,7 +70,7 @@ class SyncKitsuWithMal extends BaseCommand { public function sync(string $type) { $uType = ucfirst($type); - $malCount = count($this->malModel->{"get{$uType}List"}()); + $malCount = count($this->malModel->getList($type)); $kitsuCount = $this->kitsuModel->{"get{$uType}ListCount"}(); $this->echoBox("Number of MAL {$type} list items: {$malCount}"); @@ -138,7 +138,7 @@ class SyncKitsuWithMal extends BaseCommand { public function formatMALAnimeList() { - $orig = $this->malModel->getAnimeList(); + $orig = $this->malModel->getList('anime'); $output = []; foreach($orig as $item) @@ -162,7 +162,7 @@ class SyncKitsuWithMal extends BaseCommand { public function formatMALMangaList() { - $orig = $this->malModel->getMangaList(); + $orig = $this->malModel->getList('manga'); $output = []; foreach($orig as $item)