mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-07-15 13:51:39 +00:00
Add suggested improvements from SonarQube
This commit is contained in:
parent
bbd551e625
commit
87c7402414
1 changed files with 40 additions and 30 deletions
|
|
@ -370,8 +370,9 @@ class BuerklinProvider implements BatchInfoProviderInterface
|
||||||
*/
|
*/
|
||||||
private function getProductImages(?array $images): array
|
private function getProductImages(?array $images): array
|
||||||
{
|
{
|
||||||
if (!is_array($images))
|
if (!is_array($images)) {
|
||||||
return [];
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
// 1) Only real image entries with URL
|
// 1) Only real image entries with URL
|
||||||
$imgs = array_values(array_filter($images, fn($i) => is_array($i) && !empty($i['url'])));
|
$imgs = array_values(array_filter($images, fn($i) => is_array($i) && !empty($i['url'])));
|
||||||
|
|
@ -395,8 +396,9 @@ class BuerklinProvider implements BatchInfoProviderInterface
|
||||||
if (!str_starts_with($url, 'http://') && !str_starts_with($url, 'https://')) {
|
if (!str_starts_with($url, 'http://') && !str_starts_with($url, 'https://')) {
|
||||||
$url = 'https://www.buerklin.com' . $url;
|
$url = 'https://www.buerklin.com' . $url;
|
||||||
}
|
}
|
||||||
if (!filter_var($url, FILTER_VALIDATE_URL))
|
if (!filter_var($url, FILTER_VALIDATE_URL)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$byUrl[$url] = $url;
|
$byUrl[$url] = $url;
|
||||||
}
|
}
|
||||||
|
|
@ -412,12 +414,14 @@ class BuerklinProvider implements BatchInfoProviderInterface
|
||||||
$out = [];
|
$out = [];
|
||||||
|
|
||||||
foreach ($features as $f) {
|
foreach ($features as $f) {
|
||||||
if (!is_array($f))
|
if (!is_array($f)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$name = $f['name'] ?? null;
|
$name = $f['name'] ?? null;
|
||||||
if (!is_string($name) || trim($name) === '')
|
if (!is_string($name) || trim($name) === '') {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$vals = [];
|
$vals = [];
|
||||||
foreach (($f['featureValues'] ?? []) as $fv) {
|
foreach (($f['featureValues'] ?? []) as $fv) {
|
||||||
|
|
@ -425,8 +429,9 @@ class BuerklinProvider implements BatchInfoProviderInterface
|
||||||
$vals[] = trim($fv['value']);
|
$vals[] = trim($fv['value']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count($vals) === 0)
|
if (empty($vals)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Multiple values: join with comma
|
// Multiple values: join with comma
|
||||||
$value = implode(', ', array_values(array_unique($vals)));
|
$value = implode(', ', array_values(array_unique($vals)));
|
||||||
|
|
@ -462,9 +467,7 @@ 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 ($keyword === '') {
|
if (!empty($keyword)) {
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $this->makeAPICall('/products/search/', [
|
$response = $this->makeAPICall('/products/search/', [
|
||||||
'pageSize' => 50,
|
'pageSize' => 50,
|
||||||
|
|
@ -476,7 +479,7 @@ class BuerklinProvider implements BatchInfoProviderInterface
|
||||||
$products = $response['products'] ?? [];
|
$products = $response['products'] ?? [];
|
||||||
|
|
||||||
// Normal case: products found in search results
|
// Normal case: products found in search results
|
||||||
if (is_array($products) && count($products) > 0) {
|
if (is_array($products) && !empty($products)) {
|
||||||
return array_map(fn($p) => $this->getPartDetail($p), $products);
|
return array_map(fn($p) => $this->getPartDetail($p), $products);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -488,6 +491,11 @@ class BuerklinProvider implements BatchInfoProviderInterface
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getDetails(string $id): PartDetailDTO
|
public function getDetails(string $id): PartDetailDTO
|
||||||
{
|
{
|
||||||
|
|
@ -513,8 +521,9 @@ class BuerklinProvider implements BatchInfoProviderInterface
|
||||||
$params = [];
|
$params = [];
|
||||||
|
|
||||||
$add = function (string $name, $value) use (&$params, $group) {
|
$add = function (string $name, $value) use (&$params, $group) {
|
||||||
if ($value === null)
|
if ($value === null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_bool($value)) {
|
if (is_bool($value)) {
|
||||||
$value = $value ? 'Yes' : 'No';
|
$value = $value ? 'Yes' : 'No';
|
||||||
|
|
@ -523,9 +532,10 @@ class BuerklinProvider implements BatchInfoProviderInterface
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
$value = trim((string) $value);
|
$value = trim((string) $value);
|
||||||
if ($value === '')
|
if ($value === '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$params[] = ParameterDTO::parseValueField(
|
$params[] = ParameterDTO::parseValueField(
|
||||||
name: $name,
|
name: $name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue