mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-01-16 15:19:34 +00:00
Revert SonarQube proposed change. Having more than one return is acceptable nowadays
This commit is contained in:
parent
5852ef9674
commit
e49e2d7976
1 changed files with 19 additions and 20 deletions
|
|
@ -465,30 +465,29 @@ class BuerklinProvider implements BatchInfoProviderInterface
|
||||||
public function searchByKeyword(string $keyword): array
|
public function searchByKeyword(string $keyword): array
|
||||||
{
|
{
|
||||||
$keyword = strtoupper(trim($keyword));
|
$keyword = strtoupper(trim($keyword));
|
||||||
if (!empty($keyword)) {
|
if ($keyword === '') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$response = $this->makeAPICall('/products/search/', [
|
$response = $this->makeAPICall('/products/search/', [
|
||||||
'pageSize' => 50,
|
'pageSize' => 50,
|
||||||
'currentPage' => 0,
|
'currentPage' => 0,
|
||||||
'query' => $keyword,
|
'query' => $keyword,
|
||||||
'sort' => 'relevance',
|
'sort' => 'relevance',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$products = $response['products'] ?? [];
|
$products = $response['products'] ?? [];
|
||||||
|
|
||||||
// Normal case: products found in search results
|
// Normal case: products found in search results
|
||||||
if (is_array($products) && !empty($products)) {
|
if (is_array($products) && !empty($products)) {
|
||||||
return array_map(fn($p) => $this->getPartDetail($p), $products);
|
return array_map(fn($p) => $this->getPartDetail($p), $products);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: try direct lookup by code
|
// Fallback: try direct lookup by code
|
||||||
try {
|
try {
|
||||||
$product = $this->getProduct($keyword);
|
$product = $this->getProduct($keyword);
|
||||||
return [$this->getPartDetail($product)];
|
return [$this->getPartDetail($product)];
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return [];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue