Skip to content

Commit 138c43a

Browse files
committed
Tweak parameters
1 parent 737c8f6 commit 138c43a

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/VerifierServer/Endpoints/SS14VerifiedEndpoint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,18 @@ public function add(string $discord, string $ss14): void
165165
$this->state->setVerifyList($list);
166166
}
167167

168-
public function remove(string $discord, string $ss14): ?array
168+
public function remove(string $discord, string $ss14 = ''): ?array
169169
{
170170
$existingIndex = $this->getIndex($discord, $ss14);
171171
if ($existingIndex === false) return null;
172172
return $this->removeIndex($existingIndex);
173173
}
174174

175-
public function getIndex(string $discord, string $ss14): int|string|false
175+
public function getIndex(string $discord, string $ss14 = ''): int|string|false
176176
{
177177
$list = &$this->state->getVerifyList();
178178
$existingIndex = array_search($discord, array_column($list, 'discord'));
179-
if ($existingIndex === false) $existingIndex = array_search($ss14, array_column($list, 'ss14'));
179+
if ($ss14 && $existingIndex === false) $existingIndex = array_search($ss14, array_column($list, 'ss14'));
180180
return $existingIndex;
181181
}
182182
}

src/VerifierServer/Endpoints/VerifiedEndpoint.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ protected function post(ServerRequestInterface|string $request, int|string &$res
170170
switch ($methodType) {
171171
case 'delete':
172172
$this->delete(
173-
$this->getIndex($ckey, $discord),
173+
$this->getIndex($discord, $ckey),
174174
$list,
175175
$response,
176176
$headers,
@@ -207,16 +207,16 @@ protected function post(ServerRequestInterface|string $request, int|string &$res
207207
*/
208208
protected function __post(array &$list, string $ckey, string $discord, int|string &$response, array &$headers, string &$body): void
209209
{
210-
$existingCkeyIndex = array_search($ckey, array_column($list, 'ss13'));
211210
$existingDiscordIndex = array_search($discord, array_column($list, 'discord'));
212-
if ($existingCkeyIndex !== false || $existingDiscordIndex !== false) {
211+
$existingCkeyIndex = array_search($ckey, array_column($list, 'ss13'));
212+
if ($existingDiscordIndex !== false || $existingCkeyIndex !== false) {
213213
$response = Response::STATUS_FORBIDDEN;
214214
$headers = ['Content-Type' => 'text/plain'];
215215
$body = 'Forbidden';
216216
return;
217217
}
218218

219-
$this->add($ckey, $discord);
219+
$this->add($discord, $ckey);
220220

221221
$headers = ['Content-Type' => 'application/json'];
222222
$headers['Content-Length'] = ($body = $this->__content())
@@ -251,30 +251,30 @@ protected function delete(int|string|false $existingIndex, array &$list, int|str
251251
: 0;
252252
}
253253

254-
public function add(string $ckey, string $discord): void
254+
public function add(string $discord, string $ckey): void
255255
{
256256
$list = &$this->state->getVerifyList();
257257
$list[] = [
258-
'ss13' => $ckey,
259258
'discord' => $discord,
259+
'ss13' => $ckey,
260260
'create_time' => date('Y-m-d H:i:s')
261261
];
262262
$this->state::writeJson($this->state->getJsonPath(), $list);
263263
$this->state->setVerifyList($list);
264264
}
265265

266-
public function remove(string $ckey, string $discord): ?array
266+
public function remove(string $discord, string $ckey = ''): ?array
267267
{
268-
$existingIndex = $this->getIndex($ckey, $discord);
268+
$existingIndex = $this->getIndex($discord, $ckey);
269269
if ($existingIndex === false) return null;
270270
return $this->removeIndex($existingIndex);
271271
}
272272

273-
public function getIndex(string $ckey, string $discord): int|string|false
273+
public function getIndex(string $discord, string $ckey = ''): int|string|false
274274
{
275275
$list = &$this->state->getVerifyList();
276276
$existingIndex = array_search($ckey, array_column($list, 'ss13'));
277-
if ($existingIndex === false) $existingIndex = array_search($discord, array_column($list, 'discord'));
277+
if ($ckey && $existingIndex === false) $existingIndex = array_search($discord, array_column($list, 'discord'));
278278
return $existingIndex;
279279
}
280280

0 commit comments

Comments
 (0)