Some minor refactoring

This commit is contained in:
Timothy Warren 2017-06-19 13:49:28 -04:00
parent fa74e59854
commit e66a9f885a
2 changed files with 64 additions and 39 deletions

View File

@ -67,6 +67,13 @@ class Model {
return $this->listItem->create($data, $type); 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 public function createListItem(array $data, string $type = 'anime'): Request
{ {
if ($type === 'anime') if ($type === 'anime')
@ -91,41 +98,13 @@ class Model {
return $this->listItem->create($createData, $type); return $this->listItem->create($createData, $type);
} }
public function getMangaList(): array /**
{ * Get list info
return $this->getList('manga'); *
} * @param string $type "anime" or "manga"
* @return array
public function getAnimeList(): array */
{ public function getList(string $type): 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
{ {
$config = $this->container->get('config'); $config = $this->container->get('config');
$userName = $config->get(['mal', 'username']); $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);
} }
} }

View File

@ -70,7 +70,7 @@ class SyncKitsuWithMal extends BaseCommand {
public function sync(string $type) public function sync(string $type)
{ {
$uType = ucfirst($type); $uType = ucfirst($type);
$malCount = count($this->malModel->{"get{$uType}List"}()); $malCount = count($this->malModel->getList($type));
$kitsuCount = $this->kitsuModel->{"get{$uType}ListCount"}(); $kitsuCount = $this->kitsuModel->{"get{$uType}ListCount"}();
$this->echoBox("Number of MAL {$type} list items: {$malCount}"); $this->echoBox("Number of MAL {$type} list items: {$malCount}");
@ -138,7 +138,7 @@ class SyncKitsuWithMal extends BaseCommand {
public function formatMALAnimeList() public function formatMALAnimeList()
{ {
$orig = $this->malModel->getAnimeList(); $orig = $this->malModel->getList('anime');
$output = []; $output = [];
foreach($orig as $item) foreach($orig as $item)
@ -162,7 +162,7 @@ class SyncKitsuWithMal extends BaseCommand {
public function formatMALMangaList() public function formatMALMangaList()
{ {
$orig = $this->malModel->getMangaList(); $orig = $this->malModel->getList('manga');
$output = []; $output = [];
foreach($orig as $item) foreach($orig as $item)