From fdeea75b2fd6ade9d89d05cc3ef73794231ac1e4 Mon Sep 17 00:00:00 2001 From: n0099 Date: Sun, 15 Sep 2024 16:36:15 +0000 Subject: [PATCH] * remove `exit()` statement that exists from f8939b885ed4e2424f3c2aa60dd19e837318d049, and now being unnecessary due to 8089d16dc327a228d57eab85cff63da8fd28b12a @ `App\Helper->abortAPI()` * suppress or fix some violations of phpmd rules @ be --- be/app/Helper.php | 1 - be/app/Http/PostsQuery/BaseQuery.php | 1 + be/app/Http/PostsQuery/IndexQuery.php | 3 +++ be/app/Http/PostsQuery/QueryParams.php | 3 +++ be/app/Http/PostsQuery/SearchQuery.php | 9 +++------ 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/be/app/Helper.php b/be/app/Helper.php index 5244853e..6e89de69 100644 --- a/be/app/Helper.php +++ b/be/app/Helper.php @@ -95,7 +95,6 @@ public static function abortAPI(int $errorCode): never throw new \InvalidArgumentException('Given error code doesn\'t existed'); } response()->json(compact('errorCode', 'errorInfo'), $statusCode)->throwResponse(); - exit; } /** diff --git a/be/app/Http/PostsQuery/BaseQuery.php b/be/app/Http/PostsQuery/BaseQuery.php index 975ecbba..5c611ccc 100644 --- a/be/app/Http/PostsQuery/BaseQuery.php +++ b/be/app/Http/PostsQuery/BaseQuery.php @@ -323,6 +323,7 @@ static function (string $postIDName) use ($result): array { * @param Collection $subReplies * @phpcs:ignore Generic.Files.LineLength.TooLong * @return Collection>>>>> + * @SuppressWarnings(PHPMD.CamelCaseParameterName) */ public static function nestPostsWithParent( Collection $threads, diff --git a/be/app/Http/PostsQuery/IndexQuery.php b/be/app/Http/PostsQuery/IndexQuery.php index 4f920b37..5f78ce6b 100644 --- a/be/app/Http/PostsQuery/IndexQuery.php +++ b/be/app/Http/PostsQuery/IndexQuery.php @@ -13,6 +13,9 @@ class IndexQuery extends BaseQuery { + /** + * @SuppressWarnings(PHPMD.ElseExpression) + */ public function query(QueryParams $params, ?string $cursor): self { /** @var array $flatParams key by param name */ diff --git a/be/app/Http/PostsQuery/QueryParams.php b/be/app/Http/PostsQuery/QueryParams.php index 024b7e7f..7521e3d3 100644 --- a/be/app/Http/PostsQuery/QueryParams.php +++ b/be/app/Http/PostsQuery/QueryParams.php @@ -70,6 +70,9 @@ protected function getParamsIndexByName(string $name): array return array_keys(array_filter($this->params, static fn($p) => $p->name === $name)); } + /** + * @SuppressWarnings(PHPMD.ElseExpression) + */ public function addDefaultValueOnUniqueParams(): void { $uniqueParamsDefaultValue = [ diff --git a/be/app/Http/PostsQuery/SearchQuery.php b/be/app/Http/PostsQuery/SearchQuery.php index 77b5f22b..f59ac3a7 100644 --- a/be/app/Http/PostsQuery/SearchQuery.php +++ b/be/app/Http/PostsQuery/SearchQuery.php @@ -156,12 +156,9 @@ private static function applyTextMatchParamOnQuery( trim("$not LIKE"), $subParams['matchBy'] === 'implicit' ? "%$keyword%" : $keyword ); - if ($subParams['spaceSplit']) { // split multiple search keyword by space char - foreach (explode(' ', $value) as $splitedKeyword) { - $addMatchKeyword($splitedKeyword); - } - } else { - $addMatchKeyword($value); + // split multiple search keyword by space char when $subParams['spaceSplit'] == true + foreach ($subParams['spaceSplit'] ? explode(' ', $value) : [$value] as $keyword) { + $addMatchKeyword($keyword); } }); }