mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 10:24:31 +02:00
Applied rector suggestions
This commit is contained in:
parent
4106bcef5f
commit
20f32c7f12
170 changed files with 808 additions and 761 deletions
|
@ -26,6 +26,7 @@ namespace App\Services\InfoProviderSystem\DTOs;
|
|||
/**
|
||||
* This DTO represents a file that can be downloaded from a URL.
|
||||
* This could be a datasheet, a 3D model, a picture or similar.
|
||||
* @see \App\Tests\Services\InfoProviderSystem\DTOs\FileDTOTest
|
||||
*/
|
||||
class FileDTO
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Services\InfoProviderSystem\DTOs;
|
|||
/**
|
||||
* This DTO represents a parameter of a part (similar to the AbstractParameter entity).
|
||||
* This could be a voltage, a current, a temperature or similar.
|
||||
* @see \App\Tests\Services\InfoProviderSystem\DTOs\ParameterDTOTest
|
||||
*/
|
||||
class ParameterDTO
|
||||
{
|
||||
|
@ -76,7 +77,7 @@ class ParameterDTO
|
|||
$parts = preg_split('/\s*(\.{3}|~)\s*/', $value);
|
||||
if (count($parts) === 2) {
|
||||
//Try to extract number and unit from value (allow leading +)
|
||||
if (empty($unit)) {
|
||||
if ($unit === null || trim($unit) === '') {
|
||||
[$number, $unit] = self::splitIntoValueAndUnit(ltrim($parts[0], " +")) ?? [$parts[0], null];
|
||||
} else {
|
||||
$number = $parts[0];
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace App\Services\InfoProviderSystem\DTOs;
|
|||
|
||||
/**
|
||||
* This DTO represents a purchase information for a part (supplier name, order number and prices).
|
||||
* @see \App\Tests\Services\InfoProviderSystem\DTOs\PurchaseInfoDTOTest
|
||||
*/
|
||||
class PurchaseInfoDTO
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@ use App\Entity\Parts\ManufacturingStatus;
|
|||
|
||||
/**
|
||||
* This DTO represents a search result for a part.
|
||||
* @see \App\Tests\Services\InfoProviderSystem\DTOs\SearchResultDTOTest
|
||||
*/
|
||||
class SearchResultDTO
|
||||
{
|
||||
|
|
|
@ -45,6 +45,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
|
||||
/**
|
||||
* This class converts DTOs to entities which can be persisted in the DB
|
||||
* @see \App\Tests\Services\InfoProviderSystem\DTOtoEntityConverterTest
|
||||
*/
|
||||
final class DTOtoEntityConverter
|
||||
{
|
||||
|
@ -127,7 +128,7 @@ final class DTOtoEntityConverter
|
|||
$entity->setAttachmentType($type);
|
||||
|
||||
//If no name is given, try to extract the name from the URL
|
||||
if (empty($dto->name)) {
|
||||
if ($dto->name === null || $dto->name === '' || $dto->name === '0') {
|
||||
$entity->setName($this->getAttachmentNameFromURL($dto->url));
|
||||
} else {
|
||||
$entity->setName($dto->name);
|
||||
|
|
|
@ -27,6 +27,7 @@ use App\Services\InfoProviderSystem\Providers\InfoProviderInterface;
|
|||
|
||||
/**
|
||||
* This class keeps track of all registered info providers and allows to find them by their key
|
||||
* @see \App\Tests\Services\InfoProviderSystem\ProviderRegistryTest
|
||||
*/
|
||||
final class ProviderRegistry
|
||||
{
|
||||
|
|
|
@ -93,7 +93,7 @@ class DigikeyProvider implements InfoProviderInterface
|
|||
public function isActive(): bool
|
||||
{
|
||||
//The client ID has to be set and a token has to be available (user clicked connect)
|
||||
return !empty($this->clientId) && $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
|
||||
return $this->clientId !== '' && $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
|
@ -210,7 +210,7 @@ class DigikeyProvider implements InfoProviderInterface
|
|||
$footprint_name = $parameter['Value'];
|
||||
}
|
||||
|
||||
if (in_array(trim($parameter['Value']), array('', '-'), true)) {
|
||||
if (in_array(trim((string) $parameter['Value']), ['', '-'], true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ class Element14Provider implements InfoProviderInterface
|
|||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return !empty($this->api_key);
|
||||
return $this->api_key !== '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,7 +96,7 @@ class LCSCProvider implements InfoProviderInterface
|
|||
*/
|
||||
private function getRealDatasheetUrl(?string $url): string
|
||||
{
|
||||
if (!empty($url) && preg_match("/^https:\/\/(datasheet\.lcsc\.com|www\.lcsc\.com\/datasheet)\/.*(C\d+)\.pdf$/", $url, $matches) > 0) {
|
||||
if ($url !== null && trim($url) !== '' && preg_match("/^https:\/\/(datasheet\.lcsc\.com|www\.lcsc\.com\/datasheet)\/.*(C\d+)\.pdf$/", $url, $matches) > 0) {
|
||||
$response = $this->lcscClient->request('GET', $url, [
|
||||
'headers' => [
|
||||
'Referer' => 'https://www.lcsc.com/product-detail/_' . $matches[2] . '.html'
|
||||
|
@ -139,7 +139,7 @@ class LCSCProvider implements InfoProviderInterface
|
|||
// LCSC does not display LCSC codes in the search, instead taking you directly to the
|
||||
// detailed product listing. It does so utilizing a product tip field.
|
||||
// If product tip exists and there are no products in the product list try a detail query
|
||||
if (count($products) === 0 && !($tipProductCode === null)) {
|
||||
if (count($products) === 0 && $tipProductCode !== null) {
|
||||
$result[] = $this->queryDetail($tipProductCode);
|
||||
}
|
||||
|
||||
|
@ -174,11 +174,11 @@ class LCSCProvider implements InfoProviderInterface
|
|||
{
|
||||
// Get product images in advance
|
||||
$product_images = $this->getProductImages($product['productImages'] ?? null);
|
||||
$product['productImageUrl'] = $product['productImageUrl'] ?? null;
|
||||
$product['productImageUrl'] ??= null;
|
||||
|
||||
// If the product does not have a product image but otherwise has attached images, use the first one.
|
||||
if (count($product_images) > 0) {
|
||||
$product['productImageUrl'] = $product['productImageUrl'] ?? $product_images[0]->url;
|
||||
$product['productImageUrl'] ??= $product_images[0]->url;
|
||||
}
|
||||
|
||||
// LCSC puts HTML in footprints and descriptions sometimes randomly
|
||||
|
@ -321,7 +321,7 @@ class LCSCProvider implements InfoProviderInterface
|
|||
foreach ($attributes as $attribute) {
|
||||
|
||||
//Skip this attribute if it's empty
|
||||
if (in_array(trim($attribute['paramValueEn']), array('', '-'), true)) {
|
||||
if (in_array(trim((string) $attribute['paramValueEn']), ['', '-'], true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class MouserProvider implements InfoProviderInterface
|
|||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return !empty($this->api_key);
|
||||
return $this->api_key !== '';
|
||||
}
|
||||
|
||||
public function searchByKeyword(string $keyword): array
|
||||
|
@ -247,7 +247,7 @@ class MouserProvider implements InfoProviderInterface
|
|||
|
||||
private function parseDataSheets(?string $sheetUrl, ?string $sheetName): ?array
|
||||
{
|
||||
if (empty($sheetUrl)) {
|
||||
if ($sheetUrl === null || $sheetUrl === '' || $sheetUrl === '0') {
|
||||
return null;
|
||||
}
|
||||
$result = [];
|
||||
|
|
|
@ -183,7 +183,7 @@ class OctopartProvider implements InfoProviderInterface
|
|||
{
|
||||
//The client ID has to be set and a token has to be available (user clicked connect)
|
||||
//return /*!empty($this->clientId) && */ $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
|
||||
return !empty($this->clientId) && !empty($this->secret);
|
||||
return $this->clientId !== '' && $this->secret !== '';
|
||||
}
|
||||
|
||||
private function mapLifeCycleStatus(?string $value): ?ManufacturingStatus
|
||||
|
@ -243,11 +243,14 @@ class OctopartProvider implements InfoProviderInterface
|
|||
//If we encounter the mass spec, we save it for later
|
||||
if ($spec['attribute']['shortname'] === "weight") {
|
||||
$mass = (float) $spec['siValue'];
|
||||
} else if ($spec['attribute']['shortname'] === "case_package") { //Package
|
||||
} elseif ($spec['attribute']['shortname'] === "case_package") {
|
||||
//Package
|
||||
$package = $spec['value'];
|
||||
} else if ($spec['attribute']['shortname'] === "numberofpins") { //Pin Count
|
||||
} elseif ($spec['attribute']['shortname'] === "numberofpins") {
|
||||
//Pin Count
|
||||
$pinCount = $spec['value'];
|
||||
} else if ($spec['attribute']['shortname'] === "lifecyclestatus") { //LifeCycleStatus
|
||||
} elseif ($spec['attribute']['shortname'] === "lifecyclestatus") {
|
||||
//LifeCycleStatus
|
||||
$mStatus = $this->mapLifeCycleStatus($spec['value']);
|
||||
}
|
||||
|
||||
|
@ -295,7 +298,7 @@ class OctopartProvider implements InfoProviderInterface
|
|||
$category = null;
|
||||
if (!empty($part['category']['name'])) {
|
||||
$category = implode(' -> ', array_map(static fn($c) => $c['name'], $part['category']['ancestors'] ?? []));
|
||||
if (!empty($category)) {
|
||||
if ($category !== '' && $category !== '0') {
|
||||
$category .= ' -> ';
|
||||
}
|
||||
$category .= $part['category']['name'];
|
||||
|
|
|
@ -47,7 +47,7 @@ class TMEClient
|
|||
|
||||
public function isUsable(): bool
|
||||
{
|
||||
return !($this->token === '' || $this->secret === '');
|
||||
return $this->token !== '' && $this->secret !== '';
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ class TMEProvider implements InfoProviderInterface
|
|||
$result[] = new SearchResultDTO(
|
||||
provider_key: $this->getProviderKey(),
|
||||
provider_id: $product['Symbol'],
|
||||
name: !empty($product['OriginalSymbol']) ? $product['OriginalSymbol'] : $product['Symbol'],
|
||||
name: empty($product['OriginalSymbol']) ? $product['Symbol'] : $product['OriginalSymbol'],
|
||||
description: $product['Description'],
|
||||
category: $product['Category'],
|
||||
manufacturer: $product['Producer'],
|
||||
|
@ -116,7 +116,7 @@ class TMEProvider implements InfoProviderInterface
|
|||
return new PartDetailDTO(
|
||||
provider_key: $this->getProviderKey(),
|
||||
provider_id: $product['Symbol'],
|
||||
name: !empty($product['OriginalSymbol']) ? $product['OriginalSymbol'] : $product['Symbol'],
|
||||
name: empty($product['OriginalSymbol']) ? $product['Symbol'] : $product['OriginalSymbol'],
|
||||
description: $product['Description'],
|
||||
category: $product['Category'],
|
||||
manufacturer: $product['Producer'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue