Fixed some inspection issues

This commit is contained in:
Jan Böhmer 2024-03-03 19:57:31 +01:00
parent 33475dca66
commit 42e604245c
85 changed files with 272 additions and 291 deletions

View file

@ -45,7 +45,7 @@ class FileDTO
//Find all occurrences of non URL safe characters and replace them with their URL encoded version.
//We only want to replace characters which can not have a valid meaning in a URL (what would break the URL).
//Digikey provided some wrong URLs with a ^ in them, which is not a valid URL character. (https://github.com/Part-DB/Part-DB-server/issues/521)
$this->url = preg_replace_callback('/[^a-zA-Z0-9_\-.$+!*();\/?:@=&#%]/', fn($matches) => rawurlencode($matches[0]), $url);
$this->url = preg_replace_callback('/[^a-zA-Z0-9_\-.$+!*();\/?:@=&#%]/', static fn($matches) => rawurlencode($matches[0]), $url);
}

View file

@ -125,7 +125,7 @@ class Element14Provider implements InfoProviderInterface
}
/**
* @param mixed[]|null $datasheets
* @param array|null $datasheets
* @return FileDTO[]|null Array of FileDTOs
*/
private function parseDataSheets(?array $datasheets): ?array

View file

@ -40,7 +40,7 @@ class LCSCProvider implements InfoProviderInterface
public const DISTRIBUTOR_NAME = 'LCSC';
public function __construct(private readonly HttpClientInterface $lcscClient, private string $currency, private bool $enabled = true)
public function __construct(private readonly HttpClientInterface $lcscClient, private readonly string $currency, private readonly bool $enabled = true)
{
}
@ -152,10 +152,7 @@ class LCSCProvider implements InfoProviderInterface
}
//Build category by concatenating the catalogName and parentCatalogName
$category = null;
if (isset($product['parentCatalogName'])) {
$category = $product['parentCatalogName'];
}
$category = $product['parentCatalogName'] ?? null;
if (isset($product['catalogName'])) {
$category = ($category ?? '') . ' -> ' . $product['catalogName'];

View file

@ -210,7 +210,7 @@ class OctopartProvider implements InfoProviderInterface
$item = $this->partInfoCache->getItem($key);
$item->set($part);
$item->expiresAfter(3600 * 24 * 1); //Cache for 1 day
$item->expiresAfter(3600 * 24); //Cache for 1 day
$this->partInfoCache->save($item);
}
@ -295,7 +295,7 @@ class OctopartProvider implements InfoProviderInterface
//Built the category full path
$category = null;
if (!empty($part['category']['name'])) {
$category = implode(' -> ', array_map(fn($c) => $c['name'], $part['category']['ancestors'] ?? []));
$category = implode(' -> ', array_map(static fn($c) => $c['name'], $part['category']['ancestors'] ?? []));
if (!empty($category)) {
$category .= ' -> ';
}

View file

@ -49,11 +49,7 @@ class TMEClient
public function isUsable(): bool
{
if ($this->token === '' || $this->secret === '') {
return false;
}
return true;
return !($this->token === '' || $this->secret === '');
}