mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-02 14:34:31 +02:00
Fixed some inspection issues
This commit is contained in:
parent
33475dca66
commit
42e604245c
85 changed files with 272 additions and 291 deletions
|
@ -448,7 +448,7 @@ class AttachmentSubmitHandler
|
|||
'g' => 1000 * 1000 * 1000,
|
||||
'gi' => 1 << 30,
|
||||
];
|
||||
if (ctype_digit((string) $maxSize)) {
|
||||
if (ctype_digit($maxSize)) {
|
||||
return (int) $maxSize;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,9 @@ class FileTypeFilterTools
|
|||
//Convert jpg to .jpg
|
||||
$element = '.'.$element;
|
||||
}
|
||||
|
||||
//Prevent weird side effects
|
||||
unset($element);
|
||||
}
|
||||
|
||||
$elements = array_unique($elements);
|
||||
|
|
|
@ -133,7 +133,7 @@ class ElementTypeNameGenerator
|
|||
{
|
||||
$type = $this->getLocalizedTypeLabel($entity);
|
||||
if ($use_html) {
|
||||
return '<i>'.$type.':</i> '.htmlspecialchars((string) $entity->getName());
|
||||
return '<i>'.$type.':</i> '.htmlspecialchars($entity->getName());
|
||||
}
|
||||
|
||||
return $type.': '.$entity->getName();
|
||||
|
|
|
@ -42,7 +42,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||
|
||||
use function \count;
|
||||
use function count;
|
||||
|
||||
/**
|
||||
* This service is used to import the datastructures (categories, manufacturers, etc.) from a PartKeepr export.
|
||||
|
|
|
@ -222,7 +222,7 @@ trait PKImportHelperTrait
|
|||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function setCreationDate(TimeStampableInterface $entity, ?string $datetime_str)
|
||||
protected function setCreationDate(TimeStampableInterface $entity, ?string $datetime_str): void
|
||||
{
|
||||
if ($datetime_str !== null && $datetime_str !== '' && $datetime_str !== '0000-00-00 00:00:00') {
|
||||
$date = new \DateTime($datetime_str);
|
||||
|
@ -252,7 +252,7 @@ trait PKImportHelperTrait
|
|||
$prefixes = $data['siprefix'];
|
||||
foreach ($prefixes as $prefix) {
|
||||
if ((int) $prefix['id'] === $prefix_id) {
|
||||
return pow((int) $prefix['base'], (int) $prefix['exponent']);
|
||||
return (int)$prefix['base'] ** (int)$prefix['exponent'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'];
|
||||
|
||||
|
|
|
@ -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 .= ' -> ';
|
||||
}
|
||||
|
|
|
@ -49,11 +49,7 @@ class TMEClient
|
|||
|
||||
public function isUsable(): bool
|
||||
{
|
||||
if ($this->token === '' || $this->secret === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return !($this->token === '' || $this->secret === '');
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
|
|||
#[AsDecorator(decorates: DompdfFactoryInterface::class)]
|
||||
class DompdfFactory implements DompdfFactoryInterface
|
||||
{
|
||||
public function __construct(private string $fontDirectory, private string $tmpDirectory)
|
||||
public function __construct(private readonly string $fontDirectory, private readonly string $tmpDirectory)
|
||||
{
|
||||
//Create folder if it does not exist
|
||||
$this->createDirectoryIfNotExisting($this->fontDirectory);
|
||||
|
|
|
@ -119,7 +119,7 @@ final class PartProvider implements PlaceholderProviderInterface
|
|||
}
|
||||
|
||||
if ('[[DESCRIPTION_T]]' === $placeholder) {
|
||||
return strip_tags((string) $parsedown->line($part->getDescription()));
|
||||
return strip_tags($parsedown->line($part->getDescription()));
|
||||
}
|
||||
|
||||
if ('[[COMMENT]]' === $placeholder) {
|
||||
|
@ -127,7 +127,7 @@ final class PartProvider implements PlaceholderProviderInterface
|
|||
}
|
||||
|
||||
if ('[[COMMENT_T]]' === $placeholder) {
|
||||
return strip_tags((string) $parsedown->line($part->getComment()));
|
||||
return strip_tags($parsedown->line($part->getComment()));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -41,7 +41,7 @@ class LogDataFormatter
|
|||
public function formatData(mixed $data, AbstractLogEntry $logEntry, string $fieldName): string
|
||||
{
|
||||
if (is_string($data)) {
|
||||
$tmp = '<span class="text-muted user-select-none">"</span>' . mb_strimwidth(htmlspecialchars($data), 0, self::STRING_MAX_LENGTH, ) . '<span class="text-muted user-select-none">"</span>';
|
||||
$tmp = '<span class="text-muted user-select-none">"</span>' . mb_strimwidth(htmlspecialchars($data), 0, self::STRING_MAX_LENGTH) . '<span class="text-muted user-select-none">"</span>';
|
||||
|
||||
//Show special characters and line breaks
|
||||
$tmp = preg_replace('/\n/', '<span class="text-muted user-select-none">\\n</span><br>', $tmp);
|
||||
|
@ -87,7 +87,7 @@ class LogDataFormatter
|
|||
|
||||
private function formatJSON(array $data): string
|
||||
{
|
||||
$json = htmlspecialchars(json_encode($data, JSON_PRETTY_PRINT), ENT_QUOTES | ENT_SUBSTITUTE);
|
||||
$json = htmlspecialchars(json_encode($data, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT), ENT_QUOTES | ENT_SUBSTITUTE);
|
||||
|
||||
return sprintf(
|
||||
'<div data-controller="elements--json-formatter" data-json="%s"></div>',
|
||||
|
|
|
@ -105,7 +105,7 @@ class DBInfoHelper
|
|||
*/
|
||||
public function getDatabaseName(): ?string
|
||||
{
|
||||
return $this->connection->getDatabase() ?? null;
|
||||
return $this->connection->getDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -98,7 +98,7 @@ final class OAuthTokenManager
|
|||
$token = $this->getToken($app_name);
|
||||
|
||||
if (!$token) {
|
||||
throw new \Exception('No token was saved yet for '.$app_name);
|
||||
throw new \RuntimeException('No token was saved yet for '.$app_name);
|
||||
}
|
||||
|
||||
$client = $this->clientRegistry->getClient($app_name);
|
||||
|
|
|
@ -17,7 +17,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
final class PartLotWithdrawAddHelper
|
||||
{
|
||||
public function __construct(private readonly EventLogger $eventLogger,
|
||||
private readonly EventCommentHelper $eventCommentHelper, private EntityManagerInterface $entityManager)
|
||||
private readonly EventCommentHelper $eventCommentHelper, private readonly EntityManagerInterface $entityManager)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ class NodesListBuilder
|
|||
/** @var StructuralDBElementRepository $repo */
|
||||
$repo = $this->em->getRepository($class_name);
|
||||
|
||||
return array_map(fn(AbstractDBElement $element) => $element->getID(), $repo->getFlatList($parent));
|
||||
return array_map(static fn(AbstractDBElement $element) => $element->getID(), $repo->getFlatList($parent));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class TreeViewGenerator
|
|||
protected ElementCacheTagGenerator $tagGenerator,
|
||||
protected UserCacheKeyGenerator $keyGenerator,
|
||||
protected TranslatorInterface $translator,
|
||||
private UrlGeneratorInterface $router,
|
||||
private readonly UrlGeneratorInterface $router,
|
||||
protected bool $rootNodeExpandedByDefault,
|
||||
protected bool $rootNodeEnabled,
|
||||
|
||||
|
|
|
@ -33,8 +33,8 @@ class DecoratedGoogleAuthenticator implements GoogleAuthenticatorInterface
|
|||
|
||||
public function __construct(
|
||||
#[AutowireDecorated]
|
||||
private GoogleAuthenticatorInterface $inner,
|
||||
private RequestStack $requestStack)
|
||||
private readonly GoogleAuthenticatorInterface $inner,
|
||||
private readonly RequestStack $requestStack)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue