Fixed coding style.

This commit is contained in:
Jan Böhmer 2020-05-10 21:39:31 +02:00
parent e9493e52ec
commit f5d685dfd4
71 changed files with 619 additions and 531 deletions

View file

@ -46,7 +46,6 @@ use App\DataTables\LogDataTable;
use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use App\Entity\Parts\PartLot;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use App\Events\SecurityEvent; use App\Events\SecurityEvent;
use App\Events\SecurityEvents; use App\Events\SecurityEvents;
@ -94,7 +93,9 @@ abstract class BaseAdminController extends AbstractController
protected $historyHelper; protected $historyHelper;
protected $timeTravel; protected $timeTravel;
protected $dataTableFactory; protected $dataTableFactory;
/** @var EventDispatcher */ /**
* @var EventDispatcher
*/
protected $eventDispatcher; protected $eventDispatcher;
protected $labelGenerator; protected $labelGenerator;
protected $barcodeExampleGenerator; protected $barcodeExampleGenerator;
@ -165,7 +166,7 @@ abstract class BaseAdminController extends AbstractController
$table = null; $table = null;
} }
$form_options = [ $form_options = [
'attachment_class' => $this->attachment_class, 'attachment_class' => $this->attachment_class,
'parameter_class' => $this->parameter_class, 'parameter_class' => $this->parameter_class,
'disabled' => null !== $timeTravel_timestamp ? true : false, 'disabled' => null !== $timeTravel_timestamp ? true : false,
@ -174,8 +175,8 @@ abstract class BaseAdminController extends AbstractController
//Disable editing of options, if user is not allowed to use twig... //Disable editing of options, if user is not allowed to use twig...
if ( if (
$entity instanceof LabelProfile $entity instanceof LabelProfile
&& $entity->getOptions()->getLinesMode() === 'twig' && 'twig' === $entity->getOptions()->getLinesMode()
&& !$this->isGranted('@labels.use_twig') && ! $this->isGranted('@labels.use_twig')
) { ) {
$form_options['disable_options'] = true; $form_options['disable_options'] = true;
} }

View file

@ -43,12 +43,8 @@ declare(strict_types=1);
namespace App\Controller\AdminPages; namespace App\Controller\AdminPages;
use App\Entity\Attachments\AttachmentType; use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Entity\Attachments\LabelAttachment; use App\Entity\Attachments\LabelAttachment;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use App\Entity\Parameters\AttachmentTypeParameter;
use App\Form\AdminPages\AttachmentTypeAdminForm;
use App\Form\AdminPages\BaseEntityAdminForm;
use App\Form\AdminPages\LabelProfileAdminForm; use App\Form\AdminPages\LabelProfileAdminForm;
use App\Services\EntityExporter; use App\Services\EntityExporter;
use App\Services\EntityImporter; use App\Services\EntityImporter;

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,16 +23,11 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\LabelSystem\LabelOptions; use App\Entity\LabelSystem\LabelOptions;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use App\Entity\Parts\Part;
use App\Exceptions\TwigModeException; use App\Exceptions\TwigModeException;
use App\Form\LabelOptionsType;
use App\Form\LabelSystem\LabelDialogType; use App\Form\LabelSystem\LabelDialogType;
use App\Helpers\LabelResponse;
use App\Repository\DBElementRepository; use App\Repository\DBElementRepository;
use App\Services\ElementTypeNameGenerator; use App\Services\ElementTypeNameGenerator;
use App\Services\LabelSystem\LabelGenerator; use App\Services\LabelSystem\LabelGenerator;
@ -38,17 +36,12 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Form; use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormError;
use Symfony\Component\Form\SubmitButton;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
/** /**
* @Route("/label") * @Route("/label")
* @package App\Controller
*/ */
class LabelController extends AbstractController class LabelController extends AbstractController
{ {
@ -77,7 +70,7 @@ class LabelController extends AbstractController
$this->denyAccessUnlessGranted('@labels.create_labels'); $this->denyAccessUnlessGranted('@labels.create_labels');
//If we inherit a LabelProfile, the user need to have access to it... //If we inherit a LabelProfile, the user need to have access to it...
if ($profile !== null) { if (null !== $profile) {
$this->denyAccessUnlessGranted('read', $profile); $this->denyAccessUnlessGranted('read', $profile);
} }
@ -88,7 +81,7 @@ class LabelController extends AbstractController
} }
//We have to disable the options, if twig mode is selected and user is not allowed to use it. //We have to disable the options, if twig mode is selected and user is not allowed to use it.
$disable_options = $label_options->getLinesMode() === 'twig' && !$this->isGranted("@labels.use_twig"); $disable_options = 'twig' === $label_options->getLinesMode() && ! $this->isGranted('@labels.use_twig');
$form = $this->createForm(LabelDialogType::class, null, [ $form = $this->createForm(LabelDialogType::class, null, [
'disable_options' => $disable_options, 'disable_options' => $disable_options,
@ -99,14 +92,13 @@ class LabelController extends AbstractController
$target_id = $request->query->get('target_id', null); $target_id = $request->query->get('target_id', null);
$generate = $request->query->getBoolean('generate', false); $generate = $request->query->getBoolean('generate', false);
if ($profile === null && is_string($target_type)) { if (null === $profile && is_string($target_type)) {
$label_options->setSupportedElement($target_type); $label_options->setSupportedElement($target_type);
} }
if (is_string($target_id)) { if (is_string($target_id)) {
$form['target_id']->setData($target_id); $form['target_id']->setData($target_id);
} }
$form['options']->setData($label_options); $form['options']->setData($label_options);
$form->handleRequest($request); $form->handleRequest($request);
@ -117,17 +109,16 @@ class LabelController extends AbstractController
$filename = 'invalid.pdf'; $filename = 'invalid.pdf';
//Generate PDF either when the form is submitted and valid, or the form was not submit yet, and generate is set //Generate PDF either when the form is submitted and valid, or the form was not submit yet, and generate is set
if (($form->isSubmitted() && $form->isValid()) || ($generate && !$form->isSubmitted() && $profile !== null)) { if (($form->isSubmitted() && $form->isValid()) || ($generate && ! $form->isSubmitted() && null !== $profile)) {
$target_id = (string) $form->get('target_id')->getData(); $target_id = (string) $form->get('target_id')->getData();
$targets = $this->findObjects($form_options->getSupportedElement(), $target_id); $targets = $this->findObjects($form_options->getSupportedElement(), $target_id);
if (!empty($targets)) { if (! empty($targets)) {
try { try {
$pdf_data = $this->labelGenerator->generateLabel($form_options, $targets); $pdf_data = $this->labelGenerator->generateLabel($form_options, $targets);
$filename = $this->getLabelName($targets[0], $profile); $filename = $this->getLabelName($targets[0], $profile);
} catch (TwigModeException $exception) { } catch (TwigModeException $exception) {
$form->get('options')->get('lines')->addError(new FormError($exception->getMessage())); $form->get('options')->get('lines')->addError(new FormError($exception->getMessage()));
} }
} else { } else {
//$this->addFlash('warning', 'label_generator.no_entities_found'); //$this->addFlash('warning', 'label_generator.no_entities_found');
$form->get('target_id')->addError( $form->get('target_id')->addError(
@ -146,15 +137,15 @@ class LabelController extends AbstractController
protected function getLabelName(AbstractDBElement $element, ?LabelProfile $profile = null): string protected function getLabelName(AbstractDBElement $element, ?LabelProfile $profile = null): string
{ {
$ret = 'label_' . $this->elementTypeNameGenerator->getLocalizedTypeLabel($element); $ret = 'label_'.$this->elementTypeNameGenerator->getLocalizedTypeLabel($element);
$ret .= $element->getID(); $ret .= $element->getID();
return $ret . '.pdf'; return $ret.'.pdf';
} }
protected function findObjects(string $type, string $ids): array protected function findObjects(string $type, string $ids): array
{ {
if(!isset(LabelGenerator::CLASS_SUPPORT_MAPPING[$type])) { if (! isset(LabelGenerator::CLASS_SUPPORT_MAPPING[$type])) {
throw new \InvalidArgumentException('The given type is not known and can not be mapped to a class!'); throw new \InvalidArgumentException('The given type is not known and can not be mapped to a class!');
} }
@ -162,6 +153,7 @@ class LabelController extends AbstractController
/** @var DBElementRepository $repo */ /** @var DBElementRepository $repo */
$repo = $this->em->getRepository(LabelGenerator::CLASS_SUPPORT_MAPPING[$type]); $repo = $this->em->getRepository(LabelGenerator::CLASS_SUPPORT_MAPPING[$type]);
return $repo->getElementsFromIDArray($id_array); return $repo->getElementsFromIDArray($id_array);
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,20 +23,17 @@
namespace App\Controller; namespace App\Controller;
use App\Form\LabelSystem\ScanDialogType; use App\Form\LabelSystem\ScanDialogType;
use App\Services\LabelSystem\Barcodes\BarcodeRedirector;
use App\Services\LabelSystem\Barcodes\BarcodeNormalizer; use App\Services\LabelSystem\Barcodes\BarcodeNormalizer;
use App\Services\LabelSystem\Barcodes\BarcodeRedirector;
use Doctrine\ORM\EntityNotFoundException; use Doctrine\ORM\EntityNotFoundException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
/** /**
* @Route("/scan") * @Route("/scan")
* @package App\Controller
*/ */
class ScanController extends AbstractController class ScanController extends AbstractController
{ {
@ -58,8 +58,10 @@ class ScanController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$input = $form['input']->getData(); $input = $form['input']->getData();
try { try {
[$type, $id] = $this->barcodeNormalizer->normalizeBarcodeContent($input); [$type, $id] = $this->barcodeNormalizer->normalizeBarcodeContent($input);
try { try {
return $this->redirect($this->barcodeParser->getRedirectURL($type, $id)); return $this->redirect($this->barcodeParser->getRedirectURL($type, $id));
} catch (EntityNotFoundException $exception) { } catch (EntityNotFoundException $exception) {
@ -76,17 +78,17 @@ class ScanController extends AbstractController
} }
/** /**
* The route definition for this action is done in routes.yaml, as it does not use the _locale prefix as the other routes * The route definition for this action is done in routes.yaml, as it does not use the _locale prefix as the other routes.
* @param string $type
* @param int $id
*/ */
public function scanQRCode(string $type, int $id): Response public function scanQRCode(string $type, int $id): Response
{ {
try { try {
$this->addFlash('success', 'scan.qr_success'); $this->addFlash('success', 'scan.qr_success');
return $this->redirect($this->barcodeParser->getRedirectURL($type, $id)); return $this->redirect($this->barcodeParser->getRedirectURL($type, $id));
} catch (EntityNotFoundException $exception) { } catch (EntityNotFoundException $exception) {
$this->addFlash('success', 'scan.qr_not_found'); $this->addFlash('success', 'scan.qr_not_found');
return $this->redirectToRoute('homepage'); return $this->redirectToRoute('homepage');
} }
} }

View file

@ -72,7 +72,9 @@ use Symfony\Component\Validator\Constraints\Length;
class UserSettingsController extends AbstractController class UserSettingsController extends AbstractController
{ {
protected $demo_mode; protected $demo_mode;
/** @var EventDispatcher */ /**
* @var EventDispatcher
*/
protected $eventDispatcher; protected $eventDispatcher;
public function __construct(bool $demo_mode, EventDispatcherInterface $eventDispatcher) public function __construct(bool $demo_mode, EventDispatcherInterface $eventDispatcher)

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\DataFixtures; namespace App\DataFixtures;
use App\Entity\LabelSystem\LabelOptions; use App\Entity\LabelSystem\LabelOptions;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
@ -29,7 +31,6 @@ use Doctrine\Persistence\ObjectManager;
class LabelProfileFixtures extends Fixture class LabelProfileFixtures extends Fixture
{ {
protected $em; protected $em;
public function __construct(EntityManagerInterface $entityManager) public function __construct(EntityManagerInterface $entityManager)
@ -37,9 +38,9 @@ class LabelProfileFixtures extends Fixture
$this->em = $entityManager; $this->em = $entityManager;
} }
public function load(ObjectManager $manager) public function load(ObjectManager $manager): void
{ {
$this->em->getConnection()->exec("ALTER TABLE `label_profiles` AUTO_INCREMENT = 1;"); $this->em->getConnection()->exec('ALTER TABLE `label_profiles` AUTO_INCREMENT = 1;');
$profile1 = new LabelProfile(); $profile1 = new LabelProfile();
$profile1->setName('Profile 1'); $profile1->setName('Profile 1');
@ -77,13 +78,12 @@ class LabelProfileFixtures extends Fixture
$manager->persist($profile3); $manager->persist($profile3);
$profile4 = new LabelProfile(); $profile4 = new LabelProfile();
$profile4->setName('Profile 4'); $profile4->setName('Profile 4');
$profile4->setShowInDropdown(true); $profile4->setShowInDropdown(true);
$option4 = new LabelOptions(); $option4 = new LabelOptions();
$option4->setLines("{{ element.name }}"); $option4->setLines('{{ element.name }}');
$option4->setBarcodeType('code39'); $option4->setBarcodeType('code39');
$option4->setSupportedElement('part'); $option4->setSupportedElement('part');
$option4->setLinesMode('twig'); $option4->setLinesMode('twig');

View file

@ -38,21 +38,33 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
*/ */
class ORMAdapter extends AbstractAdapter class ORMAdapter extends AbstractAdapter
{ {
/** @var EntityManager */ /**
* @var EntityManager
*/
protected $manager; protected $manager;
/** @var \Doctrine\ORM\Mapping\ClassMetadata */ /**
* @var \Doctrine\ORM\Mapping\ClassMetadata
*/
protected $metadata; protected $metadata;
/** @var QueryBuilderProcessorInterface[] */ /**
* @var QueryBuilderProcessorInterface[]
*/
protected $criteriaProcessors; protected $criteriaProcessors;
/** @var ManagerRegistry */ /**
* @var ManagerRegistry
*/
private $registry; private $registry;
/** @var int */ /**
* @var int
*/
private $hydrationMode; private $hydrationMode;
/** @var QueryBuilderProcessorInterface[] */ /**
* @var QueryBuilderProcessorInterface[]
*/
private $queryBuilderProcessors; private $queryBuilderProcessors;
/** /**

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Entity\Attachments; namespace App\Entity\Attachments;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

View file

@ -33,7 +33,9 @@ interface TimeTravelInterface
*/ */
public function hasOldDataInformations(): bool; public function hasOldDataInformations(): bool;
/** Returns the data the entity had before this log entry. */ /**
* Returns the data the entity had before this log entry.
*/
public function getOldData(): array; public function getOldData(): array;
/** /**

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -96,12 +99,12 @@ class LabelOptions
} }
/** /**
* @param float $width
* @return LabelOptions * @return LabelOptions
*/ */
public function setWidth(float $width): LabelOptions public function setWidth(float $width): self
{ {
$this->width = $width; $this->width = $width;
return $this; return $this;
} }
@ -114,12 +117,12 @@ class LabelOptions
} }
/** /**
* @param float $height
* @return LabelOptions * @return LabelOptions
*/ */
public function setHeight(float $height): LabelOptions public function setHeight(float $height): self
{ {
$this->height = $height; $this->height = $height;
return $this; return $this;
} }
@ -132,12 +135,12 @@ class LabelOptions
} }
/** /**
* @param string $barcode_type
* @return LabelOptions * @return LabelOptions
*/ */
public function setBarcodeType(string $barcode_type): LabelOptions public function setBarcodeType(string $barcode_type): self
{ {
$this->barcode_type = $barcode_type; $this->barcode_type = $barcode_type;
return $this; return $this;
} }
@ -150,12 +153,12 @@ class LabelOptions
} }
/** /**
* @param string $picture_type
* @return LabelOptions * @return LabelOptions
*/ */
public function setPictureType(string $picture_type): LabelOptions public function setPictureType(string $picture_type): self
{ {
$this->picture_type = $picture_type; $this->picture_type = $picture_type;
return $this; return $this;
} }
@ -168,12 +171,12 @@ class LabelOptions
} }
/** /**
* @param string $supported_element
* @return LabelOptions * @return LabelOptions
*/ */
public function setSupportedElement(string $supported_element): LabelOptions public function setSupportedElement(string $supported_element): self
{ {
$this->supported_element = $supported_element; $this->supported_element = $supported_element;
return $this; return $this;
} }
@ -186,17 +189,18 @@ class LabelOptions
} }
/** /**
* @param string $lines
* @return LabelOptions * @return LabelOptions
*/ */
public function setLines(string $lines): LabelOptions public function setLines(string $lines): self
{ {
$this->lines = $lines; $this->lines = $lines;
return $this; return $this;
} }
/** /**
* Gets additional CSS (it will simply be attached * Gets additional CSS (it will simply be attached.
*
* @return string * @return string
*/ */
public function getAdditionalCss(): string public function getAdditionalCss(): string
@ -205,13 +209,12 @@ class LabelOptions
} }
/** /**
*
* @param string $additional_css
* @return LabelOptions * @return LabelOptions
*/ */
public function setAdditionalCss(string $additional_css): LabelOptions public function setAdditionalCss(string $additional_css): self
{ {
$this->additional_css = $additional_css; $this->additional_css = $additional_css;
return $this; return $this;
} }
@ -224,17 +227,12 @@ class LabelOptions
} }
/** /**
* @param string $lines_mode
* @return LabelOptions * @return LabelOptions
*/ */
public function setLinesMode(string $lines_mode): LabelOptions public function setLinesMode(string $lines_mode): self
{ {
$this->lines_mode = $lines_mode; $this->lines_mode = $lines_mode;
return $this; return $this;
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -32,7 +35,6 @@ use Symfony\Component\Validator\Constraints as Assert;
* @ORM\Table(name="label_profiles") * @ORM\Table(name="label_profiles")
* @ORM\EntityListeners({"App\EntityListeners\TreeCacheInvalidationListener"}) * @ORM\EntityListeners({"App\EntityListeners\TreeCacheInvalidationListener"})
* @UniqueEntity({"name", "options.supported_element"}) * @UniqueEntity({"name", "options.supported_element"})
* @package App\Entity\LabelSystem
*/ */
class LabelProfile extends AttachmentContainingDBElement class LabelProfile extends AttachmentContainingDBElement
{ {
@ -73,14 +75,16 @@ class LabelProfile extends AttachmentContainingDBElement
return $this->options; return $this->options;
} }
public function setOptions(LabelOptions $labelOptions): LabelProfile public function setOptions(LabelOptions $labelOptions): self
{ {
$this->options = $labelOptions; $this->options = $labelOptions;
return $this; return $this;
} }
/** /**
* Get the comment of the element. * Get the comment of the element.
*
* @return string the comment * @return string the comment
*/ */
public function getComment(): ?string public function getComment(): ?string
@ -91,11 +95,13 @@ class LabelProfile extends AttachmentContainingDBElement
public function setComment(string $new_comment): string public function setComment(string $new_comment): string
{ {
$this->comment = $new_comment; $this->comment = $new_comment;
return $this; return $this;
} }
/** /**
* Returns true, if this label profile should be shown in label generator quick menu. * Returns true, if this label profile should be shown in label generator quick menu.
*
* @return bool * @return bool
*/ */
public function isShowInDropdown(): bool public function isShowInDropdown(): bool
@ -105,20 +111,16 @@ class LabelProfile extends AttachmentContainingDBElement
/** /**
* Sets the show in dropdown menu. * Sets the show in dropdown menu.
* @param bool $show_in_dropdown *
* @return LabelProfile * @return LabelProfile
*/ */
public function setShowInDropdown(bool $show_in_dropdown): LabelProfile public function setShowInDropdown(bool $show_in_dropdown): self
{ {
$this->show_in_dropdown = $show_in_dropdown; $this->show_in_dropdown = $show_in_dropdown;
return $this; return $this;
} }
/**
* @inheritDoc
*/
public function getIDString(): string public function getIDString(): string
{ {
return 'LP'.sprintf('%09d', $this->getID()); return 'LP'.sprintf('%09d', $this->getID());

View file

@ -120,7 +120,9 @@ abstract class AbstractLogEntry extends AbstractDBElement
protected const TARGET_TYPE_PARAMETER = 18; protected const TARGET_TYPE_PARAMETER = 18;
protected const TARGET_TYPE_LABEL_PROFILE = 19; protected const TARGET_TYPE_LABEL_PROFILE = 19;
/** @var array This const is used to convert the numeric level to a PSR-3 compatible log level */ /**
* @var array This const is used to convert the numeric level to a PSR-3 compatible log level
*/
protected const LEVEL_ID_TO_STRING = [ protected const LEVEL_ID_TO_STRING = [
self::LEVEL_EMERGENCY => LogLevel::EMERGENCY, self::LEVEL_EMERGENCY => LogLevel::EMERGENCY,
self::LEVEL_ALERT => LogLevel::ALERT, self::LEVEL_ALERT => LogLevel::ALERT,

View file

@ -70,12 +70,16 @@ use Symfony\Component\Serializer\SerializerInterface;
*/ */
class EventLoggerSubscriber implements EventSubscriber class EventLoggerSubscriber implements EventSubscriber
{ {
/** @var array The given fields will not be saved, because they contain sensitive informations */ /**
* @var array The given fields will not be saved, because they contain sensitive informations
*/
protected const FIELD_BLACKLIST = [ protected const FIELD_BLACKLIST = [
User::class => ['password', 'need_pw_change', 'googleAuthenticatorSecret', 'backupCodes', 'trustedDeviceCookieVersion', 'pw_reset_token', 'backupCodesGenerationDate'], User::class => ['password', 'need_pw_change', 'googleAuthenticatorSecret', 'backupCodes', 'trustedDeviceCookieVersion', 'pw_reset_token', 'backupCodesGenerationDate'],
]; ];
/** @var array If elements of the given class are deleted, a log for the given fields will be triggered */ /**
* @var array If elements of the given class are deleted, a log for the given fields will be triggered
*/
protected const TRIGGER_ASSOCIATION_LOG_WHITELIST = [ protected const TRIGGER_ASSOCIATION_LOG_WHITELIST = [
PartLot::class => ['part'], PartLot::class => ['part'],
Orderdetail::class => ['part'], Orderdetail::class => ['part'],

View file

@ -69,7 +69,9 @@ final class RegisterU2FSubscriber implements EventSubscriberInterface
*/ */
private $router; private $router;
/** @var EventDispatcher */ /**
* @var EventDispatcher
*/
private $eventDispatcher; private $eventDispatcher;
public function __construct(UrlGeneratorInterface $router, EntityManagerInterface $entityManager, FlashBagInterface $flashBag, EventDispatcherInterface $eventDispatcher, bool $demo_mode) public function __construct(UrlGeneratorInterface $router, EntityManagerInterface $entityManager, FlashBagInterface $flashBag, EventDispatcherInterface $eventDispatcher, bool $demo_mode)

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,13 +23,11 @@
namespace App\Exceptions; namespace App\Exceptions;
use Throwable;
use Twig\Error\Error; use Twig\Error\Error;
class TwigModeException extends \RuntimeException class TwigModeException extends \RuntimeException
{ {
public function __construct(Error $previous = null) public function __construct(?Error $previous = null)
{ {
parent::__construct($previous->getMessage(), 0, $previous); parent::__construct($previous->getMessage(), 0, $previous);
} }

View file

@ -45,7 +45,6 @@ namespace App\Form\AdminPages;
use App\Entity\Attachments\Attachment; use App\Entity\Attachments\Attachment;
use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\LabelSystem\LabelOptions;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use App\Form\AttachmentFormType; use App\Form\AttachmentFormType;
use App\Form\ParameterType; use App\Form\ParameterType;
@ -106,7 +105,7 @@ class BaseEntityAdminForm extends AbstractType
'class' => get_class($entity), 'class' => get_class($entity),
'required' => false, 'required' => false,
'label' => 'parent.label', 'label' => 'parent.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity),
] ]
) )
->add( ->add(
@ -119,7 +118,7 @@ class BaseEntityAdminForm extends AbstractType
'label_attr' => [ 'label_attr' => [
'class' => 'checkbox-custom', 'class' => 'checkbox-custom',
], ],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
] ]
); );
} }
@ -135,7 +134,7 @@ class BaseEntityAdminForm extends AbstractType
'rows' => 4, 'rows' => 4,
], ],
'help' => 'bbcode.hint', 'help' => 'bbcode.hint',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
] ]
); );
} }
@ -178,7 +177,7 @@ class BaseEntityAdminForm extends AbstractType
'entry_type' => ParameterType::class, 'entry_type' => ParameterType::class,
'allow_add' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'allow_add' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'allow_delete' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'allow_delete' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'reindex_enable' => true, 'reindex_enable' => true,
'label' => false, 'label' => false,
'by_reference' => false, 'by_reference' => false,

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Form\AdminPages; namespace App\Form\AdminPages;
use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use App\Form\LabelOptionsType; use App\Form\LabelOptionsType;
@ -30,9 +32,15 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class LabelProfileAdminForm extends BaseEntityAdminForm class LabelProfileAdminForm extends BaseEntityAdminForm
{ {
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);
$resolver->setDefault('data_class', LabelProfile::class);
$resolver->setDefault('disable_options', false);
}
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void
{ {
$builder->add('show_in_dropdown', CheckboxType::class, [ $builder->add('show_in_dropdown', CheckboxType::class, [
'required' => false, 'required' => false,
'label' => 'label_profile.showInDropdown', 'label' => 'label_profile.showInDropdown',
@ -45,11 +53,4 @@ class LabelProfileAdminForm extends BaseEntityAdminForm
'disabled' => $options['disable_options'], 'disabled' => $options['disable_options'],
]); ]);
} }
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);
$resolver->setDefault('data_class', LabelProfile::class);
$resolver->setDefault('disable_options', false);
}
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Form; namespace App\Form;
use App\Entity\LabelSystem\LabelOptions; use App\Entity\LabelSystem\LabelOptions;
use FOS\CKEditorBundle\Form\Type\CKEditorType; use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
@ -40,7 +42,7 @@ class LabelOptionsType extends AbstractType
$this->security = $security; $this->security = $security;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('width', NumberType::class, [ $builder->add('width', NumberType::class, [
'label' => 'label_options.page_size.label', 'label' => 'label_options.page_size.label',
@ -49,7 +51,7 @@ class LabelOptionsType extends AbstractType
'placeholder' => 'label_options.width.placeholder', 'placeholder' => 'label_options.width.placeholder',
'min' => 0, 'min' => 0,
'step' => 'any', 'step' => 'any',
] ],
]); ]);
$builder->add('height', NumberType::class, [ $builder->add('height', NumberType::class, [
'label' => false, 'label' => false,
@ -58,7 +60,7 @@ class LabelOptionsType extends AbstractType
'placeholder' => 'label_options.height.placeholder', 'placeholder' => 'label_options.height.placeholder',
'min' => 0, 'min' => 0,
'step' => 'any', 'step' => 'any',
] ],
]); ]);
$builder->add('supported_element', ChoiceType::class, [ $builder->add('supported_element', ChoiceType::class, [
@ -67,11 +69,11 @@ class LabelOptionsType extends AbstractType
'part.label' => 'part', 'part.label' => 'part',
'part_lot.label' => 'part_lot', 'part_lot.label' => 'part_lot',
'storelocation.label' => 'storelocation', 'storelocation.label' => 'storelocation',
] ],
]); ]);
$builder->add('barcode_type', ChoiceType::class, [ $builder->add('barcode_type', ChoiceType::class, [
'label' => 'label_options.barcode_type.label', 'label' => 'label_options.barcode_type.label',
'empty_data' => 'none', 'empty_data' => 'none',
'choices' => [ 'choices' => [
'label_options.barcode_type.none' => 'none', 'label_options.barcode_type.none' => 'none',
@ -82,10 +84,10 @@ class LabelOptionsType extends AbstractType
'label_options.barcode_type.datamatrix' => 'datamatrix', 'label_options.barcode_type.datamatrix' => 'datamatrix',
], ],
'group_by' => function ($choice, $key, $value) { 'group_by' => function ($choice, $key, $value) {
if (in_array($choice, ['qr', 'datamatrix'])) { if (in_array($choice, ['qr', 'datamatrix'], true)) {
return 'label_options.barcode_type.2D'; return 'label_options.barcode_type.2D';
} }
if (in_array($choice, ['code39', 'code93', 'code128'])) { if (in_array($choice, ['code39', 'code93', 'code128'], true)) {
return 'label_options.barcode_type.1D'; return 'label_options.barcode_type.1D';
} }
@ -95,7 +97,6 @@ class LabelOptionsType extends AbstractType
'class' => 'selectpicker', 'class' => 'selectpicker',
'data-live-search' => true, 'data-live-search' => true,
], ],
]); ]);
$builder->add('lines', CKEditorType::class, [ $builder->add('lines', CKEditorType::class, [
@ -126,16 +127,16 @@ class LabelOptionsType extends AbstractType
'help_html' => true, 'help_html' => true,
'expanded' => true, 'expanded' => true,
'attr' => [ 'attr' => [
'class' => 'pt-2' 'class' => 'pt-2',
], ],
'label_attr' => [ 'label_attr' => [
'class' => 'radio-custom radio-inline' 'class' => 'radio-custom radio-inline',
], ],
'disabled' => !$this->security->isGranted('@labels.use_twig') 'disabled' => ! $this->security->isGranted('@labels.use_twig'),
]); ]);
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefault('data_class', LabelOptions::class); $resolver->setDefault('data_class', LabelOptions::class);
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,11 +23,9 @@
namespace App\Form\LabelSystem; namespace App\Form\LabelSystem;
use App\Form\LabelOptionsType; use App\Form\LabelOptionsType;
use App\Validator\Constraints\Misc\ValidRange; use App\Validator\Constraints\Misc\ValidRange;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -40,7 +41,7 @@ class LabelDialogType extends AbstractType
$this->security = $security; $this->security = $security;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('target_id', TextType::class, [ $builder->add('target_id', TextType::class, [
'required' => true, 'required' => true,
@ -53,15 +54,14 @@ class LabelDialogType extends AbstractType
$builder->add('options', LabelOptionsType::class, [ $builder->add('options', LabelOptionsType::class, [
'label' => false, 'label' => false,
'disabled' => !$this->security->isGranted('@labels.edit_options') || $options['disable_options'], 'disabled' => ! $this->security->isGranted('@labels.edit_options') || $options['disable_options'],
]); ]);
$builder->add('update', SubmitType::class, [ $builder->add('update', SubmitType::class, [
'label' => 'label_generator.update', 'label' => 'label_generator.update',
]); ]);
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
parent::configureOptions($resolver); parent::configureOptions($resolver);
$resolver->setDefault('mapped', false); $resolver->setDefault('mapped', false);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Form\LabelSystem; namespace App\Form\LabelSystem;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
@ -29,7 +31,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class ScanDialogType extends AbstractType class ScanDialogType extends AbstractType
{ {
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('input', TextType::class, [ $builder->add('input', TextType::class, [
'label' => 'scan_dialog.input', 'label' => 'scan_dialog.input',
@ -40,11 +42,11 @@ class ScanDialogType extends AbstractType
]); ]);
$builder->add('submit', SubmitType::class, [ $builder->add('submit', SubmitType::class, [
'label' => 'scan_dialog.submit' 'label' => 'scan_dialog.submit',
]); ]);
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefault('mapped', false); $resolver->setDefault('mapped', false);
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,8 +23,6 @@
namespace App\Helpers; namespace App\Helpers;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -39,6 +40,7 @@ class LabelResponse extends Response
$this->setAutoEtag(); $this->setAutoEtag();
$this->setAutoLastModified(); $this->setAutoLastModified();
return $this; return $this;
} }
@ -46,8 +48,7 @@ class LabelResponse extends Response
{ {
parent::prepare($request); parent::prepare($request);
$this->headers->set('Content-Type','application/pdf'); $this->headers->set('Content-Type', 'application/pdf');
if ('HTTP/1.0' !== $request->server->get('SERVER_PROTOCOL')) { if ('HTTP/1.0' !== $request->server->get('SERVER_PROTOCOL')) {
$this->setProtocolVersion('1.1'); $this->setProtocolVersion('1.1');
@ -89,7 +90,7 @@ class LabelResponse extends Response
*/ */
public function setContentDisposition($disposition, $filename, $filenameFallback = '') public function setContentDisposition($disposition, $filename, $filenameFallback = '')
{ {
if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || false !== strpos($filename, '%'))) { if ('' === $filenameFallback && (! preg_match('/^[\x20-\x7e]*$/', $filename) || false !== strpos($filename, '%'))) {
$encoding = mb_detect_encoding($filename, null, true) ?: '8bit'; $encoding = mb_detect_encoding($filename, null, true) ?: '8bit';
for ($i = 0, $filenameLength = mb_strlen($filename, $encoding); $i < $filenameLength; ++$i) { for ($i = 0, $filenameLength = mb_strlen($filename, $encoding); $i < $filenameLength; ++$i) {
@ -108,5 +109,4 @@ class LabelResponse extends Response
return $this; return $this;
} }
} }

View file

@ -12,25 +12,25 @@ use Doctrine\Migrations\AbstractMigration;
*/ */
final class Version20200502161750 extends AbstractMigration final class Version20200502161750 extends AbstractMigration
{ {
public function getDescription() : string public function getDescription(): string
{ {
return ''; return '';
} }
public function up(Schema $schema) : void public function up(Schema $schema): void
{ {
// this up() migration is auto-generated, please modify it to your needs // this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('CREATE TABLE label_profiles (id INT AUTO_INCREMENT NOT NULL, id_preview_attachement INT DEFAULT NULL, comment LONGTEXT NOT NULL, show_in_dropdown TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, options_width DOUBLE PRECISION NOT NULL, options_height DOUBLE PRECISION NOT NULL, options_barcode_type VARCHAR(255) NOT NULL, options_picture_type VARCHAR(255) NOT NULL, options_supported_element VARCHAR(255) NOT NULL, options_additional_css LONGTEXT NOT NULL, options_lines_mode VARCHAR(255) NOT NULL, options_lines LONGTEXT NOT NULL, INDEX IDX_C93E9CF56DEDCEC2 (id_preview_attachement), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('CREATE TABLE label_profiles (id INT AUTO_INCREMENT NOT NULL, id_preview_attachement INT DEFAULT NULL, comment LONGTEXT NOT NULL, show_in_dropdown TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, options_width DOUBLE PRECISION NOT NULL, options_height DOUBLE PRECISION NOT NULL, options_barcode_type VARCHAR(255) NOT NULL, options_picture_type VARCHAR(255) NOT NULL, options_supported_element VARCHAR(255) NOT NULL, options_additional_css LONGTEXT NOT NULL, options_lines_mode VARCHAR(255) NOT NULL, options_lines LONGTEXT NOT NULL, INDEX IDX_C93E9CF56DEDCEC2 (id_preview_attachement), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE label_profiles ADD CONSTRAINT FK_C93E9CF56DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); $this->addSql('ALTER TABLE label_profiles ADD CONSTRAINT FK_C93E9CF56DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)');
$this->addSql('ALTER TABLE log CHANGE level level TINYINT(4) NOT NULL'); $this->addSql('ALTER TABLE log CHANGE level level TINYINT(4) NOT NULL');
} }
public function down(Schema $schema) : void public function down(Schema $schema): void
{ {
// this down() migration is auto-generated, please modify it to your needs // this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); $this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('DROP TABLE label_profiles'); $this->addSql('DROP TABLE label_profiles');
$this->addSql('ALTER TABLE log CHANGE level level TINYINT(1) DEFAULT NULL'); $this->addSql('ALTER TABLE log CHANGE level level TINYINT(1) DEFAULT NULL');

View file

@ -52,7 +52,7 @@ class DBElementRepository extends EntityRepository
/** /**
* Find all elements that match a list of IDs. * Find all elements that match a list of IDs.
* @param array $ids *
* @return AbstractDBElement[] * @return AbstractDBElement[]
*/ */
public function getElementsFromIDArray(array $ids): array public function getElementsFromIDArray(array $ids): array

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -23,22 +26,21 @@ namespace App\Repository;
use App\Entity\LabelSystem\LabelOptions; use App\Entity\LabelSystem\LabelOptions;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use App\Helpers\Trees\TreeViewNode; use App\Helpers\Trees\TreeViewNode;
use Symfony\Contracts\Translation\TranslatorInterface;
class LabelProfileRepository extends NamedDBElementRepository class LabelProfileRepository extends NamedDBElementRepository
{ {
/** /**
* Find the profiles that are shown in the dropdown for the given type. * Find the profiles that are shown in the dropdown for the given type.
* You should maybe use the cached version of this in LabelProfileDropdownHelper * You should maybe use the cached version of this in LabelProfileDropdownHelper.
* @param string $type *
* @return array * @return array
*/ */
public function getDropdownProfiles(string $type): array public function getDropdownProfiles(string $type): array
{ {
if (!in_array($type, LabelOptions::SUPPORTED_ELEMENTS)) { if (! in_array($type, LabelOptions::SUPPORTED_ELEMENTS, true)) {
throw new \InvalidArgumentException('Invalid supported_element type given.'); throw new \InvalidArgumentException('Invalid supported_element type given.');
} }
return $this->findBy(['options.supported_element' => $type, 'show_in_dropdown' => true], ['name' => 'ASC']); return $this->findBy(['options.supported_element' => $type, 'show_in_dropdown' => true], ['name' => 'ASC']);
} }
@ -62,9 +64,9 @@ class LabelProfileRepository extends NamedDBElementRepository
$type_children[] = $node; $type_children[] = $node;
} }
if (!empty($type_children)) { if (! empty($type_children)) {
//Use default label e.g. 'part_label'. $$ marks that it will be translated in TreeViewGenerator //Use default label e.g. 'part_label'. $$ marks that it will be translated in TreeViewGenerator
$tmp = new TreeViewNode('$$' . $type . '.label', null, $type_children); $tmp = new TreeViewNode('$$'.$type.'.label', null, $type_children);
$result[] = $tmp; $result[] = $tmp;
} }
@ -74,16 +76,19 @@ class LabelProfileRepository extends NamedDBElementRepository
} }
/** /**
* Find all LabelProfiles that can be used with the given type * Find all LabelProfiles that can be used with the given type.
* @param string $type See LabelOptions::SUPPORTED_ELEMENTS for valid values. *
* @param array $order_by The way the results should be sorted. By default ordered by * @param string $type See LabelOptions::SUPPORTED_ELEMENTS for valid values.
* @param array $order_by The way the results should be sorted. By default ordered by
*
* @return array * @return array
*/ */
public function findForSupportedElement(string $type, array $order_by = ['name' => 'ASC']): array public function findForSupportedElement(string $type, array $order_by = ['name' => 'ASC']): array
{ {
if (!in_array($type, LabelOptions::SUPPORTED_ELEMENTS)) { if (! in_array($type, LabelOptions::SUPPORTED_ELEMENTS, true)) {
throw new \InvalidArgumentException('Invalid supported_element type given.'); throw new \InvalidArgumentException('Invalid supported_element type given.');
} }
return $this->findBy(['options.supported_element' => $type], $order_by); return $this->findBy(['options.supported_element' => $type], $order_by);
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,13 +23,11 @@
namespace App\Security\Voter; namespace App\Security\Voter;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
class LabelProfileVoter extends ExtendedVoter class LabelProfileVoter extends ExtendedVoter
{ {
protected const MAPPING = [ protected const MAPPING = [
'read' => 'read_profiles', 'read' => 'read_profiles',
'create' => 'create_profiles', 'create' => 'create_profiles',
@ -36,21 +37,15 @@ class LabelProfileVoter extends ExtendedVoter
'revert_element' => 'revert_element', 'revert_element' => 'revert_element',
]; ];
/**
* @inheritDoc
*/
protected function voteOnUser($attribute, $subject, User $user): bool protected function voteOnUser($attribute, $subject, User $user): bool
{ {
return $this->resolver->inherit($user, 'labels', self::MAPPING[$attribute]) ?? false; return $this->resolver->inherit($user, 'labels', self::MAPPING[$attribute]) ?? false;
} }
/**
* @inheritDoc
*/
protected function supports($attribute, $subject) protected function supports($attribute, $subject)
{ {
if ($subject instanceof LabelProfile) { if ($subject instanceof LabelProfile) {
if (!isset(self::MAPPING[$attribute])) { if (! isset(self::MAPPING[$attribute])) {
return false; return false;
} }

View file

@ -28,7 +28,9 @@ use App\Entity\UserSystem\User;
class OrderdetailVoter extends ExtendedVoter class OrderdetailVoter extends ExtendedVoter
{ {
/** @var string[] When this permsission are encountered, they are checked on part */ /**
* @var string[] When this permsission are encountered, they are checked on part
*/
protected const PART_PERMS = ['show_history', 'revert_element']; protected const PART_PERMS = ['show_history', 'revert_element'];
protected function voteOnUser($attribute, $subject, User $user): bool protected function voteOnUser($attribute, $subject, User $user): bool

View file

@ -28,7 +28,9 @@ use App\Entity\UserSystem\User;
class PartLotVoter extends ExtendedVoter class PartLotVoter extends ExtendedVoter
{ {
/** @var string[] When this permsission are encountered, they are checked on part */ /**
* @var string[] When this permsission are encountered, they are checked on part
*/
protected const PART_PERMS = ['show_history', 'revert_element']; protected const PART_PERMS = ['show_history', 'revert_element'];
protected function voteOnUser($attribute, $subject, User $user): bool protected function voteOnUser($attribute, $subject, User $user): bool

View file

@ -28,7 +28,9 @@ use App\Entity\UserSystem\User;
class PricedetailVoter extends ExtendedVoter class PricedetailVoter extends ExtendedVoter
{ {
/** @var string[] When this permsission are encountered, they are checked on part */ /**
* @var string[] When this permsission are encountered, they are checked on part
*/
protected const PART_PERMS = ['show_history', 'revert_element']; protected const PART_PERMS = ['show_history', 'revert_element'];
protected function voteOnUser($attribute, $subject, User $user): bool protected function voteOnUser($attribute, $subject, User $user): bool

View file

@ -62,9 +62,9 @@ class AmountFormatter
/** /**
* Formats the given value using the measurement unit and options. * Formats the given value using the measurement unit and options.
* *
* @param float|string|int $value * @param float|string|int $value
* @param MeasurementUnit|null $unit The measurement unit, whose unit symbol should be used for formatting. * @param MeasurementUnit|null $unit The measurement unit, whose unit symbol should be used for formatting.
* If set to null, it is assumed that the part amount is measured in pieces. * If set to null, it is assumed that the part amount is measured in pieces.
* *
* @return string The formatted string * @return string The formatted string
* *

View file

@ -242,7 +242,7 @@ class EntityURLGenerator
Currency::class => 'currency_edit', Currency::class => 'currency_edit',
MeasurementUnit::class => 'measurement_unit_edit', MeasurementUnit::class => 'measurement_unit_edit',
Group::class => 'group_edit', Group::class => 'group_edit',
LabelProfile::class => 'label_profile_edit' LabelProfile::class => 'label_profile_edit',
]; ];
return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]);
@ -272,7 +272,7 @@ class EntityURLGenerator
Currency::class => 'currency_edit', Currency::class => 'currency_edit',
MeasurementUnit::class => 'measurement_unit_edit', MeasurementUnit::class => 'measurement_unit_edit',
Group::class => 'group_edit', Group::class => 'group_edit',
LabelProfile::class => 'label_profile_edit' LabelProfile::class => 'label_profile_edit',
]; ];
return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]);
@ -302,7 +302,7 @@ class EntityURLGenerator
Currency::class => 'currency_new', Currency::class => 'currency_new',
MeasurementUnit::class => 'measurement_unit_new', MeasurementUnit::class => 'measurement_unit_new',
Group::class => 'group_new', Group::class => 'group_new',
LabelProfile::class => 'label_profile_new' LabelProfile::class => 'label_profile_new',
]; ];
return $this->urlGenerator->generate($this->mapToController($map, $entity)); return $this->urlGenerator->generate($this->mapToController($map, $entity));
@ -333,7 +333,7 @@ class EntityURLGenerator
Currency::class => 'currency_clone', Currency::class => 'currency_clone',
MeasurementUnit::class => 'measurement_unit_clone', MeasurementUnit::class => 'measurement_unit_clone',
Group::class => 'group_clone', Group::class => 'group_clone',
LabelProfile::class => 'label_profile_clone' LabelProfile::class => 'label_profile_clone',
]; ];
return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]);
@ -376,7 +376,7 @@ class EntityURLGenerator
Currency::class => 'currency_delete', Currency::class => 'currency_delete',
MeasurementUnit::class => 'measurement_unit_delete', MeasurementUnit::class => 'measurement_unit_delete',
Group::class => 'group_delete', Group::class => 'group_delete',
LabelProfile::class => 'label_profile_delete' LabelProfile::class => 'label_profile_delete',
]; ];
return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]); return $this->urlGenerator->generate($this->mapToController($map, $entity), ['id' => $entity->getID()]);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -40,18 +43,23 @@ final class BarcodeGenerator
switch ($options->getBarcodeType()) { switch ($options->getBarcodeType()) {
case 'qr': case 'qr':
$type = 'QRCODE'; $type = 'QRCODE';
break; break;
case 'datamatrix': case 'datamatrix':
$type = 'DATAMATRIX'; $type = 'DATAMATRIX';
break; break;
case 'code39': case 'code39':
$type = 'C39'; $type = 'C39';
break; break;
case 'code93': case 'code93':
$type = 'C93'; $type = 'C93';
break; break;
case 'code128': case 'code128':
$type = 'C128A'; $type = 'C128A';
break; break;
case 'none': case 'none':
return null; return null;
@ -80,5 +88,4 @@ final class BarcodeGenerator
throw new \InvalidArgumentException('Unknown label type!'); throw new \InvalidArgumentException('Unknown label type!');
} }
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,24 +23,18 @@
namespace App\Services\LabelSystem\Barcodes; namespace App\Services\LabelSystem\Barcodes;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation; use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Exceptions\EntityNotSupportedException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
final class BarcodeContentGenerator final class BarcodeContentGenerator
{ {
private $urlGenerator;
public const PREFIX_MAP = [ public const PREFIX_MAP = [
Part::class => 'P', Part::class => 'P',
PartLot::class => 'L', PartLot::class => 'L',
Storelocation::class => 'S' Storelocation::class => 'S',
]; ];
private const URL_MAP = [ private const URL_MAP = [
@ -45,6 +42,7 @@ final class BarcodeContentGenerator
PartLot::class => 'lot', PartLot::class => 'lot',
Storelocation::class => 'location', Storelocation::class => 'location',
]; ];
private $urlGenerator;
public function __construct(UrlGeneratorInterface $urlGenerator) public function __construct(UrlGeneratorInterface $urlGenerator)
{ {
@ -53,7 +51,7 @@ final class BarcodeContentGenerator
/** /**
* Generates a fixed URL to the given Element that can be embedded in a 2D code (e.g. QR code). * Generates a fixed URL to the given Element that can be embedded in a 2D code (e.g. QR code).
* @param AbstractDBElement $target *
* @return string * @return string
*/ */
public function getURLContent(AbstractDBElement $target): string public function getURLContent(AbstractDBElement $target): string
@ -69,15 +67,16 @@ final class BarcodeContentGenerator
/** /**
* Returns a Code that can be used in a 1D barcode. * Returns a Code that can be used in a 1D barcode.
* The return value has a format of "L0123" * The return value has a format of "L0123".
* @param AbstractDBElement $target *
* @return string * @return string
*/ */
public function get1DBarcodeContent(AbstractDBElement $target): string public function get1DBarcodeContent(AbstractDBElement $target): string
{ {
$prefix = $this->classToString(self::PREFIX_MAP, $target); $prefix = $this->classToString(self::PREFIX_MAP, $target);
$id = sprintf('%04d', $target->getID() ?? 0); $id = sprintf('%04d', $target->getID() ?? 0);
return $prefix . $id;
return $prefix.$id;
} }
private function classToString(array $map, object $target): string private function classToString(array $map, object $target): string
@ -87,12 +86,12 @@ final class BarcodeContentGenerator
return $map[$class]; return $map[$class];
} }
foreach($map as $class => $string) { foreach ($map as $class => $string) {
if (is_a($target, $class)) { if (is_a($target, $class)) {
return $string; return $string;
} }
} }
throw new \InvalidArgumentException('Unknown object class ' . get_class($target)); throw new \InvalidArgumentException('Unknown object class '.get_class($target));
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -44,39 +47,6 @@ final class BarcodeExampleElementsGenerator
} }
} }
private function getStorelocation(): Storelocation
{
$storelocation = new Storelocation();
$storelocation->setName('Location 1');
$storelocation->setComment('Example comment');
$storelocation->updatedTimestamps();
$parent = new Storelocation();
$parent->setName('Parent');
$storelocation->setParent($parent);
return $storelocation;
}
private function getStructuralData(string $class): AbstractStructuralDBElement
{
if (!is_a($class, AbstractStructuralDBElement::class, true)) {
throw new \InvalidArgumentException('$class must be an child of AbstractStructuralDBElement');
}
/** @var AbstractStructuralDBElement $parent */
$parent = new $class();
$parent->setName('Example');
/** @var AbstractStructuralDBElement $child */
$child = new $class();
$child->setName((new \ReflectionClass($class))->getShortName());
$child->setParent($parent);
return $child;
}
public function getExamplePart(): Part public function getExamplePart(): Part
{ {
$part = new Part(); $part = new Part();
@ -98,7 +68,6 @@ final class BarcodeExampleElementsGenerator
$part->setMinAmount(100); $part->setMinAmount(100);
$part->setNeedsReview(true); $part->setNeedsReview(true);
return $part; return $part;
} }
@ -115,4 +84,37 @@ final class BarcodeExampleElementsGenerator
return $lot; return $lot;
} }
private function getStorelocation(): Storelocation
{
$storelocation = new Storelocation();
$storelocation->setName('Location 1');
$storelocation->setComment('Example comment');
$storelocation->updatedTimestamps();
$parent = new Storelocation();
$parent->setName('Parent');
$storelocation->setParent($parent);
return $storelocation;
}
private function getStructuralData(string $class): AbstractStructuralDBElement
{
if (! is_a($class, AbstractStructuralDBElement::class, true)) {
throw new \InvalidArgumentException('$class must be an child of AbstractStructuralDBElement');
}
/** @var AbstractStructuralDBElement $parent */
$parent = new $class();
$parent->setName('Example');
/** @var AbstractStructuralDBElement $child */
$child = new $class();
$child->setName((new \ReflectionClass($class))->getShortName());
$child->setParent($parent);
return $child;
}
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Services\LabelSystem\Barcodes; namespace App\Services\LabelSystem\Barcodes;
final class BarcodeNormalizer final class BarcodeNormalizer
{ {
private const PREFIX_TYPE_MAP = [ private const PREFIX_TYPE_MAP = [
@ -31,8 +33,8 @@ final class BarcodeNormalizer
/** /**
* Parses barcode content and normalizes it. * Parses barcode content and normalizes it.
* Returns an array in the format ['part', 1]: First entry contains element type, second the ID of the element * Returns an array in the format ['part', 1]: First entry contains element type, second the ID of the element.
* @param string $input *
* @return array * @return array
*/ */
public function normalizeBarcodeContent(string $input): array public function normalizeBarcodeContent(string $input): array
@ -53,9 +55,10 @@ final class BarcodeNormalizer
$prefix = $matches[1]; $prefix = $matches[1];
$id = (int) $matches[2]; $id = (int) $matches[2];
if (!isset(self::PREFIX_TYPE_MAP[$prefix])) { if (! isset(self::PREFIX_TYPE_MAP[$prefix])) {
throw new \InvalidArgumentException('Unknown prefix ' . $prefix); throw new \InvalidArgumentException('Unknown prefix '.$prefix);
} }
return [self::PREFIX_TYPE_MAP[$prefix], $id]; return [self::PREFIX_TYPE_MAP[$prefix], $id];
} }
@ -64,9 +67,10 @@ final class BarcodeNormalizer
$prefix = $matches[1]; $prefix = $matches[1];
$id = (int) $matches[2]; $id = (int) $matches[2];
if (!isset(self::PREFIX_TYPE_MAP[$prefix])) { if (! isset(self::PREFIX_TYPE_MAP[$prefix])) {
throw new \InvalidArgumentException('Unknown prefix ' . $prefix); throw new \InvalidArgumentException('Unknown prefix '.$prefix);
} }
return [self::PREFIX_TYPE_MAP[$prefix], $id]; return [self::PREFIX_TYPE_MAP[$prefix], $id];
} }
@ -80,7 +84,6 @@ final class BarcodeNormalizer
return ['part', (int) $matches[1]]; return ['part', (int) $matches[1]];
} }
throw new \InvalidArgumentException('Unknown barcode format!'); throw new \InvalidArgumentException('Unknown barcode format!');
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Services\LabelSystem\Barcodes; namespace App\Services\LabelSystem\Barcodes;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityNotFoundException; use Doctrine\ORM\EntityNotFoundException;
@ -31,7 +33,6 @@ final class BarcodeRedirector
private $urlGenerator; private $urlGenerator;
private $em; private $em;
public function __construct(UrlGeneratorInterface $urlGenerator, EntityManagerInterface $entityManager) public function __construct(UrlGeneratorInterface $urlGenerator, EntityManagerInterface $entityManager)
{ {
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
@ -39,10 +40,13 @@ final class BarcodeRedirector
} }
/** /**
* Determines the URL to which the user should be redirected, when scanning a QR code * Determines the URL to which the user should be redirected, when scanning a QR code.
* @param string $type The type of the element that was scanned (e.g. 'part', 'lot', etc.) *
* @param int $id The ID of the element that was scanned * @param string $type The type of the element that was scanned (e.g. 'part', 'lot', etc.)
* @param int $id The ID of the element that was scanned
*
* @return string The URL to which should be redirected. * @return string The URL to which should be redirected.
*
* @throws EntityNotFoundException * @throws EntityNotFoundException
*/ */
public function getRedirectURL(string $type, int $id): string public function getRedirectURL(string $type, int $id): string
@ -53,7 +57,7 @@ final class BarcodeRedirector
case 'lot': case 'lot':
//Try to determine the part to the given lot //Try to determine the part to the given lot
$lot = $this->em->find(PartLot::class, $id); $lot = $this->em->find(PartLot::class, $id);
if ($lot === null) { if (null === $lot) {
throw new EntityNotFoundException(); throw new EntityNotFoundException();
} }
@ -63,7 +67,7 @@ final class BarcodeRedirector
return $this->urlGenerator->generate('part_list_store_location', ['id' => $id]); return $this->urlGenerator->generate('part_list_store_location', ['id' => $id]);
default: default:
throw new \InvalidArgumentException('Unknown $type: ' . $type); throw new \InvalidArgumentException('Unknown $type: '.$type);
} }
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,15 +23,11 @@
namespace App\Services\LabelSystem; namespace App\Services\LabelSystem;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\LabelSystem\LabelOptions; use App\Entity\LabelSystem\LabelOptions;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation; use App\Entity\Parts\Storelocation;
use App\Services\ElementTypeNameGenerator;
use Dompdf\Dompdf; use Dompdf\Dompdf;
use Twig\Environment;
final class LabelGenerator final class LabelGenerator
{ {
@ -48,44 +47,43 @@ final class LabelGenerator
} }
/** /**
* @param LabelOptions $options * @param object|object[] $elements An element or an array of elements for which labels should be generated
* @param object|object[] $elements An element or an array of elements for which labels should be generated *
* @return string * @return string
*/ */
public function generateLabel(LabelOptions $options, $elements): string public function generateLabel(LabelOptions $options, $elements): string
{ {
if (!is_array($elements) && !is_object($elements)) { if (! is_array($elements) && ! is_object($elements)) {
throw new \InvalidArgumentException('$element must be an object or an array of objects!'); throw new \InvalidArgumentException('$element must be an object or an array of objects!');
} }
if (!is_array($elements)) { if (! is_array($elements)) {
$elements = [$elements]; $elements = [$elements];
} }
foreach ($elements as $element) { foreach ($elements as $element) {
if (!$this->supports($options, $element)) { if (! $this->supports($options, $element)) {
throw new \InvalidArgumentException('The given options are not compatible with the given element!'); throw new \InvalidArgumentException('The given options are not compatible with the given element!');
} }
} }
$dompdf = new Dompdf(); $dompdf = new Dompdf();
$dompdf->setPaper($this->mmToPointsArray($options->getWidth(), $options->getHeight())); $dompdf->setPaper($this->mmToPointsArray($options->getWidth(), $options->getHeight()));
$dompdf->loadHtml($this->labelHTMLGenerator->getLabelHTML($options, $elements)); $dompdf->loadHtml($this->labelHTMLGenerator->getLabelHTML($options, $elements));
$dompdf->render(); $dompdf->render();
return $dompdf->output(); return $dompdf->output();
} }
/** /**
* Check if the given LabelOptions can be used with $element. * Check if the given LabelOptions can be used with $element.
* @param LabelOptions $options *
* @param object $element
* @return bool * @return bool
*/ */
public function supports(LabelOptions $options, object $element) public function supports(LabelOptions $options, object $element)
{ {
$supported_type = $options->getSupportedElement(); $supported_type = $options->getSupportedElement();
if (!isset(static::CLASS_SUPPORT_MAPPING[$supported_type])) { if (! isset(static::CLASS_SUPPORT_MAPPING[$supported_type])) {
throw new \InvalidArgumentException('Supported type name of the Label options not known!'); throw new \InvalidArgumentException('Supported type name of the Label options not known!');
} }
@ -93,9 +91,11 @@ final class LabelGenerator
} }
/** /**
* Converts width and height given in mm to an size array, that can be used by DOMPDF for page size * Converts width and height given in mm to an size array, that can be used by DOMPDF for page size.
* @param float $width The width of the paper *
* @param float $height The height of the paper * @param float $width The width of the paper
* @param float $height The height of the paper
*
* @return float[] * @return float[]
*/ */
public function mmToPointsArray(float $width, float $height): array public function mmToPointsArray(float $width, float $height): array

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -24,11 +27,9 @@ use App\Entity\Contracts\NamedElementInterface;
use App\Entity\LabelSystem\LabelOptions; use App\Entity\LabelSystem\LabelOptions;
use App\Exceptions\TwigModeException; use App\Exceptions\TwigModeException;
use App\Services\ElementTypeNameGenerator; use App\Services\ElementTypeNameGenerator;
use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Twig\Environment; use Twig\Environment;
use Twig\Error\Error; use Twig\Error\Error;
use Twig\Error\SyntaxError;
final class LabelHTMLGenerator final class LabelHTMLGenerator
{ {
@ -60,14 +61,14 @@ final class LabelHTMLGenerator
$twig_elements = []; $twig_elements = [];
if ($options->getLinesMode() === 'twig') { if ('twig' === $options->getLinesMode()) {
$sandboxed_twig = $this->sandboxedTwigProvider->getTwig($options); $sandboxed_twig = $this->sandboxedTwigProvider->getTwig($options);
$current_user = $this->security->getUser(); $current_user = $this->security->getUser();
} }
$page = 1; $page = 1;
foreach ($elements as $element) { foreach ($elements as $element) {
if ($options->getLinesMode() === 'twig' && isset($sandboxed_twig) && isset($current_user)) { if ('twig' === $options->getLinesMode() && isset($sandboxed_twig) && isset($current_user)) {
try { try {
$lines = $sandboxed_twig->render( $lines = $sandboxed_twig->render(
'lines', 'lines',
@ -92,10 +93,9 @@ final class LabelHTMLGenerator
'barcode_content' => $this->barcodeGenerator->getContent($options, $element), 'barcode_content' => $this->barcodeGenerator->getContent($options, $element),
]; ];
$page++; ++$page;
} }
return $this->twig->render('LabelSystem/labels/base_label.html.twig', [ return $this->twig->render('LabelSystem/labels/base_label.html.twig', [
'meta_title' => $this->getPDFTitle($options, $elements[0]), 'meta_title' => $this->getPDFTitle($options, $elements[0]),
'elements' => $twig_elements, 'elements' => $twig_elements,
@ -103,8 +103,7 @@ final class LabelHTMLGenerator
]); ]);
} }
private function getPDFTitle(LabelOptions $options, object $element)
protected function getPDFTitle(LabelOptions $options, object $element)
{ {
if ($element instanceof NamedElementInterface) { if ($element instanceof NamedElementInterface) {
return $this->elementTypeNameGenerator->getTypeNameCombination($element, false); return $this->elementTypeNameGenerator->getTypeNameCombination($element, false);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Services\LabelSystem; namespace App\Services\LabelSystem;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use App\Repository\LabelProfileRepository; use App\Repository\LabelProfileRepository;
use App\Services\UserCacheKeyGenerator; use App\Services\UserCacheKeyGenerator;
@ -44,7 +46,7 @@ final class LabelProfileDropdownHelper
public function getDropdownProfiles(string $type): array public function getDropdownProfiles(string $type): array
{ {
$secure_class_name = str_replace('\\', '_', LabelProfile::class); $secure_class_name = str_replace('\\', '_', LabelProfile::class);
$key = 'profile_dropdown_'.$this->keyGenerator->generateKey().'_'.$secure_class_name . '_' . $type; $key = 'profile_dropdown_'.$this->keyGenerator->generateKey().'_'.$secure_class_name.'_'.$type;
/** @var LabelProfileRepository $repo */ /** @var LabelProfileRepository $repo */
$repo = $this->entityManager->getRepository(LabelProfile::class); $repo = $this->entityManager->getRepository(LabelProfile::class);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -25,7 +28,6 @@ use App\Services\LabelSystem\PlaceholderProviders\PlaceholderProviderInterface;
/** /**
* This service replaces the Placeholders of the user provided lines with the proper informations. * This service replaces the Placeholders of the user provided lines with the proper informations.
* It uses the PlaceholderProviders provided by PlaceholderProviderInterface classes. * It uses the PlaceholderProviders provided by PlaceholderProviderInterface classes.
* @package App\Services\LabelSystem
*/ */
final class LabelTextReplacer final class LabelTextReplacer
{ {
@ -39,16 +41,18 @@ final class LabelTextReplacer
/** /**
* Determine the replacement for a single placeholder. It is iterated over all Replacement Providers. * Determine the replacement for a single placeholder. It is iterated over all Replacement Providers.
* If the given string is not a placeholder or the placeholder is not known, it will be returned unchanged. * If the given string is not a placeholder or the placeholder is not known, it will be returned unchanged.
* @param string $placeholder The placeholder that should be replaced. (e.g. '%%PLACEHOLDER%%') *
* @param object $target The object that should be used for the placeholder info source. * @param string $placeholder The placeholder that should be replaced. (e.g. '%%PLACEHOLDER%%')
* @return string If the placeholder was valid, the replaced info. Otherwise the passed string. * @param object $target The object that should be used for the placeholder info source.
*
* @return string If the placeholder was valid, the replaced info. Otherwise the passed string.
*/ */
public function handlePlaceholder(string $placeholder, object $target): string public function handlePlaceholder(string $placeholder, object $target): string
{ {
foreach ($this->providers as $provider) { foreach ($this->providers as $provider) {
/** @var PlaceholderProviderInterface $provider */ /** @var PlaceholderProviderInterface $provider */
$ret = $provider->replace($placeholder, $target); $ret = $provider->replace($placeholder, $target);
if ($ret !== null) { if (null !== $ret) {
return $ret; return $ret;
} }
} }
@ -58,8 +62,10 @@ final class LabelTextReplacer
/** /**
* Replaces all placeholders in the input lines. * Replaces all placeholders in the input lines.
* @param string $lines The input lines that should be replaced *
* @param object $target The object that should be used as source for the informations. * @param string $lines The input lines that should be replaced
* @param object $target The object that should be used as source for the informations.
*
* @return string The Lines with replaced informations. * @return string The Lines with replaced informations.
*/ */
public function replace(string $lines, object $target): string public function replace(string $lines, object $target): string

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Services\LabelSystem\PlaceholderProviders; namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
use App\Services\ElementTypeNameGenerator; use App\Services\ElementTypeNameGenerator;
@ -33,21 +35,16 @@ final class AbstractDBElementProvider implements PlaceholderProviderInterface
$this->elementTypeNameGenerator = $elementTypeNameGenerator; $this->elementTypeNameGenerator = $elementTypeNameGenerator;
} }
/**
* @inheritDoc
*/
public function replace(string $placeholder, object $label_target, array $options = []): ?string public function replace(string $placeholder, object $label_target, array $options = []): ?string
{ {
if ($label_target instanceof AbstractDBElement) { if ($label_target instanceof AbstractDBElement) {
if ('[[TYPE]]' === $placeholder) {
if ($placeholder === '[[TYPE]]') {
return $this->elementTypeNameGenerator->getLocalizedTypeLabel($label_target); return $this->elementTypeNameGenerator->getLocalizedTypeLabel($label_target);
} }
if ($placeholder === '[[ID]]') { if ('[[ID]]' === $placeholder) {
return (string) ($label_target->getID() ?? 'unknown'); return (string) ($label_target->getID() ?? 'unknown');
} }
} }
return null; return null;

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Services\LabelSystem\PlaceholderProviders; namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\UserSystem\User; use App\Entity\UserSystem\User;
use IntlDateFormatter; use IntlDateFormatter;
use Locale; use Locale;
@ -28,11 +30,9 @@ use Symfony\Component\Security\Core\Security;
/** /**
* Provides Placeholders for infos about global infos like Installation name or datetimes. * Provides Placeholders for infos about global infos like Installation name or datetimes.
* @package App\Services\LabelSystem\PlaceholderProviders
*/ */
final class GlobalProviders implements PlaceholderProviderInterface final class GlobalProviders implements PlaceholderProviderInterface
{ {
private $partdb_title; private $partdb_title;
private $security; private $security;
@ -42,34 +42,32 @@ final class GlobalProviders implements PlaceholderProviderInterface
$this->security = $security; $this->security = $security;
} }
/**
* @inheritDoc
*/
public function replace(string $placeholder, object $label_target, array $options = []): ?string public function replace(string $placeholder, object $label_target, array $options = []): ?string
{ {
if ($placeholder === "[[INSTALL_NAME]]") { if ('[[INSTALL_NAME]]' === $placeholder) {
return $this->partdb_title; return $this->partdb_title;
} }
$user = $this->security->getUser(); $user = $this->security->getUser();
if ($placeholder === "[[USERNAME]]") { if ('[[USERNAME]]' === $placeholder) {
if ($user instanceof User) { if ($user instanceof User) {
return $user->getName(); return $user->getName();
} }
return 'anonymous'; return 'anonymous';
} }
if ($placeholder === "[[USERNAME_FULL]]") { if ('[[USERNAME_FULL]]' === $placeholder) {
if ($user instanceof User) { if ($user instanceof User) {
return $user->getFullName(true); return $user->getFullName(true);
} }
return 'anonymous'; return 'anonymous';
} }
$now = new \DateTime(); $now = new \DateTime();
if ($placeholder === '[[DATETIME]]') { if ('[[DATETIME]]' === $placeholder) {
$formatter = IntlDateFormatter::create( $formatter = IntlDateFormatter::create(
Locale::getDefault(), Locale::getDefault(),
IntlDateFormatter::SHORT, IntlDateFormatter::SHORT,
@ -80,7 +78,7 @@ final class GlobalProviders implements PlaceholderProviderInterface
return $formatter->format($now); return $formatter->format($now);
} }
if ($placeholder === '[[DATE]]') { if ('[[DATE]]' === $placeholder) {
$formatter = IntlDateFormatter::create( $formatter = IntlDateFormatter::create(
Locale::getDefault(), Locale::getDefault(),
IntlDateFormatter::SHORT, IntlDateFormatter::SHORT,
@ -91,7 +89,7 @@ final class GlobalProviders implements PlaceholderProviderInterface
return $formatter->format($now); return $formatter->format($now);
} }
if ($placeholder === '[[TIME]]') { if ('[[TIME]]' === $placeholder) {
$formatter = IntlDateFormatter::create( $formatter = IntlDateFormatter::create(
Locale::getDefault(), Locale::getDefault(),
IntlDateFormatter::NONE, IntlDateFormatter::NONE,

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,18 +23,13 @@
namespace App\Services\LabelSystem\PlaceholderProviders; namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Contracts\NamedElementInterface; use App\Entity\Contracts\NamedElementInterface;
final class NamedElementProvider implements PlaceholderProviderInterface final class NamedElementProvider implements PlaceholderProviderInterface
{ {
/**
* @inheritDoc
*/
public function replace(string $placeholder, object $label_target, array $options = []): ?string public function replace(string $placeholder, object $label_target, array $options = []): ?string
{ {
if ($label_target instanceof NamedElementInterface && $placeholder === '[[NAME]]') { if ($label_target instanceof NamedElementInterface && '[[NAME]]' === $placeholder) {
return $label_target->getName(); return $label_target->getName();
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Services\LabelSystem\PlaceholderProviders; namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Services\AmountFormatter; use App\Services\AmountFormatter;
use App\Services\LabelSystem\LabelTextReplacer; use App\Services\LabelSystem\LabelTextReplacer;
@ -41,20 +43,20 @@ final class PartLotProvider implements PlaceholderProviderInterface
public function replace(string $placeholder, object $label_target, array $options = []): ?string public function replace(string $placeholder, object $label_target, array $options = []): ?string
{ {
if ($label_target instanceof PartLot) { if ($label_target instanceof PartLot) {
if ($placeholder === '[[LOT_ID]]') { if ('[[LOT_ID]]' === $placeholder) {
return $label_target->getID() ?? 'unknown'; return $label_target->getID() ?? 'unknown';
} }
if ($placeholder === '[[LOT_NAME]]') { if ('[[LOT_NAME]]' === $placeholder) {
return $label_target->getName(); return $label_target->getName();
} }
if ($placeholder === '[[LOT_COMMENT]]') { if ('[[LOT_COMMENT]]' === $placeholder) {
return $label_target->getComment(); return $label_target->getComment();
} }
if ($placeholder === '[[EXPIRATION_DATE]]') { if ('[[EXPIRATION_DATE]]' === $placeholder) {
if ($label_target->getExpirationDate() === null) { if (null === $label_target->getExpirationDate()) {
return ''; return '';
} }
$formatter = IntlDateFormatter::create( $formatter = IntlDateFormatter::create(
@ -67,22 +69,22 @@ final class PartLotProvider implements PlaceholderProviderInterface
return $formatter->format($label_target->getExpirationDate()); return $formatter->format($label_target->getExpirationDate());
} }
if ($placeholder === '[[AMOUNT]]') { if ('[[AMOUNT]]' === $placeholder) {
if ($label_target->isInstockUnknown()) { if ($label_target->isInstockUnknown()) {
return '?'; return '?';
} }
return $this->amountFormatter->format($label_target->getAmount(), $label_target->getPart()->getPartUnit()); return $this->amountFormatter->format($label_target->getAmount(), $label_target->getPart()->getPartUnit());
} }
if ($placeholder === '[[LOCATION]]') { if ('[[LOCATION]]' === $placeholder) {
return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getName() : ''; return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getName() : '';
} }
if ($placeholder === '[[LOCATION_FULL]]') { if ('[[LOCATION_FULL]]' === $placeholder) {
return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getFullPath() : ''; return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getFullPath() : '';
} }
return $this->labelTextReplacer->handlePlaceholder($placeholder, $label_target->getPart()); return $this->labelTextReplacer->handlePlaceholder($placeholder, $label_target->getPart());
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,14 +23,12 @@
namespace App\Services\LabelSystem\PlaceholderProviders; namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Services\SIFormatter; use App\Services\SIFormatter;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
final class PartProvider implements PlaceholderProviderInterface final class PartProvider implements PlaceholderProviderInterface
{ {
private $siFormatter; private $siFormatter;
private $translator; private $translator;
@ -37,73 +38,71 @@ final class PartProvider implements PlaceholderProviderInterface
$this->translator = $translator; $this->translator = $translator;
} }
/**
* @inheritDoc
*/
public function replace(string $placeholder, object $part, array $options = []): ?string public function replace(string $placeholder, object $part, array $options = []): ?string
{ {
if (!$part instanceof Part) { if (! $part instanceof Part) {
return null; return null;
} }
if ($placeholder === '[[CATEGORY]]') { if ('[[CATEGORY]]' === $placeholder) {
return $part->getCategory() ? $part->getCategory()->getName() : ''; return $part->getCategory() ? $part->getCategory()->getName() : '';
} }
if ($placeholder === '[[CATEGORY_FULL]]') { if ('[[CATEGORY_FULL]]' === $placeholder) {
return $part->getCategory() ? $part->getCategory()->getFullPath() : ''; return $part->getCategory() ? $part->getCategory()->getFullPath() : '';
} }
if ($placeholder === '[[MANUFACTURER]]') { if ('[[MANUFACTURER]]' === $placeholder) {
return $part->getManufacturer() ? $part->getManufacturer()->getName() : ''; return $part->getManufacturer() ? $part->getManufacturer()->getName() : '';
} }
if ($placeholder === '[[MANUFACTURER_FULL]]') { if ('[[MANUFACTURER_FULL]]' === $placeholder) {
return $part->getManufacturer() ? $part->getManufacturer()->getFullPath() : ''; return $part->getManufacturer() ? $part->getManufacturer()->getFullPath() : '';
} }
if ($placeholder === '[[FOOTPRINT]]') { if ('[[FOOTPRINT]]' === $placeholder) {
return $part->getFootprint() ? $part->getFootprint()->getName() : ''; return $part->getFootprint() ? $part->getFootprint()->getName() : '';
} }
if ($placeholder === '[[FOOTPRINT_FULL]]') { if ('[[FOOTPRINT_FULL]]' === $placeholder) {
return $part->getFootprint() ? $part->getFootprint()->getFullPath() : ''; return $part->getFootprint() ? $part->getFootprint()->getFullPath() : '';
} }
if ($placeholder === '[[MASS]]') { if ('[[MASS]]' === $placeholder) {
return $part->getMass() ? $this->siFormatter->format($part->getMass(), 'g', 1) : ''; return $part->getMass() ? $this->siFormatter->format($part->getMass(), 'g', 1) : '';
} }
if ($placeholder === '[[MPN]]') { if ('[[MPN]]' === $placeholder) {
return $part->getManufacturerProductNumber(); return $part->getManufacturerProductNumber();
} }
if ($placeholder === '[[TAGS]]') { if ('[[TAGS]]' === $placeholder) {
return $part->getTags(); return $part->getTags();
} }
if ($placeholder === '[[M_STATUS]]') { if ('[[M_STATUS]]' === $placeholder) {
if ($part->getManufacturingStatus() === '') { if ('' === $part->getManufacturingStatus()) {
return ''; return '';
} }
return $this->translator->trans('m_status.' . $part->getManufacturingStatus());
return $this->translator->trans('m_status.'.$part->getManufacturingStatus());
} }
$parsedown = new \Parsedown(); $parsedown = new \Parsedown();
if ($placeholder === '[[DESCRIPTION]]') { if ('[[DESCRIPTION]]' === $placeholder) {
return $parsedown->line($part->getDescription()); return $parsedown->line($part->getDescription());
} }
if ($placeholder === '[[DESCRIPTION_T]]') { if ('[[DESCRIPTION_T]]' === $placeholder) {
return strip_tags($parsedown->line($part->getDescription())); return strip_tags($parsedown->line($part->getDescription()));
} }
if ($placeholder === '[[COMMENT]]') { if ('[[COMMENT]]' === $placeholder) {
return $parsedown->line($part->getComment()); return $parsedown->line($part->getComment());
} }
if ($placeholder === '[[COMMENT_T]]') { if ('[[COMMENT_T]]' === $placeholder) {
return strip_tags($parsedown->line($part->getComment())); return strip_tags($parsedown->line($part->getComment()));
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,16 +23,16 @@
namespace App\Services\LabelSystem\PlaceholderProviders; namespace App\Services\LabelSystem\PlaceholderProviders;
interface PlaceholderProviderInterface interface PlaceholderProviderInterface
{ {
/** /**
* Determines the real value of this placeholder. * Determines the real value of this placeholder.
* If the placeholder is not supported, null must be returned. * If the placeholder is not supported, null must be returned.
* @param string $placeholder The placeholder (e.g. "%%PLACEHOLDER%%") that should be replaced *
* @param object $label_target The object that is targeted by the label * @param string $placeholder The placeholder (e.g. "%%PLACEHOLDER%%") that should be replaced
* @param array $options A list of options that can be used to specify the generated output further. * @param object $label_target The object that is targeted by the label
* @param array $options A list of options that can be used to specify the generated output further.
*
* @return string|null The real value of this placeholder, null if not supported. * @return string|null The real value of this placeholder, null if not supported.
*/ */
public function replace(string $placeholder, object $label_target, array $options = []): ?string; public function replace(string $placeholder, object $label_target, array $options = []): ?string;

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,29 +23,26 @@
namespace App\Services\LabelSystem\PlaceholderProviders; namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\Base\AbstractStructuralDBElement;
final class StructuralDBElementProvider implements PlaceholderProviderInterface final class StructuralDBElementProvider implements PlaceholderProviderInterface
{ {
public function replace(string $placeholder, object $label_target, array $options = []): ?string public function replace(string $placeholder, object $label_target, array $options = []): ?string
{ {
if ($label_target instanceof AbstractStructuralDBElement) { if ($label_target instanceof AbstractStructuralDBElement) {
if ($placeholder === '[[COMMENT]]') { if ('[[COMMENT]]' === $placeholder) {
return $label_target->getComment(); return $label_target->getComment();
} }
if ($placeholder === '[[COMMENT_T]]') { if ('[[COMMENT_T]]' === $placeholder) {
return strip_tags($label_target->getComment()); return strip_tags($label_target->getComment());
} }
if ($placeholder === '[[FULL_PATH]]') { if ('[[FULL_PATH]]' === $placeholder) {
return $label_target->getFullPath(); return $label_target->getFullPath();
} }
if ($placeholder === '[[PARENT]]') { if ('[[PARENT]]' === $placeholder) {
return $label_target->getParent() ? $label_target->getParent()->getName() : ''; return $label_target->getParent() ? $label_target->getParent()->getName() : '';
} }
if ($placeholder === '[[PARENT_FULL_PATH]]') { if ('[[PARENT_FULL_PATH]]' === $placeholder) {
return $label_target->getParent() ? $label_target->getParent()->getFullPath() : ''; return $label_target->getParent() ? $label_target->getParent()->getFullPath() : '';
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -26,21 +29,16 @@ use Locale;
final class TimestampableElementProvider implements PlaceholderProviderInterface final class TimestampableElementProvider implements PlaceholderProviderInterface
{ {
/**
* @inheritDoc
*/
public function replace(string $placeholder, object $label_target, array $options = []): ?string public function replace(string $placeholder, object $label_target, array $options = []): ?string
{ {
if ($label_target instanceof TimeStampableInterface) { if ($label_target instanceof TimeStampableInterface) {
if ($placeholder === '[[LAST_MODIFIED]]') { if ('[[LAST_MODIFIED]]' === $placeholder) {
return IntlDateFormatter::formatObject($label_target->getLastModified() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault()); return IntlDateFormatter::formatObject($label_target->getLastModified() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault());
} }
if ($placeholder === '[[CREATION_DATE]]') { if ('[[CREATION_DATE]]' === $placeholder) {
return IntlDateFormatter::formatObject($label_target->getAddedDate() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault()); return IntlDateFormatter::formatObject($label_target->getAddedDate() ?? new \DateTime(), IntlDateFormatter::SHORT, Locale::getDefault());
} }
} }
return null; return null;

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,12 +23,10 @@
namespace App\Services\LabelSystem; namespace App\Services\LabelSystem;
use App\Entity\Attachments\Attachment; use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentContainingDBElement; use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Base\AbstractCompany; use App\Entity\Base\AbstractCompany;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Contracts\NamedElementInterface; use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\TimeStampableInterface; use App\Entity\Contracts\TimeStampableInterface;
@ -45,7 +46,6 @@ use App\Twig\Sandbox\InheritanceSecurityPolicy;
use Twig\Environment; use Twig\Environment;
use Twig\Extension\SandboxExtension; use Twig\Extension\SandboxExtension;
use Twig\Extra\Intl\IntlExtension; use Twig\Extra\Intl\IntlExtension;
use Twig\Sandbox\SecurityPolicy;
use Twig\Sandbox\SecurityPolicyInterface; use Twig\Sandbox\SecurityPolicyInterface;
final class SandboxedTwigProvider final class SandboxedTwigProvider
@ -58,7 +58,7 @@ final class SandboxedTwigProvider
'reduce', 'replace', 'reverse', 'slice', 'sort', 'spaceless', 'split', 'striptags', 'timezone_name', 'title', 'reduce', 'replace', 'reverse', 'slice', 'sort', 'spaceless', 'split', 'striptags', 'timezone_name', 'title',
'trim', 'upper', 'url_encode', 'trim', 'upper', 'url_encode',
//Part-DB specific filters: //Part-DB specific filters:
'moneyFormat', 'siFormat', 'amountFormat']; 'moneyFormat', 'siFormat', 'amountFormat', ];
private const ALLOWED_FUNCTIONS = ['date', 'html_classes', 'max', 'min', 'random', 'range']; private const ALLOWED_FUNCTIONS = ['date', 'html_classes', 'max', 'min', 'random', 'range'];
@ -67,31 +67,30 @@ final class SandboxedTwigProvider
AbstractDBElement::class => ['getID', '__toString'], AbstractDBElement::class => ['getID', '__toString'],
TimeStampableInterface::class => ['getLastModified', 'getAddedDate'], TimeStampableInterface::class => ['getLastModified', 'getAddedDate'],
AbstractStructuralDBElement::class => ['isChildOf', 'isRoot', 'getParent', 'getComment', 'getLevel', AbstractStructuralDBElement::class => ['isChildOf', 'isRoot', 'getParent', 'getComment', 'getLevel',
'getFullPath', 'getPathArray', 'getChildren', 'isNotSelectable'], 'getFullPath', 'getPathArray', 'getChildren', 'isNotSelectable', ],
AbstractCompany::class => ['getAddress', 'getPhoneNumber', 'getFaxNumber', 'getEmailAddress', 'getWebsite'], AbstractCompany::class => ['getAddress', 'getPhoneNumber', 'getFaxNumber', 'getEmailAddress', 'getWebsite'],
AttachmentContainingDBElement::class => ['getAttachments', 'getMasterPictureAttachment'], AttachmentContainingDBElement::class => ['getAttachments', 'getMasterPictureAttachment'],
Attachment::class => ['isPicture', 'is3DModel', 'isExternal', 'isSecure', 'isBuiltIn', 'getExtension', Attachment::class => ['isPicture', 'is3DModel', 'isExternal', 'isSecure', 'isBuiltIn', 'getExtension',
'getElement', 'getURL', 'getFilename', 'getAttachmentType', 'getShowInTable'], 'getElement', 'getURL', 'getFilename', 'getAttachmentType', 'getShowInTable', ],
AbstractParameter::class => ['getFormattedValue', 'getGroup', 'getSymbol', 'getValueMin', 'getValueMax', AbstractParameter::class => ['getFormattedValue', 'getGroup', 'getSymbol', 'getValueMin', 'getValueMax',
'getValueTypical', 'getUnit', 'getValueText'], 'getValueTypical', 'getUnit', 'getValueText', ],
MeasurementUnit::class => ['getUnit', 'isInteger', 'useSIPrefix'], MeasurementUnit::class => ['getUnit', 'isInteger', 'useSIPrefix'],
PartLot::class => ['isExpired', 'getDescription', 'getComment', 'getExpirationDate', 'getStorageLocation', PartLot::class => ['isExpired', 'getDescription', 'getComment', 'getExpirationDate', 'getStorageLocation',
'getPart', 'isInstockUnknown', 'getAmount', 'getNeedsRefill'], 'getPart', 'isInstockUnknown', 'getAmount', 'getNeedsRefill', ],
Storelocation::class => ['isFull', 'isOnlySinglePart', 'isLimitToExistingParts', 'getStorageType'], Storelocation::class => ['isFull', 'isOnlySinglePart', 'isLimitToExistingParts', 'getStorageType'],
Supplier::class => ['getShippingCosts', 'getDefaultCurrency'], Supplier::class => ['getShippingCosts', 'getDefaultCurrency'],
Part::class => ['isNeedsReview', 'getTags', 'getMass', 'getDescription', 'isFavorite', 'getCategory', Part::class => ['isNeedsReview', 'getTags', 'getMass', 'getDescription', 'isFavorite', 'getCategory',
'getFootprint', 'getPartLots', 'getPartUnit', 'useFloatAmount', 'getMinAmount', 'getAmountSum', 'getFootprint', 'getPartLots', 'getPartUnit', 'useFloatAmount', 'getMinAmount', 'getAmountSum',
'getManufacturerProductUrl', 'getCustomProductURL', 'getManufacturingStatus', 'getManufacturer', 'getManufacturerProductUrl', 'getCustomProductURL', 'getManufacturingStatus', 'getManufacturer',
'getManufacturerProductNumber', 'getOrderdetails', 'isObsolete'], 'getManufacturerProductNumber', 'getOrderdetails', 'isObsolete', ],
Currency::class => ['getIsoCode', 'getInverseExchangeRate', 'getExchangeRate'], Currency::class => ['getIsoCode', 'getInverseExchangeRate', 'getExchangeRate'],
Orderdetail::class => ['getPart', 'getSupplier', 'getSupplierPartNr', 'getObsolete', Orderdetail::class => ['getPart', 'getSupplier', 'getSupplierPartNr', 'getObsolete',
'getPricedetails', 'findPriceForQty', ], 'getPricedetails', 'findPriceForQty', ],
Pricedetail::class => ['getOrderdetail', 'getPrice', 'getPricePerUnit', 'getPriceRelatedQuantity', Pricedetail::class => ['getOrderdetail', 'getPrice', 'getPricePerUnit', 'getPriceRelatedQuantity',
'getMinDiscountQuantity', 'getCurrency'], 'getMinDiscountQuantity', 'getCurrency', ],
//Only allow very little information about users... //Only allow very little information about users...
User::class => ['isAnonymousUser', 'getUsername', 'getFullName', 'getFirstName', 'getLastName', User::class => ['isAnonymousUser', 'getUsername', 'getFullName', 'getFirstName', 'getLastName',
'getDepartment', 'getEmail'] 'getDepartment', 'getEmail', ],
]; ];
private const ALLOWED_PROPERTIES = []; private const ALLOWED_PROPERTIES = [];
@ -104,14 +103,13 @@ final class SandboxedTwigProvider
public function getTwig(LabelOptions $options): Environment public function getTwig(LabelOptions $options): Environment
{ {
if ($options->getLinesMode() !== 'twig') { if ('twig' !== $options->getLinesMode()) {
throw new \InvalidArgumentException('The LabelOptions must explicitly allow twig via lines_mode = "twig"!'); throw new \InvalidArgumentException('The LabelOptions must explicitly allow twig via lines_mode = "twig"!');
} }
$loader = new \Twig\Loader\ArrayLoader([ $loader = new \Twig\Loader\ArrayLoader([
'lines' => $options->getLines(), 'lines' => $options->getLines(),
]); ]);
$twig = new Environment($loader); $twig = new Environment($loader);
//Second argument activate sandbox globally. //Second argument activate sandbox globally.
@ -127,7 +125,7 @@ final class SandboxedTwigProvider
return $twig; return $twig;
} }
protected function getSecurityPolicy(): SecurityPolicyInterface private function getSecurityPolicy(): SecurityPolicyInterface
{ {
return new InheritanceSecurityPolicy( return new InheritanceSecurityPolicy(
self::ALLOWED_TAGS, self::ALLOWED_TAGS,

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -21,13 +24,15 @@
namespace App\Services\Misc; namespace App\Services\Misc;
/** /**
* This Parser allows to parse number ranges like 1-3, 4, 5 * This Parser allows to parse number ranges like 1-3, 4, 5.
*/ */
class RangeParser class RangeParser
{ {
/** /**
* Converts the given range string to an array of all numbers in the given range. * Converts the given range string to an array of all numbers in the given range.
* @param string $range_str A range string like '1-3, 5, 6' *
* @param string $range_str A range string like '1-3, 5, 6'
*
* @return int[] An array with all numbers from the range (e.g. [1, 2, 3, 5, 6] * @return int[] An array with all numbers from the range (e.g. [1, 2, 3, 5, 6]
*/ */
public function parse(string $range_str): array public function parse(string $range_str): array
@ -48,7 +53,7 @@ class RangeParser
} elseif (empty($number)) { //Allow empty tokens } elseif (empty($number)) { //Allow empty tokens
continue; continue;
} else { } else {
throw new \InvalidArgumentException('Invalid range encoutered: ' . $number); throw new \InvalidArgumentException('Invalid range encoutered: '.$number);
} }
} }
@ -58,13 +63,16 @@ class RangeParser
/** /**
* Checks if the given string is a valid range. * Checks if the given string is a valid range.
* @param string $range_str The string that should be checked *
* @param string $range_str The string that should be checked
*
* @return bool True if the string is valid, false if not. * @return bool True if the string is valid, false if not.
*/ */
public function isValidRange(string $range_str): bool public function isValidRange(string $range_str): bool
{ {
try { try {
$this->parse($range_str); $this->parse($range_str);
return true; return true;
} catch (\InvalidArgumentException $exception) { } catch (\InvalidArgumentException $exception) {
return false; return false;
@ -86,8 +94,8 @@ class RangeParser
$tmp = []; $tmp = [];
while ($min <= $max) { while ($min <= $max) {
$tmp[] = $min; $tmp[] = $min;
$min++; ++$min;
}; }
return $tmp; return $tmp;
} }

View file

@ -105,6 +105,7 @@ class SIFormatter
* @param float $value The value that should be converted * @param float $value The value that should be converted
* @param string $unit The unit that should be appended after the prefix * @param string $unit The unit that should be appended after the prefix
* @param int $decimals the number of decimals (after decimal dot) that should be outputed * @param int $decimals the number of decimals (after decimal dot) that should be outputed
*
* @return string The formatted value * @return string The formatted value
*/ */
public function format(float $value, string $unit = '', int $decimals = 2): string public function format(float $value, string $unit = '', int $decimals = 2): string

View file

@ -211,7 +211,6 @@ class ToolsTreeBuilder
); );
} }
return $nodes; return $nodes;
} }

View file

@ -118,13 +118,13 @@ class TreeViewGenerator
$item->addTag((string) \count($item->getNodes())); $item->addTag((string) \count($item->getNodes()));
} }
if (! empty($href_type) && $item->getId() !== null) { if (! empty($href_type) && null !== $item->getId()) {
$entity = $this->em->getPartialReference($class, $item->getId()); $entity = $this->em->getPartialReference($class, $item->getId());
$item->setHref($this->urlGenerator->getURL($entity, $href_type)); $item->setHref($this->urlGenerator->getURL($entity, $href_type));
} }
//Translate text if text starts with $$ //Translate text if text starts with $$
if (substr($item->getText(), 0, 2) === '$$') { if ('$$' === substr($item->getText(), 0, 2)) {
$item->setText($this->translator->trans(substr($item->getText(), 2))); $item->setText($this->translator->trans(substr($item->getText(), 2)));
} }
} }

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
/* /*
* This file is part of Twig. * This file is part of Twig.
* *
@ -75,19 +77,19 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
public function checkSecurity($tags, $filters, $functions): void public function checkSecurity($tags, $filters, $functions): void
{ {
foreach ($tags as $tag) { foreach ($tags as $tag) {
if (!\in_array($tag, $this->allowedTags)) { if (! \in_array($tag, $this->allowedTags, true)) {
throw new SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); throw new SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag);
} }
} }
foreach ($filters as $filter) { foreach ($filters as $filter) {
if (!\in_array($filter, $this->allowedFilters)) { if (! \in_array($filter, $this->allowedFilters, true)) {
throw new SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); throw new SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter);
} }
} }
foreach ($functions as $function) { foreach ($functions as $function) {
if (!\in_array($function, $this->allowedFunctions)) { if (! \in_array($function, $this->allowedFunctions, true)) {
throw new SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); throw new SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function);
} }
} }
@ -103,7 +105,7 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
$method = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); $method = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
foreach ($this->allowedMethods as $class => $methods) { foreach ($this->allowedMethods as $class => $methods) {
if ($obj instanceof $class) { if ($obj instanceof $class) {
$allowed = \in_array($method, $methods); $allowed = \in_array($method, $methods, true);
//CHANGED: Only break if we the method is allowed, otherwise try it on the other methods //CHANGED: Only break if we the method is allowed, otherwise try it on the other methods
if ($allowed) { if ($allowed) {
@ -112,8 +114,9 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
} }
} }
if (!$allowed) { if (! $allowed) {
$class = \get_class($obj); $class = \get_class($obj);
throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method);
} }
} }
@ -123,7 +126,7 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
$allowed = false; $allowed = false;
foreach ($this->allowedProperties as $class => $properties) { foreach ($this->allowedProperties as $class => $properties) {
if ($obj instanceof $class) { if ($obj instanceof $class) {
$allowed = \in_array($property, \is_array($properties) ? $properties : [$properties]); $allowed = \in_array($property, \is_array($properties) ? $properties : [$properties], true);
//CHANGED: Only break if we the method is allowed, otherwise try it on the other methods //CHANGED: Only break if we the method is allowed, otherwise try it on the other methods
if ($allowed) { if ($allowed) {
@ -132,8 +135,9 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
} }
} }
if (!$allowed) { if (! $allowed) {
$class = \get_class($obj); $class = \get_class($obj);
throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property);
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,12 +23,10 @@
namespace App\Validator\Constraints\Misc; namespace App\Validator\Constraints\Misc;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
/** /**
* @Annotation * @Annotation
* @package App\Validator\Constraints\Misc
*/ */
class ValidRange extends Constraint class ValidRange extends Constraint
{ {

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Validator\Constraints\Misc; namespace App\Validator\Constraints\Misc;
use App\Services\Misc\RangeParser; use App\Services\Misc\RangeParser;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\ConstraintValidator;
@ -29,7 +31,6 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException;
class ValidRangeValidator extends ConstraintValidator class ValidRangeValidator extends ConstraintValidator
{ {
protected $rangeParser; protected $rangeParser;
public function __construct(RangeParser $rangeParser) public function __construct(RangeParser $rangeParser)
@ -37,9 +38,9 @@ class ValidRangeValidator extends ConstraintValidator
$this->rangeParser = $rangeParser; $this->rangeParser = $rangeParser;
} }
public function validate($value, Constraint $constraint) public function validate($value, Constraint $constraint): void
{ {
if (!$constraint instanceof ValidRange) { if (! $constraint instanceof ValidRange) {
throw new UnexpectedTypeException($constraint, ValidRange::class); throw new UnexpectedTypeException($constraint, ValidRange::class);
} }
@ -49,11 +50,11 @@ class ValidRangeValidator extends ConstraintValidator
return; return;
} }
if (!is_string($value)) { if (! is_string($value)) {
throw new UnexpectedValueException($value, 'string'); throw new UnexpectedValueException($value, 'string');
} }
if(!$this->rangeParser->isValidRange($value)) { if (! $this->rangeParser->isValidRange($value)) {
$this->context->buildViolation($constraint->message) $this->context->buildViolation($constraint->message)
->addViolation(); ->addViolation();
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,7 +23,6 @@
namespace App\Tests\Controller\AdminPages; namespace App\Tests\Controller\AdminPages;
use App\Entity\LabelSystem\LabelProfile; use App\Entity\LabelSystem\LabelProfile;
use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Exception\AccessDeniedException;

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -23,16 +26,16 @@ namespace App\Tests\Services\LabelSystem;
use App\Entity\LabelSystem\LabelOptions; use App\Entity\LabelSystem\LabelOptions;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Services\LabelSystem\BarcodeGenerator; use App\Services\LabelSystem\BarcodeGenerator;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
final class BarcodeGeneratorTest extends WebTestCase final class BarcodeGeneratorTest extends WebTestCase
{ {
/**
/** @var BarcodeGenerator */ * @var BarcodeGenerator
*/
protected $services; protected $services;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->services = self::$container->get(BarcodeGenerator::class); $this->services = self::$container->get(BarcodeGenerator::class);
@ -50,7 +53,7 @@ final class BarcodeGeneratorTest extends WebTestCase
$content = $this->services->generateSVG($options, $part); $content = $this->services->generateSVG($options, $part);
//When type is none, service must return null. //When type is none, service must return null.
if ($type === 'none') { if ('none' === $type) {
$this->assertNull($content); $this->assertNull($content);
} else { } else {
$this->assertIsString($content); $this->assertIsString($content);
@ -70,10 +73,10 @@ final class BarcodeGeneratorTest extends WebTestCase
$svg = $this->services->generateSVG($options, $part); $svg = $this->services->generateSVG($options, $part);
//When type is none, service must return null. //When type is none, service must return null.
if ($type === "none") { if ('none' === $type) {
$this->assertNull($svg); $this->assertNull($svg);
} else { } else {
$this->assertStringContainsStringIgnoringCase("SVG", $svg); $this->assertStringContainsStringIgnoringCase('SVG', $svg);
} }
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -24,21 +27,21 @@ use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation; use App\Entity\Parts\Storelocation;
use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator; use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class BarcodeContentGeneratorTest extends KernelTestCase class BarcodeContentGeneratorTest extends KernelTestCase
{ {
/** @var BarcodeContentGenerator */ /**
* @var BarcodeContentGenerator
*/
private $service; private $service;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->service = self::$container->get(BarcodeContentGenerator::class); $this->service = self::$container->get(BarcodeContentGenerator::class);
} }
public function Barcode1DDataProvider(): array public function Barcode1DDataProvider(): array
{ {
return [ return [
@ -53,7 +56,7 @@ class BarcodeContentGeneratorTest extends KernelTestCase
return [ return [
['/scan/part/0', Part::class], ['/scan/part/0', Part::class],
['/scan/lot/0', PartLot::class], ['/scan/lot/0', PartLot::class],
['/scan/location/0', Storelocation::class] ['/scan/location/0', Storelocation::class],
]; ];
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -21,16 +24,16 @@
namespace App\Tests\Services\LabelSystem\Barcodes; namespace App\Tests\Services\LabelSystem\Barcodes;
use App\Services\LabelSystem\Barcodes\BarcodeNormalizer; use App\Services\LabelSystem\Barcodes\BarcodeNormalizer;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BarcodeNormalizerTest extends WebTestCase class BarcodeNormalizerTest extends WebTestCase
{ {
/**
/** @var BarcodeNormalizer */ * @var BarcodeNormalizer
*/
protected $service; protected $service;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->service = self::$container->get(BarcodeNormalizer::class); $this->service = self::$container->get(BarcodeNormalizer::class);
@ -80,7 +83,7 @@ class BarcodeNormalizerTest extends WebTestCase
/** /**
* @dataProvider dataProvider * @dataProvider dataProvider
*/ */
public function testNormalizeBarcodeContent(array $expected, string $input) public function testNormalizeBarcodeContent(array $expected, string $input): void
{ {
$this->assertSame($expected, $this->service->normalizeBarcodeContent($input)); $this->assertSame($expected, $this->service->normalizeBarcodeContent($input));
} }
@ -88,7 +91,7 @@ class BarcodeNormalizerTest extends WebTestCase
/** /**
* @dataProvider invalidDataProvider * @dataProvider invalidDataProvider
*/ */
public function testInvalidFormats(string $input) public function testInvalidFormats(string $input): void
{ {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
$this->service->normalizeBarcodeContent($input); $this->service->normalizeBarcodeContent($input);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -22,15 +25,16 @@ namespace App\Tests\Services\LabelSystem\Barcodes;
use App\Services\LabelSystem\Barcodes\BarcodeRedirector; use App\Services\LabelSystem\Barcodes\BarcodeRedirector;
use Doctrine\ORM\EntityNotFoundException; use Doctrine\ORM\EntityNotFoundException;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class BarcodeRedirectorTest extends KernelTestCase class BarcodeRedirectorTest extends KernelTestCase
{ {
/** @var BarcodeRedirector */ /**
* @var BarcodeRedirector
*/
private $service; private $service;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->service = self::$container->get(BarcodeRedirector::class); $this->service = self::$container->get(BarcodeRedirector::class);
@ -42,7 +46,7 @@ class BarcodeRedirectorTest extends KernelTestCase
['part', '/en/part/1'], ['part', '/en/part/1'],
//Part lot redirects to Part info page (Part lot 1 is associated with part 3 //Part lot redirects to Part info page (Part lot 1 is associated with part 3
['lot', '/en/part/3'], ['lot', '/en/part/3'],
['location', '/en/store_location/1/parts'] ['location', '/en/store_location/1/parts'],
]; ];
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -26,15 +29,16 @@ use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation; use App\Entity\Parts\Storelocation;
use App\Services\LabelSystem\LabelGenerator; use App\Services\LabelSystem\LabelGenerator;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class LabelGeneratorTest extends WebTestCase class LabelGeneratorTest extends WebTestCase
{ {
/** @var LabelGenerator */ /**
* @var LabelGenerator
*/
protected $service; protected $service;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->service = self::$container->get(LabelGenerator::class); $this->service = self::$container->get(LabelGenerator::class);
@ -45,14 +49,14 @@ class LabelGeneratorTest extends WebTestCase
return [ return [
['part', Part::class], ['part', Part::class],
['part_lot', PartLot::class], ['part_lot', PartLot::class],
['storelocation', Storelocation::class] ['storelocation', Storelocation::class],
]; ];
} }
/** /**
* @dataProvider supportsDataProvider * @dataProvider supportsDataProvider
*/ */
public function testSupports(string $type, string $class) public function testSupports(string $type, string $class): void
{ {
$options = new LabelOptions(); $options = new LabelOptions();
$options->setSupportedElement($type); $options->setSupportedElement($type);
@ -61,18 +65,17 @@ class LabelGeneratorTest extends WebTestCase
$this->assertTrue($this->service->supports($options, new $class())); $this->assertTrue($this->service->supports($options, new $class()));
//Ensure that another class is not supported //Ensure that another class is not supported
$not_supported = new class extends AbstractDBElement { $not_supported = new class() extends AbstractDBElement {
public function getIDString(): string public function getIDString(): string
{ {
return "not_important"; return 'not_important';
} }
}; };
$this->assertFalse($this->service->supports($options, $not_supported)); $this->assertFalse($this->service->supports($options, $not_supported));
} }
public function testMmToPointsArray() public function testMmToPointsArray(): void
{ {
$this->assertSame( $this->assertSame(
[0.0, 0.0, 141.7325, 85.0395], [0.0, 0.0, 141.7325, 85.0395],
@ -80,7 +83,7 @@ class LabelGeneratorTest extends WebTestCase
); );
} }
public function testGenerateLabel() public function testGenerateLabel(): void
{ {
$part = new Part(); $part = new Part();
$options = new LabelOptions(); $options = new LabelOptions();

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -22,20 +25,19 @@ namespace App\Tests\Services\LabelSystem;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Services\AmountFormatter;
use App\Services\LabelSystem\LabelTextReplacer; use App\Services\LabelSystem\LabelTextReplacer;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class LabelTextReplacerTest extends WebTestCase class LabelTextReplacerTest extends WebTestCase
{ {
/** /**
* @var LabelTextReplacer * @var LabelTextReplacer
*/ */
protected $service; protected $service;
/** @var Part */ /**
* @var Part
*/
protected $target; protected $target;
protected function setUp(): void protected function setUp(): void
@ -76,7 +78,7 @@ class LabelTextReplacerTest extends WebTestCase
['[[UNKNOWN]] Test', '[[UNKNOWN]] Test'], ['[[UNKNOWN]] Test', '[[UNKNOWN]] Test'],
["[[NAME\n]] [[NAME ]]", "[[NAME\n]] [[NAME ]]"], ["[[NAME\n]] [[NAME ]]", "[[NAME\n]] [[NAME ]]"],
['[[]]', '[[]]'], ['[[]]', '[[]]'],
['TEST[[ ]]TEST', 'TEST[[ ]]TEST'] ['TEST[[ ]]TEST', 'TEST[[ ]]TEST'],
]; ];
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -21,29 +24,25 @@
namespace App\Tests\Services\LabelSystem\PlaceholderProviders; namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Base\AbstractDBElement; use App\Entity\Base\AbstractDBElement;
use App\Entity\Parts\Part;
use App\Services\LabelSystem\PlaceholderProviders\AbstractDBElementProvider; use App\Services\LabelSystem\PlaceholderProviders\AbstractDBElementProvider;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class AbstractElementProviderTest extends WebTestCase class AbstractElementProviderTest extends WebTestCase
{ {
/** @var AbstractDBElementProvider */ /**
* @var AbstractDBElementProvider
*/
protected $service; protected $service;
protected $target; protected $target;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->service = self::$container->get(AbstractDBElementProvider::class); $this->service = self::$container->get(AbstractDBElementProvider::class);
$this->target = new class extends AbstractDBElement { $this->target = new class() extends AbstractDBElement {
protected $id = 123; protected $id = 123;
/**
* @inheritDoc
*/
public function getIDString(): string public function getIDString(): string
{ {
return 'ignore'; return 'ignore';

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -22,17 +25,18 @@ namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders; use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class GlobalProvidersTest extends WebTestCase class GlobalProvidersTest extends WebTestCase
{ {
/** @var GlobalProviders */ /**
* @var GlobalProviders
*/
protected $service; protected $service;
protected $target; protected $target;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->service = self::$container->get(GlobalProviders::class); $this->service = self::$container->get(GlobalProviders::class);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -21,28 +24,23 @@
namespace App\Tests\Services\LabelSystem\PlaceholderProviders; namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Contracts\NamedElementInterface; use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Parts\Part;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use App\Services\LabelSystem\PlaceholderProviders\NamedElementProvider; use App\Services\LabelSystem\PlaceholderProviders\NamedElementProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class NamedElementProviderTest extends WebTestCase class NamedElementProviderTest extends WebTestCase
{ {
/** @var NamedElementProvider */ /**
* @var NamedElementProvider
*/
protected $service; protected $service;
protected $target; protected $target;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->service = self::$container->get(NamedElementProvider::class); $this->service = self::$container->get(NamedElementProvider::class);
$this->target = new class implements NamedElementInterface { $this->target = new class() implements NamedElementInterface {
/**
* @inheritDoc
*/
public function getName(): string public function getName(): string
{ {
return 'This is my Name'; return 'This is my Name';
@ -53,7 +51,7 @@ class NamedElementProviderTest extends WebTestCase
public function dataProvider(): array public function dataProvider(): array
{ {
return [ return [
['This is my Name', '[[NAME]]'] ['This is my Name', '[[NAME]]'],
]; ];
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,22 +23,22 @@
namespace App\Tests\Services\LabelSystem\PlaceholderProviders; namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation; use App\Entity\Parts\Storelocation;
use App\Services\LabelSystem\PlaceholderProviders\NamedElementProvider;
use App\Services\LabelSystem\PlaceholderProviders\PartLotProvider; use App\Services\LabelSystem\PlaceholderProviders\PartLotProvider;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class PartLotProviderTest extends WebTestCase class PartLotProviderTest extends WebTestCase
{ {
/** @var PartLotProvider */ /**
* @var PartLotProvider
*/
protected $service; protected $service;
protected $target; protected $target;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
\Locale::setDefault('en'); \Locale::setDefault('en');

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -20,14 +23,10 @@
namespace App\Tests\Services\LabelSystem\PlaceholderProviders; namespace App\Tests\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\Parts\Category; use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Services\LabelSystem\PlaceholderProviders\GlobalProviders;
use App\Services\LabelSystem\PlaceholderProviders\PartProvider; use App\Services\LabelSystem\PlaceholderProviders\PartProvider;
use DateTime;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -36,15 +35,19 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
*/ */
class PartProviderTest extends WebTestCase class PartProviderTest extends WebTestCase
{ {
/** @var PartProvider */ /**
* @var PartProvider
*/
protected $service; protected $service;
protected $target; protected $target;
/** @var \Doctrine\ORM\EntityManager */ /**
* @var \Doctrine\ORM\EntityManager
*/
protected $em; protected $em;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->service = self::$container->get(PartProvider::class); $this->service = self::$container->get(PartProvider::class);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -28,29 +31,24 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class TimestampableElementProviderTest extends WebTestCase class TimestampableElementProviderTest extends WebTestCase
{ {
/** @var GlobalProviders */ /**
* @var GlobalProviders
*/
protected $service; protected $service;
protected $target; protected $target;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
\Locale::setDefault('en'); \Locale::setDefault('en');
$this->service = self::$container->get(TimestampableElementProvider::class); $this->service = self::$container->get(TimestampableElementProvider::class);
$this->target = new class implements TimeStampableInterface { $this->target = new class() implements TimeStampableInterface {
/**
* @inheritDoc
*/
public function getLastModified(): ?DateTime public function getLastModified(): ?DateTime
{ {
return new \DateTime('2000-01-01'); return new \DateTime('2000-01-01');
} }
/**
* @inheritDoc
*/
public function getAddedDate(): ?DateTime public function getAddedDate(): ?DateTime
{ {
return new \DateTime('2000-01-01'); return new \DateTime('2000-01-01');

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -24,18 +27,18 @@ use App\Entity\LabelSystem\LabelOptions;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot; use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation; use App\Entity\Parts\Storelocation;
use App\Services\LabelSystem\Barcodes\BarcodeExampleElementsGenerator;
use App\Services\LabelSystem\SandboxedTwigProvider; use App\Services\LabelSystem\SandboxedTwigProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Twig\Sandbox\SecurityError; use Twig\Sandbox\SecurityError;
class SandboxedTwigProviderTest extends WebTestCase class SandboxedTwigProviderTest extends WebTestCase
{ {
/** @var SandboxedTwigProvider */ /**
* @var SandboxedTwigProvider
*/
private $service; private $service;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->service = self::$container->get(SandboxedTwigProvider::class); $this->service = self::$container->get(SandboxedTwigProvider::class);
@ -65,26 +68,25 @@ class SandboxedTwigProviderTest extends WebTestCase
'], '],
[' ['
{{ part.reviewNeeded }} {{ part.tags }} {{ part.mass }} {{ part.reviewNeeded }} {{ part.tags }} {{ part.mass }}
'] '],
]; ];
} }
public function twigNotAllowedDataProvider(): array public function twigNotAllowedDataProvider(): array
{ {
return [ return [
["{% block test %} {% endblock %}"], ['{% block test %} {% endblock %}'],
["{% deprecated test %}"], ['{% deprecated test %}'],
["{% flush %}"], ['{% flush %}'],
["{{ part.setName('test') }}"], ["{{ part.setName('test') }}"],
["{{ part.setCategory(null) }}"] ['{{ part.setCategory(null) }}'],
]; ];
} }
/** /**
* @dataProvider twigDataProvider * @dataProvider twigDataProvider
*/ */
public function testTwigFeatures(string $twig) public function testTwigFeatures(string $twig): void
{ {
$options = new LabelOptions(); $options = new LabelOptions();
$options->setSupportedElement('part'); $options->setSupportedElement('part');
@ -104,7 +106,7 @@ class SandboxedTwigProviderTest extends WebTestCase
/** /**
* @dataProvider twigNotAllowedDataProvider * @dataProvider twigNotAllowedDataProvider
*/ */
public function testTwigForbidden(string $twig) public function testTwigForbidden(string $twig): void
{ {
$this->expectException(SecurityError::class); $this->expectException(SecurityError::class);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -30,7 +33,7 @@ class RangeParserTest extends WebTestCase
*/ */
protected $service; protected $service;
public function setUp(): void protected function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->service = self::$container->get(RangeParser::class); $this->service = self::$container->get(RangeParser::class);
@ -42,19 +45,19 @@ class RangeParserTest extends WebTestCase
[[], ''], [[], ''],
[[], ' '], [[], ' '],
[[], "\t"], [[], "\t"],
[[1], "1"], [[1], '1'],
[[1, 2, 3], "1,2, 3"], [[1, 2, 3], '1,2, 3'],
[[1, 2, 3], "1-3"], [[1, 2, 3], '1-3'],
[[1, 2, 3, 4], "1- 3, 4"], [[1, 2, 3, 4], '1- 3, 4'],
[[1, 2, 3, 4], "1, 2,3 - 4"], [[1, 2, 3, 4], '1, 2,3 - 4'],
[[1, 2, 3], " 1; 2, 3"], [[1, 2, 3], ' 1; 2, 3'],
[[-1, 0, 1, 2], "-1; 0; 1, 2"], [[-1, 0, 1, 2], '-1; 0; 1, 2'],
[[4,3, 1, 2], "4,3, 1;2"], [[4, 3, 1, 2], '4,3, 1;2'],
[[1, 2, 3, 4], "2-1, 3-4"], [[1, 2, 3, 4], '2-1, 3-4'],
[[1], "1-1"], [[1], '1-1'],
[[-3, -2, -1], "-3--1"], [[-3, -2, -1], '-3--1'],
[[1, 2, 3], "1,,2;;,,3"], [[1, 2, 3], '1,,2;;,,3'],
[[100, 1000, 1], "100, 1000, 1"], [[100, 1000, 1], '100, 1000, 1'],
[[], 'test', true], [[], 'test', true],
[[], '1-2-3-4,5', true], [[], '1-2-3-4,5', true],
[[], '1 2 3, 455, 23', true], [[], '1 2 3, 455, 23', true],

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\Dotenv\Dotenv;
require dirname(__DIR__).'/vendor/autoload.php'; require dirname(__DIR__).'/vendor/autoload.php';