mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Applied rector suggestions
This commit is contained in:
parent
4106bcef5f
commit
20f32c7f12
170 changed files with 808 additions and 761 deletions
|
@ -81,12 +81,12 @@ class EntityFilterHelper
|
|||
|
||||
public function getDescription(array $properties): array
|
||||
{
|
||||
if (!$properties) {
|
||||
if ($properties === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$description = [];
|
||||
foreach ($properties as $property => $strategy) {
|
||||
foreach (array_keys($properties) as $property) {
|
||||
$description[(string)$property] = [
|
||||
'property' => $property,
|
||||
'type' => Type::BUILTIN_TYPE_STRING,
|
||||
|
|
|
@ -61,7 +61,7 @@ final class LikeFilter extends AbstractFilter
|
|||
}
|
||||
|
||||
$description = [];
|
||||
foreach ($this->properties as $property => $strategy) {
|
||||
foreach (array_keys($this->properties) as $property) {
|
||||
$description[(string)$property] = [
|
||||
'property' => $property,
|
||||
'type' => Type::BUILTIN_TYPE_STRING,
|
||||
|
|
|
@ -74,15 +74,10 @@ abstract class BaseAdminController extends AbstractController
|
|||
protected string $attachment_class = '';
|
||||
protected ?string $parameter_class = '';
|
||||
|
||||
/**
|
||||
* @var EventDispatcher|EventDispatcherInterface
|
||||
*/
|
||||
protected EventDispatcher|EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
public function __construct(protected TranslatorInterface $translator, protected UserPasswordHasherInterface $passwordEncoder,
|
||||
protected AttachmentSubmitHandler $attachmentSubmitHandler,
|
||||
protected EventCommentHelper $commentHelper, protected HistoryHelper $historyHelper, protected TimeTravel $timeTravel,
|
||||
protected DataTableFactory $dataTableFactory, EventDispatcherInterface $eventDispatcher, protected LabelExampleElementsGenerator $barcodeExampleGenerator,
|
||||
protected DataTableFactory $dataTableFactory, protected EventDispatcher|EventDispatcherInterface $eventDispatcher, protected LabelExampleElementsGenerator $barcodeExampleGenerator,
|
||||
protected LabelGenerator $labelGenerator, protected EntityManagerInterface $entityManager)
|
||||
{
|
||||
if ('' === $this->entity_class || '' === $this->form_class || '' === $this->twig_template || '' === $this->route_base) {
|
||||
|
@ -96,7 +91,6 @@ abstract class BaseAdminController extends AbstractController
|
|||
if ('' === $this->parameter_class || ($this->parameter_class && !is_a($this->parameter_class, AbstractParameter::class, true))) {
|
||||
throw new InvalidArgumentException('You have to override the $parameter_class value with a valid Parameter class in your subclass!');
|
||||
}
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
protected function revertElementIfNeeded(AbstractDBElement $entity, ?string $timestamp): ?DateTime
|
||||
|
@ -192,10 +186,8 @@ abstract class BaseAdminController extends AbstractController
|
|||
}
|
||||
|
||||
//Ensure that the master picture is still part of the attachments
|
||||
if ($entity instanceof AttachmentContainingDBElement) {
|
||||
if ($entity->getMasterPictureAttachment() !== null && !$entity->getAttachments()->contains($entity->getMasterPictureAttachment())) {
|
||||
$entity->setMasterPictureAttachment(null);
|
||||
}
|
||||
if ($entity instanceof AttachmentContainingDBElement && ($entity->getMasterPictureAttachment() !== null && !$entity->getAttachments()->contains($entity->getMasterPictureAttachment()))) {
|
||||
$entity->setMasterPictureAttachment(null);
|
||||
}
|
||||
|
||||
$this->commentHelper->setMessage($form['log_comment']->getData());
|
||||
|
@ -283,10 +275,8 @@ abstract class BaseAdminController extends AbstractController
|
|||
}
|
||||
|
||||
//Ensure that the master picture is still part of the attachments
|
||||
if ($new_entity instanceof AttachmentContainingDBElement) {
|
||||
if ($new_entity->getMasterPictureAttachment() !== null && !$new_entity->getAttachments()->contains($new_entity->getMasterPictureAttachment())) {
|
||||
$new_entity->setMasterPictureAttachment(null);
|
||||
}
|
||||
if ($new_entity instanceof AttachmentContainingDBElement && ($new_entity->getMasterPictureAttachment() !== null && !$new_entity->getAttachments()->contains($new_entity->getMasterPictureAttachment()))) {
|
||||
$new_entity->setMasterPictureAttachment(null);
|
||||
}
|
||||
|
||||
$this->commentHelper->setMessage($form['log_comment']->getData());
|
||||
|
|
|
@ -30,6 +30,9 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Controller\KiCadApiControllerTest
|
||||
*/
|
||||
#[Route('/kicad-api/v1')]
|
||||
class KiCadApiController extends AbstractController
|
||||
{
|
||||
|
@ -62,7 +65,7 @@ class KiCadApiController extends AbstractController
|
|||
#[Route('/parts/category/{category}.json', name: 'kicad_api_category')]
|
||||
public function categoryParts(?Category $category): Response
|
||||
{
|
||||
if ($category) {
|
||||
if ($category !== null) {
|
||||
$this->denyAccessUnlessGranted('read', $category);
|
||||
} else {
|
||||
$this->denyAccessUnlessGranted('@categories.read');
|
||||
|
|
|
@ -51,7 +51,7 @@ class OAuthClientController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/{name}/check', name: 'oauth_client_check')]
|
||||
public function check(string $name, Request $request): Response
|
||||
public function check(string $name): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('@system.manage_oauth_tokens');
|
||||
|
||||
|
|
|
@ -329,7 +329,7 @@ class PartController extends AbstractController
|
|||
$this->em->flush();
|
||||
if ($mode === 'new') {
|
||||
$this->addFlash('success', 'part.created_flash');
|
||||
} else if ($mode === 'edit') {
|
||||
} elseif ($mode === 'edit') {
|
||||
$this->addFlash('success', 'part.edited_flash');
|
||||
}
|
||||
|
||||
|
@ -358,11 +358,11 @@ class PartController extends AbstractController
|
|||
$template = '';
|
||||
if ($mode === 'new') {
|
||||
$template = 'parts/edit/new_part.html.twig';
|
||||
} else if ($mode === 'edit') {
|
||||
} elseif ($mode === 'edit') {
|
||||
$template = 'parts/edit/edit_part_info.html.twig';
|
||||
} else if ($mode === 'merge') {
|
||||
} elseif ($mode === 'merge') {
|
||||
$template = 'parts/edit/merge_parts.html.twig';
|
||||
} else if ($mode === 'update_from_ip') {
|
||||
} elseif ($mode === 'update_from_ip') {
|
||||
$template = 'parts/edit/update_from_ip.html.twig';
|
||||
}
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ class ProjectController extends AbstractController
|
|||
'project' => $project,
|
||||
'part' => $part
|
||||
]);
|
||||
if ($bom_entry) {
|
||||
if ($bom_entry !== null) {
|
||||
$preset_data->add($bom_entry);
|
||||
} else { //Otherwise create an empty one
|
||||
$entry = new ProjectBOMEntry();
|
||||
|
|
|
@ -54,6 +54,9 @@ use Symfony\Component\HttpFoundation\Response;
|
|||
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Controller\ScanControllerTest
|
||||
*/
|
||||
#[Route(path: '/scan')]
|
||||
class ScanController extends AbstractController
|
||||
{
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Component\Runtime\SymfonyRuntime;
|
||||
use App\Services\Attachments\AttachmentSubmitHandler;
|
||||
use App\Services\Attachments\AttachmentURLGenerator;
|
||||
use App\Services\Attachments\BuiltinAttachmentsFinder;
|
||||
|
@ -84,7 +85,7 @@ class ToolsController extends AbstractController
|
|||
'php_post_max_size' => ini_get('post_max_size'),
|
||||
'kernel_runtime_environment' => $this->getParameter('kernel.runtime_environment'),
|
||||
'kernel_runtime_mode' => $this->getParameter('kernel.runtime_mode'),
|
||||
'kernel_runtime' => $_SERVER['APP_RUNTIME'] ?? $_ENV['APP_RUNTIME'] ?? 'Symfony\\Component\\Runtime\\SymfonyRuntime',
|
||||
'kernel_runtime' => $_SERVER['APP_RUNTIME'] ?? $_ENV['APP_RUNTIME'] ?? SymfonyRuntime::class,
|
||||
|
||||
//DB section
|
||||
'db_type' => $DBInfoHelper->getDatabaseType() ?? 'Unknown',
|
||||
|
|
|
@ -59,11 +59,8 @@ use Symfony\Component\Validator\Constraints\Length;
|
|||
#[Route(path: '/user')]
|
||||
class UserSettingsController extends AbstractController
|
||||
{
|
||||
protected EventDispatcher|EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
public function __construct(protected bool $demo_mode, EventDispatcherInterface $eventDispatcher)
|
||||
public function __construct(protected bool $demo_mode, protected EventDispatcher|EventDispatcherInterface $eventDispatcher)
|
||||
{
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
#[Route(path: '/2fa_backup_codes', name: 'show_backup_codes')]
|
||||
|
|
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\DataTables\Adapters;
|
||||
|
||||
use Doctrine\ORM\Query\Expr\From;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
|
@ -51,12 +52,12 @@ class TwoStepORMAdapter extends ORMAdapter
|
|||
|
||||
private bool $use_simple_total = false;
|
||||
|
||||
private \Closure|null $query_modifier;
|
||||
private \Closure|null $query_modifier = null;
|
||||
|
||||
public function __construct(ManagerRegistry $registry = null)
|
||||
{
|
||||
parent::__construct($registry);
|
||||
$this->detailQueryCallable = static function (QueryBuilder $qb, array $ids) {
|
||||
$this->detailQueryCallable = static function (QueryBuilder $qb, array $ids): never {
|
||||
throw new \RuntimeException('You need to set the detail_query option to use the TwoStepORMAdapter');
|
||||
};
|
||||
}
|
||||
|
@ -66,9 +67,7 @@ class TwoStepORMAdapter extends ORMAdapter
|
|||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setRequired('filter_query');
|
||||
$resolver->setDefault('query', function (Options $options) {
|
||||
return $options['filter_query'];
|
||||
});
|
||||
$resolver->setDefault('query', fn(Options $options) => $options['filter_query']);
|
||||
|
||||
$resolver->setRequired('detail_query');
|
||||
$resolver->setAllowedTypes('detail_query', \Closure::class);
|
||||
|
@ -108,7 +107,7 @@ class TwoStepORMAdapter extends ORMAdapter
|
|||
}
|
||||
}
|
||||
|
||||
/** @var Query\Expr\From $fromClause */
|
||||
/** @var From $fromClause */
|
||||
$fromClause = $builder->getDQLPart('from')[0];
|
||||
$identifier = "{$fromClause->getAlias()}.{$this->metadata->getSingleIdentifierFieldName()}";
|
||||
|
||||
|
@ -201,7 +200,7 @@ class TwoStepORMAdapter extends ORMAdapter
|
|||
/** The paginator count queries can be rather slow, so when query for total count (100ms or longer),
|
||||
* just return the entity count.
|
||||
*/
|
||||
/** @var Query\Expr\From $from_expr */
|
||||
/** @var From $from_expr */
|
||||
$from_expr = $queryBuilder->getDQLPart('from')[0];
|
||||
|
||||
return $this->manager->getRepository($from_expr->getFrom())->count([]);
|
||||
|
|
|
@ -92,7 +92,7 @@ final class AttachmentDataTable implements DataTableTypeInterface
|
|||
if ($context->isExternal()) {
|
||||
return sprintf(
|
||||
'<a href="%s" class="link-external">%s</a>',
|
||||
htmlspecialchars($context->getURL()),
|
||||
htmlspecialchars((string) $context->getURL()),
|
||||
htmlspecialchars($value)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\DataTables\Column;
|
||||
|
||||
use Omines\DataTablesBundle\Column\AbstractColumn;
|
||||
|
|
|
@ -109,7 +109,7 @@ class ColumnSortHelper
|
|||
}
|
||||
|
||||
//and the remaining non-visible columns
|
||||
foreach ($this->columns as $col_id => $col_data) {
|
||||
foreach (array_keys($this->columns) as $col_id) {
|
||||
if (in_array($col_id, $processed_columns, true)) {
|
||||
// column already processed
|
||||
continue;
|
||||
|
|
|
@ -162,7 +162,7 @@ class LogDataTable implements DataTableTypeInterface
|
|||
if (!$user instanceof User) {
|
||||
if ($context->isCLIEntry()) {
|
||||
return sprintf('%s [%s]',
|
||||
htmlentities($context->getCLIUsername()),
|
||||
htmlentities((string) $context->getCLIUsername()),
|
||||
$this->translator->trans('log.cli_user')
|
||||
);
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ final class PartsDataTable implements DataTableTypeInterface
|
|||
'orderField' => 'NATSORT(_partUnit.name)',
|
||||
'render' => function($value, Part $context): string {
|
||||
$partUnit = $context->getPartUnit();
|
||||
if (!$partUnit) {
|
||||
if ($partUnit === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ final class PartsDataTable implements DataTableTypeInterface
|
|||
'label' => $this->translator->trans('part.table.manufacturingStatus'),
|
||||
'class' => ManufacturingStatus::class,
|
||||
'render' => function (?ManufacturingStatus $status, Part $context): string {
|
||||
if (!$status) {
|
||||
if ($status === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
|||
'orderField' => 'NATSORT(part.name)',
|
||||
'render' => function ($value, ProjectBOMEntry $context) {
|
||||
if(!$context->getPart() instanceof Part) {
|
||||
return htmlspecialchars($context->getName());
|
||||
return htmlspecialchars((string) $context->getName());
|
||||
}
|
||||
if($context->getPart() instanceof Part) {
|
||||
$tmp = $this->partDataTableHelper->renderName($context->getPart());
|
||||
|
@ -154,7 +154,7 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
|||
'label' => 'project.bom.instockAmount',
|
||||
'visible' => false,
|
||||
'render' => function ($value, ProjectBOMEntry $context) {
|
||||
if ($context->getPart()) {
|
||||
if ($context->getPart() !== null) {
|
||||
return $this->partDataTableHelper->renderAmount($context->getPart());
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ class ProjectBomEntriesDataTable implements DataTableTypeInterface
|
|||
'label' => 'part.table.storeLocations',
|
||||
'visible' => false,
|
||||
'render' => function ($value, ProjectBOMEntry $context) {
|
||||
if ($context->getPart()) {
|
||||
if ($context->getPart() !== null) {
|
||||
return $this->partDataTableHelper->renderStorageLocations($context->getPart());
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Doctrine\Functions;
|
||||
|
||||
use Doctrine\ORM\Query\Parser;
|
||||
use Doctrine\ORM\Query\SqlWalker;
|
||||
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
|
||||
use Doctrine\ORM\Query\TokenType;
|
||||
|
||||
|
@ -36,7 +38,7 @@ class Field2 extends FunctionNode
|
|||
|
||||
private $values = [];
|
||||
|
||||
public function parse(\Doctrine\ORM\Query\Parser $parser): void
|
||||
public function parse(Parser $parser): void
|
||||
{
|
||||
$parser->match(TokenType::T_IDENTIFIER);
|
||||
$parser->match(TokenType::T_OPEN_PARENTHESIS);
|
||||
|
@ -58,15 +60,16 @@ class Field2 extends FunctionNode
|
|||
$parser->match(TokenType::T_CLOSE_PARENTHESIS);
|
||||
}
|
||||
|
||||
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker): string
|
||||
public function getSql(SqlWalker $sqlWalker): string
|
||||
{
|
||||
$query = 'FIELD2(';
|
||||
|
||||
$query .= $this->field->dispatch($sqlWalker);
|
||||
|
||||
$query .= ', ';
|
||||
$counter = count($this->values);
|
||||
|
||||
for ($i = 0; $i < count($this->values); $i++) {
|
||||
for ($i = 0; $i < $counter; $i++) {
|
||||
if ($i > 0) {
|
||||
$query .= ', ';
|
||||
}
|
||||
|
@ -74,8 +77,6 @@ class Field2 extends FunctionNode
|
|||
$query .= $this->values[$i]->dispatch($sqlWalker);
|
||||
}
|
||||
|
||||
$query .= ')';
|
||||
|
||||
return $query;
|
||||
return $query . ')';
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Doctrine\Functions;
|
||||
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver;
|
||||
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
|
||||
|
@ -59,9 +60,9 @@ class Natsort extends FunctionNode
|
|||
* The result is cached in memory.
|
||||
* @param Connection $connection
|
||||
* @return bool
|
||||
* @throws \Doctrine\DBAL\Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function mariaDBSupportsNaturalSort(Connection $connection): bool
|
||||
private function mariaDBSupportsNaturalSort(Connection $connection): bool
|
||||
{
|
||||
if (self::$supportsNaturalSort !== null) {
|
||||
return self::$supportsNaturalSort;
|
||||
|
@ -95,7 +96,7 @@ class Natsort extends FunctionNode
|
|||
return $this->field->dispatch($sqlWalker) . ' COLLATE numeric';
|
||||
}
|
||||
|
||||
if ($platform instanceof MariaDBPlatform && self::mariaDBSupportsNaturalSort($sqlWalker->getConnection())) {
|
||||
if ($platform instanceof MariaDBPlatform && $this->mariaDBSupportsNaturalSort($sqlWalker->getConnection())) {
|
||||
return 'NATURAL_SORT_KEY(' . $this->field->dispatch($sqlWalker) . ')';
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ final class FieldHelper
|
|||
//If we are on MySQL, we can just use the FIELD function
|
||||
if ($db_platform instanceof AbstractMySQLPlatform) {
|
||||
$qb->orderBy("FIELD2($field_expr, :field_arr)", $order);
|
||||
} else if ($db_platform instanceof PostgreSQLPlatform) {
|
||||
} elseif ($db_platform instanceof PostgreSQLPlatform) {
|
||||
//Use the postgres native array_position function
|
||||
self::addPostgresOrderBy($qb, $field_expr, $key, $values, $order);
|
||||
} else {
|
||||
|
|
|
@ -98,10 +98,9 @@ class SQLiteRegexExtensionMiddlewareDriver extends AbstractDriverMiddleware
|
|||
* This function returns the index (position) of the first argument in the subsequent arguments.
|
||||
* If the first argument is not found or is NULL, 0 is returned.
|
||||
* @param string|int|null $value
|
||||
* @param mixed ...$array
|
||||
* @return int
|
||||
*/
|
||||
final public static function field(string|int|null $value, ...$array): int
|
||||
final public static function field(string|int|null $value, mixed ...$array): int
|
||||
{
|
||||
if ($value === null) {
|
||||
return 0;
|
||||
|
|
|
@ -385,7 +385,7 @@ abstract class Attachment extends AbstractNamedDBElement
|
|||
return null;
|
||||
}
|
||||
|
||||
return parse_url($this->getURL(), PHP_URL_HOST);
|
||||
return parse_url((string) $this->getURL(), PHP_URL_HOST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -477,7 +477,7 @@ abstract class Attachment extends AbstractNamedDBElement
|
|||
*/
|
||||
public function setElement(AttachmentContainingDBElement $element): self
|
||||
{
|
||||
if (!is_a($element, static::ALLOWED_ELEMENT_CLASS)) {
|
||||
if (!$element instanceof AttachmentContainingDBElement) {
|
||||
throw new InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', static::class, static::ALLOWED_ELEMENT_CLASS));
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Attachments;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
|
@ -85,8 +86,11 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
#[ApiFilter(OrderFilter::class, properties: ['name', 'id', 'addedDate', 'lastModified'])]
|
||||
class AttachmentType extends AbstractStructuralDBElement
|
||||
{
|
||||
/**
|
||||
* @var Collection<int, \App\Entity\Attachments\AttachmentType>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: AttachmentType::class, cascade: ['persist'])]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: AttachmentType::class, inversedBy: 'children')]
|
||||
|
@ -110,7 +114,7 @@ class AttachmentType extends AbstractStructuralDBElement
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: AttachmentTypeAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
#[Groups(['attachment_type:read', 'attachment_type:write'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
|
@ -123,7 +127,7 @@ class AttachmentType extends AbstractStructuralDBElement
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: AttachmentTypeParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
#[Groups(['attachment_type:read', 'attachment_type:write'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\LabelSystem;
|
||||
|
||||
enum BarcodeType: string
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\LabelSystem;
|
||||
|
||||
enum LabelPictureType: string
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\LabelSystem;
|
||||
|
||||
enum LabelProcessMode: string
|
||||
|
|
|
@ -41,6 +41,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\LabelSystem;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Repository\LabelProfileRepository;
|
||||
use App\EntityListeners\TreeCacheInvalidationListener;
|
||||
|
@ -66,7 +67,7 @@ class LabelProfile extends AttachmentContainingDBElement
|
|||
* @var Collection<int, LabelAttachment>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: LabelAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $attachments;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: LabelAttachment::class)]
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\LabelSystem;
|
||||
|
||||
use App\Entity\Parts\Part;
|
||||
|
|
|
@ -55,7 +55,8 @@ abstract class AbstractLogEntry extends AbstractDBElement
|
|||
#[ORM\Column(type: Types::STRING)]
|
||||
protected string $username = '';
|
||||
|
||||
/** @var \DateTime The datetime the event associated with this log entry has occured
|
||||
/**
|
||||
* @var \DateTimeInterface The datetime the event associated with this log entry has occured
|
||||
*/
|
||||
#[ORM\Column(name: 'datetime', type: Types::DATETIME_MUTABLE)]
|
||||
protected \DateTime $timestamp;
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
use Psr\Log\LogLevel as PSRLogLevel;
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
use App\Entity\Attachments\Attachment;
|
||||
|
@ -120,7 +122,7 @@ enum LogTargetType: int
|
|||
}
|
||||
}
|
||||
|
||||
$elementClass = is_object($element) ? get_class($element) : $element;
|
||||
$elementClass = is_object($element) ? $element::class : $element;
|
||||
//If no matching type was found, throw an exception
|
||||
throw new \InvalidArgumentException("The given class $elementClass is not a valid log target type.");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
use App\Entity\Contracts\LogWithEventUndoInterface;
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Entity\LogSystem;
|
||||
|
||||
enum PartStockChangeType: string
|
||||
|
|
|
@ -52,8 +52,6 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
$this->level = LogLevel::INFO;
|
||||
|
||||
$this->setTargetElement($lot);
|
||||
|
||||
$this->typeString = 'part_stock_changed';
|
||||
$this->extra = array_merge($this->extra, [
|
||||
't' => $type->toExtraShortType(),
|
||||
'o' => $old_stock,
|
||||
|
|
|
@ -38,7 +38,7 @@ use League\OAuth2\Client\Token\AccessTokenInterface;
|
|||
class OAuthToken extends AbstractNamedDBElement implements AccessTokenInterface
|
||||
{
|
||||
/** @var string|null The short-term usable OAuth2 token */
|
||||
#[ORM\Column(type: 'text', nullable: true)]
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
private ?string $token = null;
|
||||
|
||||
/** @var \DateTimeImmutable|null The date when the token expires */
|
||||
|
@ -46,7 +46,7 @@ class OAuthToken extends AbstractNamedDBElement implements AccessTokenInterface
|
|||
private ?\DateTimeImmutable $expires_at = null;
|
||||
|
||||
/** @var string|null The refresh token for the OAuth2 auth */
|
||||
#[ORM\Column(type: 'text', nullable: true)]
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
private ?string $refresh_token = null;
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
|
@ -91,7 +92,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
class Category extends AbstractPartsContainingDBElement
|
||||
{
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
|
||||
|
@ -165,7 +166,7 @@ class Category extends AbstractPartsContainingDBElement
|
|||
#[Assert\Valid]
|
||||
#[Groups(['full', 'category:read', 'category:write'])]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: CategoryAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $attachments;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: CategoryAttachment::class)]
|
||||
|
@ -178,7 +179,7 @@ class Category extends AbstractPartsContainingDBElement
|
|||
#[Assert\Valid]
|
||||
#[Groups(['full', 'category:read', 'category:write'])]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: CategoryParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
#[Groups(['category:read'])]
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
|
@ -96,7 +97,7 @@ class Footprint extends AbstractPartsContainingDBElement
|
|||
protected ?AbstractStructuralDBElement $parent = null;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
#[Groups(['footprint:read', 'footprint:write'])]
|
||||
|
@ -107,7 +108,7 @@ class Footprint extends AbstractPartsContainingDBElement
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: FootprintAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
#[Groups(['footprint:read', 'footprint:write'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
|
@ -128,7 +129,7 @@ class Footprint extends AbstractPartsContainingDBElement
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: FootprintParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
#[Groups(['footprint:read', 'footprint:write'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
|
|
|
@ -31,25 +31,26 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
|||
|
||||
/**
|
||||
* This class represents a reference to a info provider inside a part.
|
||||
* @see \App\Tests\Entity\Parts\InfoProviderReferenceTest
|
||||
*/
|
||||
#[Embeddable]
|
||||
class InfoProviderReference
|
||||
{
|
||||
|
||||
/** @var string|null The key referencing the provider used to get this part, or null if it was not provided by a data provider */
|
||||
#[Column(type: 'string', nullable: true)]
|
||||
#[Column(type: Types::STRING, nullable: true)]
|
||||
#[Groups(['provider_reference:read'])]
|
||||
private ?string $provider_key = null;
|
||||
|
||||
/** @var string|null The id of this part inside the provider system or null if the part was not provided by a data provider */
|
||||
#[Column(type: 'string', nullable: true)]
|
||||
#[Column(type: Types::STRING, nullable: true)]
|
||||
#[Groups(['provider_reference:read'])]
|
||||
private ?string $provider_id = null;
|
||||
|
||||
/**
|
||||
* @var string|null The url of this part inside the provider system or null if this info is not existing
|
||||
*/
|
||||
#[Column(type: 'string', nullable: true)]
|
||||
#[Column(type: Types::STRING, nullable: true)]
|
||||
#[Groups(['provider_reference:read'])]
|
||||
private ?string $provider_url = null;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
|
@ -95,7 +96,7 @@ class Manufacturer extends AbstractCompany
|
|||
protected ?AbstractStructuralDBElement $parent = null;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
/**
|
||||
|
@ -103,7 +104,7 @@ class Manufacturer extends AbstractCompany
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: ManufacturerAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
#[Groups(['manufacturer:read', 'manufacturer:write'])]
|
||||
#[ApiProperty(readableLink: false, writableLink: true)]
|
||||
protected Collection $attachments;
|
||||
|
@ -118,7 +119,7 @@ class Manufacturer extends AbstractCompany
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: ManufacturerParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
#[Groups(['manufacturer:read', 'manufacturer:write'])]
|
||||
#[ApiProperty(readableLink: false, writableLink: true)]
|
||||
protected Collection $parameters;
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
|
@ -123,7 +124,7 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
|
|||
protected bool $use_si_prefix = false;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class, cascade: ['persist'])]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
|
||||
|
@ -137,7 +138,7 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: MeasurementUnitAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
#[Groups(['measurement_unit:read', 'measurement_unit:write'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
|
@ -150,7 +151,7 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: MeasurementUnitParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
#[Groups(['measurement_unit:read', 'measurement_unit:write'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
|
@ -119,7 +120,7 @@ class Part extends AttachmentContainingDBElement
|
|||
#[Assert\Valid]
|
||||
#[Groups(['full', 'part:read', 'part:write'])]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: PartParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
#[UniqueObjectCollection(fields: ['name', 'group', 'element'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
|
@ -140,7 +141,7 @@ class Part extends AttachmentContainingDBElement
|
|||
#[Assert\Valid]
|
||||
#[Groups(['full', 'part:read', 'part:write'])]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: PartAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $attachments;
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,6 +49,7 @@ use Symfony\Component\Validator\Constraints\Length;
|
|||
/**
|
||||
* This entity describes a part association, which is a semantic connection between two parts.
|
||||
* For example, a part association can be used to describe that a part is a replacement for another part.
|
||||
* @see \App\Tests\Entity\Parts\PartAssociationTest
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: DBElementRepository::class)]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
|
|
|
@ -105,7 +105,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
|
|||
protected string $comment = '';
|
||||
|
||||
/**
|
||||
* @var \DateTime|null Set a time until when the lot must be used.
|
||||
* @var \DateTimeInterface|null Set a time until when the lot must be used.
|
||||
* Set to null, if the lot can be used indefinitely.
|
||||
*/
|
||||
#[Groups(['extended', 'full', 'import', 'part_lot:read', 'part_lot:write'])]
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts\PartTraits;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use App\Entity\Parts\MeasurementUnit;
|
||||
use App\Entity\Parts\PartLot;
|
||||
|
@ -42,7 +43,7 @@ trait InstockTrait
|
|||
#[Assert\Valid]
|
||||
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
|
||||
#[ORM\OneToMany(mappedBy: 'part', targetEntity: PartLot::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['amount' => 'DESC'])]
|
||||
#[ORM\OrderBy(['amount' => Criteria::DESC])]
|
||||
protected Collection $partLots;
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts\PartTraits;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use App\Entity\PriceInformations\Orderdetail;
|
||||
use Symfony\Component\Serializer\Annotation\Groups;
|
||||
|
@ -41,7 +42,7 @@ trait OrderTrait
|
|||
#[Assert\Valid]
|
||||
#[Groups(['extended', 'full', 'import', 'part:read', 'part:write'])]
|
||||
#[ORM\OneToMany(mappedBy: 'part', targetEntity: Orderdetail::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['supplierpartnr' => 'ASC'])]
|
||||
#[ORM\OrderBy(['supplierpartnr' => Criteria::ASC])]
|
||||
protected Collection $orderdetails;
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
|
@ -90,7 +91,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
class StorageLocation extends AbstractPartsContainingDBElement
|
||||
{
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
|
||||
|
@ -114,7 +115,7 @@ class StorageLocation extends AbstractPartsContainingDBElement
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: StorageLocationParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
#[Groups(['location:read', 'location:write'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\Parts;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
|
@ -92,7 +93,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
class Supplier extends AbstractCompany
|
||||
{
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
|
||||
|
@ -129,7 +130,7 @@ class Supplier extends AbstractCompany
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: SupplierAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
#[Groups(['supplier:read', 'supplier:write'])]
|
||||
#[ApiProperty(readableLink: false, writableLink: true)]
|
||||
protected Collection $attachments;
|
||||
|
@ -144,7 +145,7 @@ class Supplier extends AbstractCompany
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: SupplierParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
#[Groups(['supplier:read', 'supplier:write'])]
|
||||
#[ApiProperty(readableLink: false, writableLink: true)]
|
||||
protected Collection $parameters;
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\PriceInformations;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
|
@ -118,7 +119,7 @@ class Currency extends AbstractStructuralDBElement
|
|||
protected string $iso_code = "";
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class, cascade: ['persist'])]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
|
||||
|
@ -132,7 +133,7 @@ class Currency extends AbstractStructuralDBElement
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: CurrencyAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
#[Groups(['currency:read', 'currency:write'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
|
@ -145,7 +146,7 @@ class Currency extends AbstractStructuralDBElement
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: CurrencyParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
#[Groups(['currency:read', 'currency:write'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\PriceInformations;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
|
@ -96,10 +97,13 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
|
|||
{
|
||||
use TimestampTrait;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Pricedetail>
|
||||
*/
|
||||
#[Assert\Valid]
|
||||
#[Groups(['extended', 'full', 'import', 'orderdetail:read', 'orderdetail:write'])]
|
||||
#[ORM\OneToMany(mappedBy: 'orderdetail', targetEntity: Pricedetail::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['min_discount_quantity' => 'ASC'])]
|
||||
#[ORM\OrderBy(['min_discount_quantity' => Criteria::ASC])]
|
||||
protected Collection $pricedetails;
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\ProjectSystem;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
use ApiPlatform\Metadata\ApiFilter;
|
||||
use ApiPlatform\Metadata\ApiProperty;
|
||||
|
@ -88,7 +89,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|||
class Project extends AbstractStructuralDBElement
|
||||
{
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
|
||||
|
@ -100,6 +101,9 @@ class Project extends AbstractStructuralDBElement
|
|||
#[Groups(['project:read', 'project:write'])]
|
||||
protected string $comment = '';
|
||||
|
||||
/**
|
||||
* @var Collection<int, ProjectBOMEntry>
|
||||
*/
|
||||
#[Assert\Valid]
|
||||
#[Groups(['extended', 'full'])]
|
||||
#[ORM\OneToMany(mappedBy: 'project', targetEntity: ProjectBOMEntry::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
|
@ -137,7 +141,7 @@ class Project extends AbstractStructuralDBElement
|
|||
* @var Collection<int, ProjectAttachment>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: ProjectAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
#[Groups(['project:read', 'project:write'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
|
@ -149,7 +153,7 @@ class Project extends AbstractStructuralDBElement
|
|||
/** @var Collection<int, ProjectParameter>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: ProjectParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
#[Groups(['project:read', 'project:write'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\UserSystem;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Validator\Constraints\NoLockout;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
|
@ -49,7 +50,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
|||
class Group extends AbstractStructuralDBElement implements HasPermissionsInterface
|
||||
{
|
||||
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $children;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
|
||||
|
@ -74,7 +75,7 @@ class Group extends AbstractStructuralDBElement implements HasPermissionsInterfa
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: GroupAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
protected Collection $attachments;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: GroupAttachment::class)]
|
||||
|
@ -91,7 +92,7 @@ class Group extends AbstractStructuralDBElement implements HasPermissionsInterfa
|
|||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: GroupParameter::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['group' => Criteria::ASC, 'name' => 'ASC'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
public function __construct()
|
||||
|
|
|
@ -22,6 +22,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Entity\UserSystem;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use ApiPlatform\Doctrine\Common\Filter\DateFilterInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
|
||||
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
|
||||
|
@ -267,7 +268,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
* @var Collection<int, UserAttachment>
|
||||
*/
|
||||
#[ORM\OneToMany(mappedBy: 'element', targetEntity: UserAttachment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
#[ORM\OrderBy(['name' => Criteria::ASC])]
|
||||
#[Groups(['user:read', 'user:write'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
|
@ -317,7 +318,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
protected ?PermissionData $permissions = null;
|
||||
|
||||
/**
|
||||
* @var \DateTime|null the time until the password reset token is valid
|
||||
* @var \DateTimeInterface|null the time until the password reset token is valid
|
||||
*/
|
||||
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
|
||||
protected ?\DateTime $pw_reset_expires = null;
|
||||
|
|
|
@ -142,7 +142,7 @@ class AttachmentFormType extends AbstractType
|
|||
|
||||
if (!$file instanceof UploadedFile) {
|
||||
//When no file was uploaded, but a URL was entered, try to determine the attachment name from the URL
|
||||
if (empty($attachment->getName()) && !empty($attachment->getURL())) {
|
||||
if ((trim($attachment->getName()) === '') && ($attachment->getURL() !== null && $attachment->getURL() !== '')) {
|
||||
$name = basename(parse_url($attachment->getURL(), PHP_URL_PATH));
|
||||
$attachment->setName($name);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
|
|
|
@ -45,9 +45,7 @@ class PermissionsType extends AbstractType
|
|||
$resolver->setDefaults([
|
||||
'show_legend' => true,
|
||||
'show_presets' => false,
|
||||
'show_dependency_notice' => static function (Options $options) {
|
||||
return !$options['disabled'];
|
||||
},
|
||||
'show_dependency_notice' => static fn(Options $options) => !$options['disabled'],
|
||||
'constraints' => static function (Options $options) {
|
||||
if (!$options['disabled']) {
|
||||
return [new NoLockout()];
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Form\ProjectSystem;
|
||||
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
|
|
|
@ -100,7 +100,7 @@ class StructuralEntityChoiceHelper
|
|||
public function generateChoiceAttrCurrency(Currency $choice, Options|array $options): array
|
||||
{
|
||||
$tmp = $this->generateChoiceAttr($choice, $options);
|
||||
$symbol = empty($choice->getIsoCode()) ? null : Currencies::getSymbol($choice->getIsoCode());
|
||||
$symbol = $choice->getIsoCode() === '' ? null : Currencies::getSymbol($choice->getIsoCode());
|
||||
$tmp['data-short'] = $options['short'] ? $symbol : $choice->getName();
|
||||
|
||||
//Show entities that are not added to DB yet separately from other entities
|
||||
|
|
|
@ -52,11 +52,7 @@ class StructuralEntityChoiceLoader extends AbstractChoiceLoader
|
|||
protected function loadChoices(): iterable
|
||||
{
|
||||
//If the starting_element is set and not persisted yet, add it to the list
|
||||
if ($this->starting_element !== null && $this->starting_element->getID() === null) {
|
||||
$tmp = [$this->starting_element];
|
||||
} else {
|
||||
$tmp = [];
|
||||
}
|
||||
$tmp = $this->starting_element !== null && $this->starting_element->getID() === null ? [$this->starting_element] : [];
|
||||
|
||||
if ($this->additional_element) {
|
||||
$tmp = $this->createNewEntitiesFromValue($this->additional_element);
|
||||
|
@ -163,7 +159,7 @@ class StructuralEntityChoiceLoader extends AbstractChoiceLoader
|
|||
// the same as the value that is generated for the same entity after it is persisted.
|
||||
// Otherwise, errors occurs that the element could not be found.
|
||||
foreach ($values as &$data) {
|
||||
$data = trim($data);
|
||||
$data = trim((string) $data);
|
||||
$data = preg_replace('/\s*->\s*/', '->', $data);
|
||||
}
|
||||
unset ($data);
|
||||
|
|
|
@ -108,12 +108,8 @@ class StructuralEntityType extends AbstractType
|
|||
$resolver->setDefault('dto_value', null);
|
||||
$resolver->setAllowedTypes('dto_value', ['null', 'string']);
|
||||
//If no help text is explicitly set, we use the dto value as help text and show it as html
|
||||
$resolver->setDefault('help', function (Options $options) {
|
||||
return $this->dtoText($options['dto_value']);
|
||||
});
|
||||
$resolver->setDefault('help_html', function (Options $options) {
|
||||
return $options['dto_value'] !== null;
|
||||
});
|
||||
$resolver->setDefault('help', fn(Options $options) => $this->dtoText($options['dto_value']));
|
||||
$resolver->setDefault('help_html', fn(Options $options) => $options['dto_value'] !== null);
|
||||
|
||||
$resolver->setDefault('attr', function (Options $options) {
|
||||
$tmp = [
|
||||
|
|
|
@ -47,9 +47,9 @@ class FilenameSanatizer
|
|||
'-', $filename);
|
||||
|
||||
// avoids ".", ".." or ".hiddenFiles"
|
||||
$filename = ltrim($filename, '.-');
|
||||
$filename = ltrim((string) $filename, '.-');
|
||||
//Limit filename length to 255 bytes
|
||||
$ext = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
return mb_strcut(pathinfo($filename, PATHINFO_FILENAME), 0, 255 - ($ext ? strlen($ext) + 1 : 0), mb_detect_encoding($filename)) . ($ext ? '.' . $ext : '');
|
||||
return mb_strcut(pathinfo($filename, PATHINFO_FILENAME), 0, 255 - ($ext !== '' && $ext !== '0' ? strlen($ext) + 1 : 0), mb_detect_encoding($filename)) . ($ext !== '' && $ext !== '0' ? '.' . $ext : '');
|
||||
}
|
||||
}
|
|
@ -174,11 +174,7 @@ final class ProjectBuildRequest
|
|||
*/
|
||||
public function getLotWithdrawAmount(PartLot|int $lot): float
|
||||
{
|
||||
if ($lot instanceof PartLot) {
|
||||
$lot_id = $lot->getID();
|
||||
} else { // Then it must be an int
|
||||
$lot_id = $lot;
|
||||
}
|
||||
$lot_id = $lot instanceof PartLot ? $lot->getID() : $lot;
|
||||
|
||||
if (! array_key_exists($lot_id, $this->withdraw_amounts)) {
|
||||
throw new \InvalidArgumentException('The given lot is not in the withdraw amounts array!');
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Helpers;
|
|||
/**
|
||||
* Helper functions for logic operations with trinary logic.
|
||||
* True and false are represented as classical boolean values, undefined is represented as null.
|
||||
* @see \App\Tests\Helpers\TrinaryLogicHelperTest
|
||||
*/
|
||||
class TrinaryLogicHelper
|
||||
{
|
||||
|
|
|
@ -64,7 +64,7 @@ trait WithPermPresetsTrait
|
|||
|
||||
public function setContainer(ContainerInterface $container = null): void
|
||||
{
|
||||
if ($container) {
|
||||
if ($container !== null) {
|
||||
$this->container = $container;
|
||||
$this->permission_presets_helper = $container->get(PermissionPresetsHelper::class);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ use Doctrine\ORM\Mapping\ClassMetadata;
|
|||
/**
|
||||
* @template TEntityClass of AttachmentContainingDBElement
|
||||
* @extends NamedDBElementRepository<TEntityClass>
|
||||
* @see \App\Tests\Repository\AttachmentContainingDBElementRepositoryTest
|
||||
*/
|
||||
class AttachmentContainingDBElementRepository extends NamedDBElementRepository
|
||||
{
|
||||
|
|
|
@ -49,6 +49,7 @@ use ReflectionClass;
|
|||
/**
|
||||
* @template TEntityClass of AbstractDBElement
|
||||
* @extends EntityRepository<TEntityClass>
|
||||
* @see \App\Tests\Repository\DBElementRepositoryTest
|
||||
*/
|
||||
class DBElementRepository extends EntityRepository
|
||||
{
|
||||
|
@ -143,9 +144,7 @@ class DBElementRepository extends EntityRepository
|
|||
*/
|
||||
protected function sortResultArrayByIDArray(array &$result_array, array $ids): void
|
||||
{
|
||||
usort($result_array, static function (AbstractDBElement $a, AbstractDBElement $b) use ($ids) {
|
||||
return array_search($a->getID(), $ids, true) <=> array_search($b->getID(), $ids, true);
|
||||
});
|
||||
usort($result_array, static fn(AbstractDBElement $a, AbstractDBElement $b) => array_search($a->getID(), $ids, true) <=> array_search($b->getID(), $ids, true));
|
||||
}
|
||||
|
||||
protected function setField(AbstractDBElement $element, string $field, int $new_value): void
|
||||
|
|
|
@ -29,6 +29,7 @@ use App\Helpers\Trees\TreeViewNode;
|
|||
/**
|
||||
* @template TEntityClass of AbstractNamedDBElement
|
||||
* @extends DBElementRepository<TEntityClass>
|
||||
* @see \App\Tests\Repository\NamedDBElementRepositoryTest
|
||||
*/
|
||||
class NamedDBElementRepository extends DBElementRepository
|
||||
{
|
||||
|
|
|
@ -52,7 +52,7 @@ class StructuralDBElementRepository extends AttachmentContainingDBElementReposit
|
|||
$qb->select('e')
|
||||
->orderBy('NATSORT(e.name)', $nameOrdering);
|
||||
|
||||
if ($parent) {
|
||||
if ($parent !== null) {
|
||||
$qb->where('e.parent = :parent')
|
||||
->setParameter('parent', $parent);
|
||||
} else {
|
||||
|
@ -260,7 +260,7 @@ class StructuralDBElementRepository extends AttachmentContainingDBElementReposit
|
|||
|
||||
//Try to find if we already have an element cached for this name
|
||||
$entity = $this->getNewEntityFromCache($name, null);
|
||||
if ($entity) {
|
||||
if ($entity !== null) {
|
||||
return $entity;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
|||
* @method User[] findAll()
|
||||
* @method User[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
* @extends NamedDBElementRepository<User>
|
||||
* @see \App\Tests\Repository\UserRepositoryTest
|
||||
*/
|
||||
final class UserRepository extends NamedDBElementRepository implements PasswordUpgraderInterface
|
||||
{
|
||||
|
|
|
@ -44,12 +44,12 @@ class WebauthnKeyLastUseTwoFactorProvider implements TwoFactorProviderInterface
|
|||
|
||||
public function __construct(
|
||||
#[AutowireDecorated]
|
||||
private TwoFactorProviderInterface $decorated,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private readonly TwoFactorProviderInterface $decorated,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
#[Autowire(service: 'jbtronics_webauthn_tfa.user_public_key_source_repo')]
|
||||
private UserPublicKeyCredentialSourceRepository $publicKeyCredentialSourceRepository,
|
||||
private readonly UserPublicKeyCredentialSourceRepository $publicKeyCredentialSourceRepository,
|
||||
#[Autowire(service: 'jbtronics_webauthn_tfa.webauthn_provider')]
|
||||
private WebauthnProvider $webauthnProvider,
|
||||
private readonly WebauthnProvider $webauthnProvider,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Serializer\APIPlatform;
|
||||
|
||||
use ApiPlatform\Metadata\Exception\ResourceClassNotFoundException;
|
||||
use ApiPlatform\Api\IriConverterInterface;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\Metadata\Post;
|
||||
|
@ -59,7 +60,7 @@ class DetermineTypeFromElementIRIDenormalizer implements DenormalizerInterface,
|
|||
* @param array $input
|
||||
* @param Operation $operation
|
||||
* @return array
|
||||
* @throws \ApiPlatform\Metadata\Exception\ResourceClassNotFoundException
|
||||
* @throws ResourceClassNotFoundException
|
||||
*/
|
||||
private function addTypeDiscriminatorIfNecessary(array $input, Operation $operation): array
|
||||
{
|
||||
|
|
|
@ -161,7 +161,7 @@ class PartNormalizer implements NormalizerInterface, DenormalizerInterface, Norm
|
|||
if (isset($data['supplier']) && $data['supplier'] !== "") {
|
||||
$supplier = $this->locationDenormalizer->denormalize($data['supplier'], Supplier::class, $format, $context);
|
||||
|
||||
if ($supplier) {
|
||||
if ($supplier !== null) {
|
||||
$orderdetail = new Orderdetail();
|
||||
$orderdetail->setSupplier($supplier);
|
||||
|
||||
|
|
|
@ -139,12 +139,12 @@ class AttachmentPathResolver
|
|||
}
|
||||
|
||||
//If we have now have a placeholder left, the string is invalid:
|
||||
if (preg_match('#%\w+%#', $placeholder_path)) {
|
||||
if (preg_match('#%\w+%#', (string) $placeholder_path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Path is invalid if path is directory traversal
|
||||
if (str_contains($placeholder_path, '..')) {
|
||||
if (str_contains((string) $placeholder_path, '..')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ class AttachmentPathResolver
|
|||
}
|
||||
|
||||
//If the new string does not begin with a placeholder, it is invalid
|
||||
if (!preg_match('#^%\w+%#', $real_path)) {
|
||||
if (!preg_match('#^%\w+%#', (string) $real_path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -300,7 +300,7 @@ class AttachmentSubmitHandler
|
|||
return $attachment;
|
||||
}
|
||||
|
||||
$filename = basename($old_path);
|
||||
$filename = basename((string) $old_path);
|
||||
//If the basename is not one of the new unique on, we have to save the old filename
|
||||
if (!preg_match('#\w+-\w{13}\.#', $filename)) {
|
||||
//Save filename to attachment field
|
||||
|
@ -378,7 +378,7 @@ class AttachmentSubmitHandler
|
|||
|
||||
//If we don't know filename yet, try to determine it out of url
|
||||
if ('' === $filename) {
|
||||
$filename = basename(parse_url($url, PHP_URL_PATH));
|
||||
$filename = basename(parse_url((string) $url, PHP_URL_PATH));
|
||||
}
|
||||
|
||||
//Set original file
|
||||
|
|
|
@ -46,11 +46,10 @@ class ElementCacheTagGenerator
|
|||
{
|
||||
//Ensure that the given element is a class name
|
||||
if (is_object($element)) {
|
||||
$element = get_class($element);
|
||||
} else { //And that the class exists
|
||||
if (!class_exists($element)) {
|
||||
throw new \InvalidArgumentException("The given class '$element' does not exist!");
|
||||
}
|
||||
$element = $element::class;
|
||||
} elseif (!class_exists($element)) {
|
||||
//And that the class exists
|
||||
throw new \InvalidArgumentException("The given class '$element' does not exist!");
|
||||
}
|
||||
|
||||
//Check if the tag is already cached
|
||||
|
|
|
@ -134,7 +134,7 @@ class KiCadHelper
|
|||
|
||||
if ($this->category_depth >= 0) {
|
||||
//Ensure that the category is set
|
||||
if (!$category) {
|
||||
if ($category === null) {
|
||||
throw new NotFoundHttpException('Category must be set, if category_depth is greater than 1!');
|
||||
}
|
||||
|
||||
|
@ -196,25 +196,25 @@ class KiCadHelper
|
|||
|
||||
//Add basic fields
|
||||
$result["fields"]["description"] = $this->createField($part->getDescription());
|
||||
if ($part->getCategory()) {
|
||||
if ($part->getCategory() !== null) {
|
||||
$result["fields"]["Category"] = $this->createField($part->getCategory()->getFullPath('/'));
|
||||
}
|
||||
if ($part->getManufacturer()) {
|
||||
if ($part->getManufacturer() !== null) {
|
||||
$result["fields"]["Manufacturer"] = $this->createField($part->getManufacturer()->getName());
|
||||
}
|
||||
if ($part->getManufacturerProductNumber() !== "") {
|
||||
$result['fields']["MPN"] = $this->createField($part->getManufacturerProductNumber());
|
||||
}
|
||||
if ($part->getManufacturingStatus()) {
|
||||
if ($part->getManufacturingStatus() !== null) {
|
||||
$result["fields"]["Manufacturing Status"] = $this->createField(
|
||||
//Always use the english translation
|
||||
$this->translator->trans($part->getManufacturingStatus()->toTranslationKey(), locale: 'en')
|
||||
);
|
||||
}
|
||||
if ($part->getFootprint()) {
|
||||
if ($part->getFootprint() !== null) {
|
||||
$result["fields"]["Part-DB Footprint"] = $this->createField($part->getFootprint()->getName());
|
||||
}
|
||||
if ($part->getPartUnit()) {
|
||||
if ($part->getPartUnit() !== null) {
|
||||
$unit = $part->getPartUnit()->getName();
|
||||
if ($part->getPartUnit()->getUnit() !== "") {
|
||||
$unit .= ' ('.$part->getPartUnit()->getUnit().')';
|
||||
|
@ -225,7 +225,7 @@ class KiCadHelper
|
|||
$result["fields"]["Mass"] = $this->createField($part->getMass() . ' g');
|
||||
}
|
||||
$result["fields"]["Part-DB ID"] = $this->createField($part->getId());
|
||||
if (!empty($part->getIpn())) {
|
||||
if ($part->getIpn() !== null && $part->getIpn() !== '' && $part->getIpn() !== '0') {
|
||||
$result["fields"]["Part-DB IPN"] = $this->createField($part->getIpn());
|
||||
}
|
||||
|
||||
|
@ -308,14 +308,9 @@ class KiCadHelper
|
|||
)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//And on the footprint
|
||||
if ($part->getFootprint() && $part->getFootprint()->getEdaInfo()->getKicadFootprint() !== null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Otherwise the part should be not visible
|
||||
return false;
|
||||
return $part->getFootprint() && $part->getFootprint()->getEdaInfo()->getKicadFootprint() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -69,7 +69,7 @@ class EntityMerger
|
|||
{
|
||||
$merger = $this->findMergerForObject($target, $other, $context);
|
||||
if ($merger === null) {
|
||||
throw new \RuntimeException('No merger found for merging '.get_class($other).' into '.get_class($target));
|
||||
throw new \RuntimeException('No merger found for merging '.$other::class.' into '.$target::class);
|
||||
}
|
||||
return $merger->merge($target, $other, $context);
|
||||
}
|
||||
|
|
|
@ -85,9 +85,7 @@ trait EntityMergerHelperTrait
|
|||
protected function useOtherValueIfNotNull(object $target, object $other, string $field): object
|
||||
{
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return $target_value ?? $other_value;
|
||||
},
|
||||
fn($target_value, $other_value) => $target_value ?? $other_value,
|
||||
$target,
|
||||
$other,
|
||||
$field
|
||||
|
@ -106,9 +104,7 @@ trait EntityMergerHelperTrait
|
|||
protected function useOtherValueIfNotEmtpy(object $target, object $other, string $field): object
|
||||
{
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return empty($target_value) ? $other_value : $target_value;
|
||||
},
|
||||
fn($target_value, $other_value) => empty($target_value) ? $other_value : $target_value,
|
||||
$target,
|
||||
$other,
|
||||
$field
|
||||
|
@ -126,9 +122,7 @@ trait EntityMergerHelperTrait
|
|||
protected function useLargerValue(object $target, object $other, string $field): object
|
||||
{
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return max($target_value, $other_value);
|
||||
},
|
||||
fn($target_value, $other_value) => max($target_value, $other_value),
|
||||
$target,
|
||||
$other,
|
||||
$field
|
||||
|
@ -146,9 +140,7 @@ trait EntityMergerHelperTrait
|
|||
protected function useSmallerValue(object $target, object $other, string $field): object
|
||||
{
|
||||
return $this->useCallback(
|
||||
function ($target_value, $other_value) {
|
||||
return min($target_value, $other_value);
|
||||
},
|
||||
fn($target_value, $other_value) => min($target_value, $other_value),
|
||||
$target,
|
||||
$other,
|
||||
$field
|
||||
|
@ -166,9 +158,7 @@ trait EntityMergerHelperTrait
|
|||
protected function useTrueValue(object $target, object $other, string $field): object
|
||||
{
|
||||
return $this->useCallback(
|
||||
function (bool $target_value, bool $other_value): bool {
|
||||
return $target_value || $other_value;
|
||||
},
|
||||
fn(bool $target_value, bool $other_value): bool => $target_value || $other_value,
|
||||
$target,
|
||||
$other,
|
||||
$field
|
||||
|
@ -232,10 +222,8 @@ trait EntityMergerHelperTrait
|
|||
continue 2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($target_collection->contains($item)) {
|
||||
continue;
|
||||
}
|
||||
} elseif ($target_collection->contains($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$clones[] = clone $item;
|
||||
|
@ -257,11 +245,9 @@ trait EntityMergerHelperTrait
|
|||
*/
|
||||
protected function mergeAttachments(AttachmentContainingDBElement $target, AttachmentContainingDBElement $other): object
|
||||
{
|
||||
return $this->mergeCollections($target, $other, 'attachments', function (Attachment $t, Attachment $o): bool {
|
||||
return $t->getName() === $o->getName()
|
||||
&& $t->getAttachmentType() === $o->getAttachmentType()
|
||||
&& $t->getPath() === $o->getPath();
|
||||
});
|
||||
return $this->mergeCollections($target, $other, 'attachments', fn(Attachment $t, Attachment $o): bool => $t->getName() === $o->getName()
|
||||
&& $t->getAttachmentType() === $o->getAttachmentType()
|
||||
&& $t->getPath() === $o->getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -272,16 +258,14 @@ trait EntityMergerHelperTrait
|
|||
*/
|
||||
protected function mergeParameters(AbstractStructuralDBElement|Part $target, AbstractStructuralDBElement|Part $other): object
|
||||
{
|
||||
return $this->mergeCollections($target, $other, 'parameters', function (AbstractParameter $t, AbstractParameter $o): bool {
|
||||
return $t->getName() === $o->getName()
|
||||
&& $t->getSymbol() === $o->getSymbol()
|
||||
&& $t->getUnit() === $o->getUnit()
|
||||
&& $t->getValueMax() === $o->getValueMax()
|
||||
&& $t->getValueMin() === $o->getValueMin()
|
||||
&& $t->getValueTypical() === $o->getValueTypical()
|
||||
&& $t->getValueText() === $o->getValueText()
|
||||
&& $t->getGroup() === $o->getGroup();
|
||||
});
|
||||
return $this->mergeCollections($target, $other, 'parameters', fn(AbstractParameter $t, AbstractParameter $o): bool => $t->getName() === $o->getName()
|
||||
&& $t->getSymbol() === $o->getSymbol()
|
||||
&& $t->getUnit() === $o->getUnit()
|
||||
&& $t->getValueMax() === $o->getValueMax()
|
||||
&& $t->getValueMin() === $o->getValueMin()
|
||||
&& $t->getValueTypical() === $o->getValueTypical()
|
||||
&& $t->getValueText() === $o->getValueText()
|
||||
&& $t->getGroup() === $o->getGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,6 +33,7 @@ use App\Entity\PriceInformations\Orderdetail;
|
|||
* This class merges two parts together.
|
||||
*
|
||||
* @implements EntityMergerInterface<Part>
|
||||
* @see \App\Tests\Services\EntityMergers\Mergers\PartMergerTest
|
||||
*/
|
||||
class PartMerger implements EntityMergerInterface
|
||||
{
|
||||
|
@ -99,7 +100,7 @@ class PartMerger implements EntityMergerInterface
|
|||
return $target;
|
||||
}
|
||||
|
||||
private static function comparePartAssociations(PartAssociation $t, PartAssociation $o): bool {
|
||||
private function comparePartAssociations(PartAssociation $t, PartAssociation $o): bool {
|
||||
//We compare the translation keys, as it contains info about the type and other type info
|
||||
return $t->getOther() === $o->getOther()
|
||||
&& $t->getTypeTranslationKey() === $o->getTypeTranslationKey();
|
||||
|
@ -117,7 +118,7 @@ class PartMerger implements EntityMergerInterface
|
|||
$this->mergeParameters($target, $other);
|
||||
|
||||
//Merge the associations
|
||||
$this->mergeCollections($target, $other, 'associated_parts_as_owner', self::comparePartAssociations(...));
|
||||
$this->mergeCollections($target, $other, 'associated_parts_as_owner', $this->comparePartAssociations(...));
|
||||
|
||||
//We have to recreate the associations towards the other part, as they are not created by the merger
|
||||
foreach ($other->getAssociatedPartsAsOther() as $association) {
|
||||
|
@ -131,7 +132,7 @@ class PartMerger implements EntityMergerInterface
|
|||
}
|
||||
//Ensure that the association is not already present
|
||||
foreach ($owner->getAssociatedPartsAsOwner() as $existing_association) {
|
||||
if (self::comparePartAssociations($existing_association, $clone)) {
|
||||
if ($this->comparePartAssociations($existing_association, $clone)) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -360,11 +360,7 @@ class EntityURLGenerator
|
|||
*/
|
||||
protected function mapToController(array $map, string|AbstractDBElement $entity): string
|
||||
{
|
||||
if (is_string($entity)) { //If a class name was already passed, then use it directly
|
||||
$class = $entity;
|
||||
} else { //Otherwise get the class name from the entity
|
||||
$class = $entity::class;
|
||||
}
|
||||
$class = is_string($entity) ? $entity : $entity::class;
|
||||
|
||||
//Check if we have an direct mapping for the given class
|
||||
if (!array_key_exists($class, $map)) {
|
||||
|
|
|
@ -116,7 +116,7 @@ class PKOptionalImporter
|
|||
//All imported users get assigned to the "PartKeepr Users" group
|
||||
$group_users = $this->em->find(Group::class, 3);
|
||||
$group = $this->em->getRepository(Group::class)->findOneBy(['name' => 'PartKeepr Users', 'parent' => $group_users]);
|
||||
if (!$group) {
|
||||
if ($group === null) {
|
||||
$group = new Group();
|
||||
$group->setName('PartKeepr Users');
|
||||
$group->setParent($group_users);
|
||||
|
|
|
@ -218,7 +218,7 @@ class PKPartImporter
|
|||
'iso_code' => $currency_iso_code,
|
||||
]);
|
||||
|
||||
if (!$currency) {
|
||||
if ($currency === null) {
|
||||
$currency = new Currency();
|
||||
$currency->setIsoCode($currency_iso_code);
|
||||
$currency->setName(Currencies::getName($currency_iso_code));
|
||||
|
@ -265,7 +265,7 @@ class PKPartImporter
|
|||
]);
|
||||
|
||||
//When no orderdetail exists, create one
|
||||
if (!$orderdetail) {
|
||||
if ($orderdetail === null) {
|
||||
$orderdetail = new Orderdetail();
|
||||
$orderdetail->setSupplier($supplier);
|
||||
$orderdetail->setSupplierpartnr($spn);
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -28,6 +28,7 @@ use Com\Tecnick\Barcode\Barcode;
|
|||
|
||||
/**
|
||||
* This function is used to generate barcodes of various types using arbitrary (text) content.
|
||||
* @see \App\Tests\Services\LabelSystem\Barcodes\BarcodeHelperTest
|
||||
*/
|
||||
class BarcodeHelper
|
||||
{
|
||||
|
@ -66,7 +67,7 @@ class BarcodeHelper
|
|||
{
|
||||
$svg = $this->barcodeAsSVG($content, $type);
|
||||
$base64 = $this->dataUri($svg, 'image/svg+xml');
|
||||
$alt_text = $alt_text ?? $content;
|
||||
$alt_text ??= $content;
|
||||
|
||||
return '<img src="'.$base64.'" width="'.$width.'" style="min-height: 25px;" alt="'.$alt_text.'"/>';
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\Barcodes\BarcodeNormalizerTest
|
||||
* @see \App\Tests\Services\LabelSystem\Barcodes\BarcodeScanHelperTest
|
||||
*/
|
||||
final class BarcodeScanHelper
|
||||
{
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
|
@ -17,7 +20,6 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Services\LabelSystem;
|
||||
|
||||
use Dompdf\Dompdf;
|
||||
|
@ -36,10 +38,8 @@ class DompdfFactory implements DompdfFactoryInterface
|
|||
|
||||
private function createDirectoryIfNotExisting(string $path): void
|
||||
{
|
||||
if (!is_dir($path)) {
|
||||
if (!mkdir($concurrentDirectory = $path, 0777, true) && !is_dir($concurrentDirectory)) {
|
||||
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
|
||||
}
|
||||
if (!is_dir($path) && (!mkdir($concurrentDirectory = $path, 0777, true) && !is_dir($concurrentDirectory))) {
|
||||
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ use App\Services\LabelSystem\Barcodes\BarcodeHelper;
|
|||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* @see \App\Tests\Services\LabelSystem\BarcodeGeneratorTest
|
||||
* @see \App\Tests\Services\LabelSystem\LabelBarcodeGeneratorTest
|
||||
*/
|
||||
final class LabelBarcodeGenerator
|
||||
{
|
||||
|
|
|
@ -119,7 +119,7 @@ final class PartProvider implements PlaceholderProviderInterface
|
|||
}
|
||||
|
||||
if ('[[DESCRIPTION_T]]' === $placeholder) {
|
||||
return strip_tags($parsedown->line($part->getDescription()));
|
||||
return strip_tags((string) $parsedown->line($part->getDescription()));
|
||||
}
|
||||
|
||||
if ('[[COMMENT]]' === $placeholder) {
|
||||
|
@ -127,7 +127,7 @@ final class PartProvider implements PlaceholderProviderInterface
|
|||
}
|
||||
|
||||
if ('[[COMMENT_T]]' === $placeholder) {
|
||||
return strip_tags($parsedown->line($part->getComment()));
|
||||
return strip_tags((string) $parsedown->line($part->getComment()));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -52,7 +52,7 @@ final class StructuralDBElementProvider implements PlaceholderProviderInterface
|
|||
return $label_target->getComment();
|
||||
}
|
||||
if ('[[COMMENT_T]]' === $placeholder) {
|
||||
return strip_tags($label_target->getComment());
|
||||
return strip_tags((string) $label_target->getComment());
|
||||
}
|
||||
if ('[[FULL_PATH]]' === $placeholder) {
|
||||
return $label_target->getFullPath();
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue