Browse Source

Some minor refactoring

Timothy J. Warren 1 year ago
parent
commit
5ef0ccf9a7
2 changed files with 52 additions and 27 deletions
  1. 49
    24
      src/API/MAL/Model.php
  2. 3
    3
      src/Command/SyncKitsuWithMal.php

+ 49
- 24
src/API/MAL/Model.php View File

@@ -67,6 +67,13 @@ class Model {
67 67
 		return $this->listItem->create($data, $type);
68 68
 	}
69 69
 
70
+	/**
71
+	 * Create a list item on MAL from a Kitsu list item
72
+	 *
73
+	 * @param array $data
74
+	 * @param string $type "anime" or "manga"
75
+	 * @return Request
76
+	 */
70 77
 	public function createListItem(array $data, string $type = 'anime'): Request
71 78
 	{
72 79
 		if ($type === 'anime')
@@ -91,21 +98,50 @@ class Model {
91 98
 		return $this->listItem->create($createData, $type);
92 99
 	}
93 100
 
94
-	public function getMangaList(): array
101
+	/**
102
+	 * Get list info
103
+	 *
104
+	 * @param string $type "anime" or "manga"
105
+	 * @return array
106
+	 */
107
+	public function getList(string $type): array
95 108
 	{
96
-		return $this->getList('manga');
97
-	}
109
+		$config = $this->container->get('config');
110
+		$userName = $config->get(['mal', 'username']);
111
+		$list = $this->getRequest('https://myanimelist.net/malappinfo.php', [
112
+			'headers' => [
113
+				'Accept' => 'text/xml'
114
+			],
115
+			'query' => [
116
+				'u' => $userName,
117
+				'status' => 'all',
118
+				'type' => $type
119
+			]
120
+		]);
98 121
 
99
-	public function getAnimeList(): array
100
-	{
101
-		return $this->getList('anime');
122
+		return $list['myanimelist'][$type] ?? [];
102 123
 	}
103 124
 
125
+	/**
126
+	 * Retrieve a list item
127
+	 *
128
+	 * Does not apply to MAL
129
+	 *
130
+	 * @param string $listId
131
+	 * @return array
132
+	 */
104 133
 	public function getListItem(string $listId): array
105 134
 	{
106 135
 		return [];
107 136
 	}
108 137
 
138
+	/**
139
+	 * Update a list item
140
+	 *
141
+	 * @param array $data
142
+	 * @param string $type "anime" or "manga"
143
+	 * @return Request
144
+	 */
109 145
 	public function updateListItem(array $data, string $type = 'anime'): Request
110 146
 	{
111 147
 		if ($type === 'anime')
@@ -120,26 +156,15 @@ class Model {
120 156
 		return $this->listItem->update($updateData['id'], $updateData['data'], $type);
121 157
 	}
122 158
 
159
+	/**
160
+	 * Delete a list item
161
+	 *
162
+	 * @param string $id
163
+	 * @param string $type "anime" or "manga"
164
+	 * @return Request
165
+	 */
123 166
 	public function deleteListItem(string $id, string $type = 'anime'): Request
124 167
 	{
125 168
 		return $this->listItem->delete($id, $type);
126 169
 	}
127
-
128
-	private function getList(string $type): array
129
-	{
130
-		$config = $this->container->get('config');
131
-		$userName = $config->get(['mal', 'username']);
132
-		$list = $this->getRequest('https://myanimelist.net/malappinfo.php', [
133
-			'headers' => [
134
-				'Accept' => 'text/xml'
135
-			],
136
-			'query' => [
137
-				'u' => $userName,
138
-				'status' => 'all',
139
-				'type' => $type
140
-			]
141
-		]);
142
-
143
-		return $list['myanimelist'][$type];
144
-	}
145 170
 }

+ 3
- 3
src/Command/SyncKitsuWithMal.php View File

@@ -70,7 +70,7 @@ class SyncKitsuWithMal extends BaseCommand {
70 70
 	public function sync(string $type)
71 71
 	{
72 72
 		$uType = ucfirst($type);
73
-		$malCount = count($this->malModel->{"get{$uType}List"}());
73
+		$malCount = count($this->malModel->getList($type));
74 74
 		$kitsuCount = $this->kitsuModel->{"get{$uType}ListCount"}();
75 75
 
76 76
 		$this->echoBox("Number of MAL {$type} list items: {$malCount}");
@@ -138,7 +138,7 @@ class SyncKitsuWithMal extends BaseCommand {
138 138
 
139 139
 	public function formatMALAnimeList()
140 140
 	{
141
-		$orig = $this->malModel->getAnimeList();
141
+		$orig = $this->malModel->getList('anime');
142 142
 		$output = [];
143 143
 
144 144
 		foreach($orig as $item)
@@ -162,7 +162,7 @@ class SyncKitsuWithMal extends BaseCommand {
162 162
 
163 163
 	public function formatMALMangaList()
164 164
 	{
165
-		$orig = $this->malModel->getMangaList();
165
+		$orig = $this->malModel->getList('manga');
166 166
 		$output = [];
167 167
 
168 168
 		foreach($orig as $item)