diff --git a/src/Controller/AdminPages/BaseAdminController.php b/src/Controller/AdminPages/BaseAdminController.php index 2b2e0f90..fd86769c 100644 --- a/src/Controller/AdminPages/BaseAdminController.php +++ b/src/Controller/AdminPages/BaseAdminController.php @@ -46,7 +46,6 @@ use App\DataTables\LogDataTable; use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\LabelSystem\LabelProfile; -use App\Entity\Parts\PartLot; use App\Entity\UserSystem\User; use App\Events\SecurityEvent; use App\Events\SecurityEvents; @@ -94,7 +93,9 @@ abstract class BaseAdminController extends AbstractController protected $historyHelper; protected $timeTravel; protected $dataTableFactory; - /** @var EventDispatcher */ + /** + * @var EventDispatcher + */ protected $eventDispatcher; protected $labelGenerator; protected $barcodeExampleGenerator; @@ -165,7 +166,7 @@ abstract class BaseAdminController extends AbstractController $table = null; } - $form_options = [ + $form_options = [ 'attachment_class' => $this->attachment_class, 'parameter_class' => $this->parameter_class, '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... if ( $entity instanceof LabelProfile - && $entity->getOptions()->getLinesMode() === 'twig' - && !$this->isGranted('@labels.use_twig') + && 'twig' === $entity->getOptions()->getLinesMode() + && ! $this->isGranted('@labels.use_twig') ) { $form_options['disable_options'] = true; } diff --git a/src/Controller/AdminPages/LabelProfileController.php b/src/Controller/AdminPages/LabelProfileController.php index a1b64058..6854e32e 100644 --- a/src/Controller/AdminPages/LabelProfileController.php +++ b/src/Controller/AdminPages/LabelProfileController.php @@ -43,12 +43,8 @@ declare(strict_types=1); namespace App\Controller\AdminPages; use App\Entity\Attachments\AttachmentType; -use App\Entity\Attachments\AttachmentTypeAttachment; use App\Entity\Attachments\LabelAttachment; 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\Services\EntityExporter; use App\Services\EntityImporter; diff --git a/src/Controller/LabelController.php b/src/Controller/LabelController.php index 29a564f5..ac888ccb 100644 --- a/src/Controller/LabelController.php +++ b/src/Controller/LabelController.php @@ -1,4 +1,7 @@ denyAccessUnlessGranted('@labels.create_labels'); //If we inherit a LabelProfile, the user need to have access to it... - if ($profile !== null) { + if (null !== $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. - $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, [ 'disable_options' => $disable_options, @@ -99,14 +92,13 @@ class LabelController extends AbstractController $target_id = $request->query->get('target_id', null); $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); } if (is_string($target_id)) { $form['target_id']->setData($target_id); } - $form['options']->setData($label_options); $form->handleRequest($request); @@ -117,17 +109,16 @@ class LabelController extends AbstractController $filename = 'invalid.pdf'; //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(); $targets = $this->findObjects($form_options->getSupportedElement(), $target_id); - if (!empty($targets)) { + if (! empty($targets)) { try { $pdf_data = $this->labelGenerator->generateLabel($form_options, $targets); $filename = $this->getLabelName($targets[0], $profile); } catch (TwigModeException $exception) { $form->get('options')->get('lines')->addError(new FormError($exception->getMessage())); } - } else { //$this->addFlash('warning', 'label_generator.no_entities_found'); $form->get('target_id')->addError( @@ -146,15 +137,15 @@ class LabelController extends AbstractController protected function getLabelName(AbstractDBElement $element, ?LabelProfile $profile = null): string { - $ret = 'label_' . $this->elementTypeNameGenerator->getLocalizedTypeLabel($element); + $ret = 'label_'.$this->elementTypeNameGenerator->getLocalizedTypeLabel($element); $ret .= $element->getID(); - return $ret . '.pdf'; + return $ret.'.pdf'; } 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!'); } @@ -162,6 +153,7 @@ class LabelController extends AbstractController /** @var DBElementRepository $repo */ $repo = $this->em->getRepository(LabelGenerator::CLASS_SUPPORT_MAPPING[$type]); + return $repo->getElementsFromIDArray($id_array); } -} \ No newline at end of file +} diff --git a/src/Controller/ScanController.php b/src/Controller/ScanController.php index 3d4ce484..880af1a6 100644 --- a/src/Controller/ScanController.php +++ b/src/Controller/ScanController.php @@ -1,4 +1,7 @@ isSubmitted() && $form->isValid()) { $input = $form['input']->getData(); + try { [$type, $id] = $this->barcodeNormalizer->normalizeBarcodeContent($input); + try { return $this->redirect($this->barcodeParser->getRedirectURL($type, $id)); } catch (EntityNotFoundException $exception) { @@ -76,18 +78,18 @@ 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 - * @param string $type - * @param int $id + * The route definition for this action is done in routes.yaml, as it does not use the _locale prefix as the other routes. */ public function scanQRCode(string $type, int $id): Response { try { $this->addFlash('success', 'scan.qr_success'); + return $this->redirect($this->barcodeParser->getRedirectURL($type, $id)); } catch (EntityNotFoundException $exception) { $this->addFlash('success', 'scan.qr_not_found'); + return $this->redirectToRoute('homepage'); } } -} \ No newline at end of file +} diff --git a/src/Controller/UserSettingsController.php b/src/Controller/UserSettingsController.php index 58e0fabf..7ff41a65 100644 --- a/src/Controller/UserSettingsController.php +++ b/src/Controller/UserSettingsController.php @@ -72,7 +72,9 @@ use Symfony\Component\Validator\Constraints\Length; class UserSettingsController extends AbstractController { protected $demo_mode; - /** @var EventDispatcher */ + /** + * @var EventDispatcher + */ protected $eventDispatcher; public function __construct(bool $demo_mode, EventDispatcherInterface $eventDispatcher) diff --git a/src/DataFixtures/LabelProfileFixtures.php b/src/DataFixtures/LabelProfileFixtures.php index fa1a72b4..24a08f3d 100644 --- a/src/DataFixtures/LabelProfileFixtures.php +++ b/src/DataFixtures/LabelProfileFixtures.php @@ -1,4 +1,7 @@ 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->setName('Profile 1'); @@ -77,13 +78,12 @@ class LabelProfileFixtures extends Fixture $manager->persist($profile3); - $profile4 = new LabelProfile(); $profile4->setName('Profile 4'); $profile4->setShowInDropdown(true); $option4 = new LabelOptions(); - $option4->setLines("{{ element.name }}"); + $option4->setLines('{{ element.name }}'); $option4->setBarcodeType('code39'); $option4->setSupportedElement('part'); $option4->setLinesMode('twig'); @@ -93,4 +93,4 @@ class LabelProfileFixtures extends Fixture $manager->flush(); } -} \ No newline at end of file +} diff --git a/src/DataTables/Adapter/ORMAdapter.php b/src/DataTables/Adapter/ORMAdapter.php index 157ce4f0..b1d0bf18 100644 --- a/src/DataTables/Adapter/ORMAdapter.php +++ b/src/DataTables/Adapter/ORMAdapter.php @@ -38,21 +38,33 @@ use Symfony\Component\OptionsResolver\OptionsResolver; */ class ORMAdapter extends AbstractAdapter { - /** @var EntityManager */ + /** + * @var EntityManager + */ protected $manager; - /** @var \Doctrine\ORM\Mapping\ClassMetadata */ + /** + * @var \Doctrine\ORM\Mapping\ClassMetadata + */ protected $metadata; - /** @var QueryBuilderProcessorInterface[] */ + /** + * @var QueryBuilderProcessorInterface[] + */ protected $criteriaProcessors; - /** @var ManagerRegistry */ + /** + * @var ManagerRegistry + */ private $registry; - /** @var int */ + /** + * @var int + */ private $hydrationMode; - /** @var QueryBuilderProcessorInterface[] */ + /** + * @var QueryBuilderProcessorInterface[] + */ private $queryBuilderProcessors; /** diff --git a/src/Entity/Attachments/LabelAttachment.php b/src/Entity/Attachments/LabelAttachment.php index 65d31f42..53927edf 100644 --- a/src/Entity/Attachments/LabelAttachment.php +++ b/src/Entity/Attachments/LabelAttachment.php @@ -1,4 +1,7 @@ width = $width; + return $this; } @@ -114,12 +117,12 @@ class LabelOptions } /** - * @param float $height * @return LabelOptions */ - public function setHeight(float $height): LabelOptions + public function setHeight(float $height): self { $this->height = $height; + return $this; } @@ -132,12 +135,12 @@ class LabelOptions } /** - * @param string $barcode_type * @return LabelOptions */ - public function setBarcodeType(string $barcode_type): LabelOptions + public function setBarcodeType(string $barcode_type): self { $this->barcode_type = $barcode_type; + return $this; } @@ -150,12 +153,12 @@ class LabelOptions } /** - * @param string $picture_type * @return LabelOptions */ - public function setPictureType(string $picture_type): LabelOptions + public function setPictureType(string $picture_type): self { $this->picture_type = $picture_type; + return $this; } @@ -168,12 +171,12 @@ class LabelOptions } /** - * @param string $supported_element * @return LabelOptions */ - public function setSupportedElement(string $supported_element): LabelOptions + public function setSupportedElement(string $supported_element): self { $this->supported_element = $supported_element; + return $this; } @@ -186,17 +189,18 @@ class LabelOptions } /** - * @param string $lines * @return LabelOptions */ - public function setLines(string $lines): LabelOptions + public function setLines(string $lines): self { $this->lines = $lines; + return $this; } /** - * Gets additional CSS (it will simply be attached + * Gets additional CSS (it will simply be attached. + * * @return string */ public function getAdditionalCss(): string @@ -205,13 +209,12 @@ class LabelOptions } /** - * - * @param string $additional_css * @return LabelOptions */ - public function setAdditionalCss(string $additional_css): LabelOptions + public function setAdditionalCss(string $additional_css): self { $this->additional_css = $additional_css; + return $this; } @@ -224,17 +227,12 @@ class LabelOptions } /** - * @param string $lines_mode * @return LabelOptions */ - public function setLinesMode(string $lines_mode): LabelOptions + public function setLinesMode(string $lines_mode): self { $this->lines_mode = $lines_mode; + return $this; } - - - - - -} \ No newline at end of file +} diff --git a/src/Entity/LabelSystem/LabelProfile.php b/src/Entity/LabelSystem/LabelProfile.php index 0311e64b..732d0850 100644 --- a/src/Entity/LabelSystem/LabelProfile.php +++ b/src/Entity/LabelSystem/LabelProfile.php @@ -1,4 +1,7 @@ options; } - public function setOptions(LabelOptions $labelOptions): LabelProfile + public function setOptions(LabelOptions $labelOptions): self { $this->options = $labelOptions; + return $this; } /** * Get the comment of the element. + * * @return string the comment */ public function getComment(): ?string @@ -91,11 +95,13 @@ class LabelProfile extends AttachmentContainingDBElement public function setComment(string $new_comment): string { $this->comment = $new_comment; + return $this; } /** * Returns true, if this label profile should be shown in label generator quick menu. + * * @return bool */ public function isShowInDropdown(): bool @@ -105,22 +111,18 @@ class LabelProfile extends AttachmentContainingDBElement /** * Sets the show in dropdown menu. - * @param bool $show_in_dropdown + * * @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; + return $this; } - - - /** - * @inheritDoc - */ public function getIDString(): string { return 'LP'.sprintf('%09d', $this->getID()); } -} \ No newline at end of file +} diff --git a/src/Entity/LogSystem/AbstractLogEntry.php b/src/Entity/LogSystem/AbstractLogEntry.php index 829dad48..3f8e9954 100644 --- a/src/Entity/LogSystem/AbstractLogEntry.php +++ b/src/Entity/LogSystem/AbstractLogEntry.php @@ -120,7 +120,9 @@ abstract class AbstractLogEntry extends AbstractDBElement protected const TARGET_TYPE_PARAMETER = 18; 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 = [ self::LEVEL_EMERGENCY => LogLevel::EMERGENCY, self::LEVEL_ALERT => LogLevel::ALERT, diff --git a/src/EventSubscriber/LogSystem/EventLoggerSubscriber.php b/src/EventSubscriber/LogSystem/EventLoggerSubscriber.php index bf53115b..281d0a12 100644 --- a/src/EventSubscriber/LogSystem/EventLoggerSubscriber.php +++ b/src/EventSubscriber/LogSystem/EventLoggerSubscriber.php @@ -70,12 +70,16 @@ use Symfony\Component\Serializer\SerializerInterface; */ 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 = [ 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 = [ PartLot::class => ['part'], Orderdetail::class => ['part'], diff --git a/src/EventSubscriber/UserSystem/RegisterU2FSubscriber.php b/src/EventSubscriber/UserSystem/RegisterU2FSubscriber.php index a6c986f5..190dbc65 100644 --- a/src/EventSubscriber/UserSystem/RegisterU2FSubscriber.php +++ b/src/EventSubscriber/UserSystem/RegisterU2FSubscriber.php @@ -69,7 +69,9 @@ final class RegisterU2FSubscriber implements EventSubscriberInterface */ private $router; - /** @var EventDispatcher */ + /** + * @var EventDispatcher + */ private $eventDispatcher; public function __construct(UrlGeneratorInterface $router, EntityManagerInterface $entityManager, FlashBagInterface $flashBag, EventDispatcherInterface $eventDispatcher, bool $demo_mode) diff --git a/src/Exceptions/TwigModeException.php b/src/Exceptions/TwigModeException.php index 67e54059..52d125e1 100644 --- a/src/Exceptions/TwigModeException.php +++ b/src/Exceptions/TwigModeException.php @@ -1,4 +1,7 @@ getMessage(), 0, $previous); } -} \ No newline at end of file +} diff --git a/src/Form/AdminPages/BaseEntityAdminForm.php b/src/Form/AdminPages/BaseEntityAdminForm.php index 4fdb7c55..b4d20ea8 100644 --- a/src/Form/AdminPages/BaseEntityAdminForm.php +++ b/src/Form/AdminPages/BaseEntityAdminForm.php @@ -45,7 +45,6 @@ namespace App\Form\AdminPages; use App\Entity\Attachments\Attachment; use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Base\AbstractStructuralDBElement; -use App\Entity\LabelSystem\LabelOptions; use App\Entity\LabelSystem\LabelProfile; use App\Form\AttachmentFormType; use App\Form\ParameterType; @@ -106,7 +105,7 @@ class BaseEntityAdminForm extends AbstractType 'class' => get_class($entity), 'required' => false, 'label' => 'parent.label', - 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), + 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity), ] ) ->add( @@ -119,7 +118,7 @@ class BaseEntityAdminForm extends AbstractType 'label_attr' => [ '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, ], '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, 'allow_add' => $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, 'label' => false, 'by_reference' => false, diff --git a/src/Form/AdminPages/LabelProfileAdminForm.php b/src/Form/AdminPages/LabelProfileAdminForm.php index b77aa502..38cd05ef 100644 --- a/src/Form/AdminPages/LabelProfileAdminForm.php +++ b/src/Form/AdminPages/LabelProfileAdminForm.php @@ -1,4 +1,7 @@ setDefault('data_class', LabelProfile::class); + $resolver->setDefault('disable_options', false); + } + protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void { - $builder->add('show_in_dropdown', CheckboxType::class, [ 'required' => false, 'label' => 'label_profile.showInDropdown', @@ -45,11 +53,4 @@ class LabelProfileAdminForm extends BaseEntityAdminForm 'disabled' => $options['disable_options'], ]); } - - public function configureOptions(OptionsResolver $resolver): void - { - parent::configureOptions($resolver); - $resolver->setDefault('data_class', LabelProfile::class); - $resolver->setDefault('disable_options', false); - } -} \ No newline at end of file +} diff --git a/src/Form/LabelOptionsType.php b/src/Form/LabelOptionsType.php index 9f35957e..e2152298 100644 --- a/src/Form/LabelOptionsType.php +++ b/src/Form/LabelOptionsType.php @@ -1,4 +1,7 @@ security = $security; } - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('width', NumberType::class, [ 'label' => 'label_options.page_size.label', @@ -49,7 +51,7 @@ class LabelOptionsType extends AbstractType 'placeholder' => 'label_options.width.placeholder', 'min' => 0, 'step' => 'any', - ] + ], ]); $builder->add('height', NumberType::class, [ 'label' => false, @@ -58,7 +60,7 @@ class LabelOptionsType extends AbstractType 'placeholder' => 'label_options.height.placeholder', 'min' => 0, 'step' => 'any', - ] + ], ]); $builder->add('supported_element', ChoiceType::class, [ @@ -67,11 +69,11 @@ class LabelOptionsType extends AbstractType 'part.label' => 'part', 'part_lot.label' => 'part_lot', 'storelocation.label' => 'storelocation', - ] + ], ]); $builder->add('barcode_type', ChoiceType::class, [ - 'label' => 'label_options.barcode_type.label', + 'label' => 'label_options.barcode_type.label', 'empty_data' => 'none', 'choices' => [ 'label_options.barcode_type.none' => 'none', @@ -82,10 +84,10 @@ class LabelOptionsType extends AbstractType 'label_options.barcode_type.datamatrix' => 'datamatrix', ], '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'; } - if (in_array($choice, ['code39', 'code93', 'code128'])) { + if (in_array($choice, ['code39', 'code93', 'code128'], true)) { return 'label_options.barcode_type.1D'; } @@ -95,7 +97,6 @@ class LabelOptionsType extends AbstractType 'class' => 'selectpicker', 'data-live-search' => true, ], - ]); $builder->add('lines', CKEditorType::class, [ @@ -126,17 +127,17 @@ class LabelOptionsType extends AbstractType 'help_html' => true, 'expanded' => true, 'attr' => [ - 'class' => 'pt-2' + 'class' => 'pt-2', ], '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); } -} \ No newline at end of file +} diff --git a/src/Form/LabelSystem/LabelDialogType.php b/src/Form/LabelSystem/LabelDialogType.php index 60f392c0..2c5bf343 100644 --- a/src/Form/LabelSystem/LabelDialogType.php +++ b/src/Form/LabelSystem/LabelDialogType.php @@ -1,4 +1,7 @@ security = $security; } - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->add('target_id', TextType::class, [ 'required' => true, @@ -53,18 +54,17 @@ class LabelDialogType extends AbstractType $builder->add('options', LabelOptionsType::class, [ '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, [ 'label' => 'label_generator.update', ]); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { parent::configureOptions($resolver); $resolver->setDefault('mapped', false); $resolver->setDefault('disable_options', false); } -} \ No newline at end of file +} diff --git a/src/Form/LabelSystem/ScanDialogType.php b/src/Form/LabelSystem/ScanDialogType.php index fc269203..89dbf5bb 100644 --- a/src/Form/LabelSystem/ScanDialogType.php +++ b/src/Form/LabelSystem/ScanDialogType.php @@ -1,4 +1,7 @@ add('input', TextType::class, [ 'label' => 'scan_dialog.input', @@ -40,12 +42,12 @@ class ScanDialogType extends AbstractType ]); $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); } -} \ No newline at end of file +} diff --git a/src/Helpers/LabelResponse.php b/src/Helpers/LabelResponse.php index 510ff0b1..b60aa875 100644 --- a/src/Helpers/LabelResponse.php +++ b/src/Helpers/LabelResponse.php @@ -1,4 +1,7 @@ setAutoEtag(); $this->setAutoLastModified(); + return $this; } @@ -46,8 +48,7 @@ class LabelResponse extends Response { 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')) { $this->setProtocolVersion('1.1'); @@ -89,7 +90,7 @@ class LabelResponse extends Response */ 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'; for ($i = 0, $filenameLength = mb_strlen($filename, $encoding); $i < $filenameLength; ++$i) { @@ -108,5 +109,4 @@ class LabelResponse extends Response return $this; } - -} \ No newline at end of file +} diff --git a/src/Migrations/Version20200502161750.php b/src/Migrations/Version20200502161750.php index 74be880a..837348dd 100644 --- a/src/Migrations/Version20200502161750.php +++ b/src/Migrations/Version20200502161750.php @@ -12,25 +12,25 @@ use Doctrine\Migrations\AbstractMigration; */ final class Version20200502161750 extends AbstractMigration { - public function getDescription() : string + public function getDescription(): string { 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->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('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'); } - 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->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('ALTER TABLE log CHANGE level level TINYINT(1) DEFAULT NULL'); diff --git a/src/Repository/DBElementRepository.php b/src/Repository/DBElementRepository.php index 0c84f1e5..f265f8c0 100644 --- a/src/Repository/DBElementRepository.php +++ b/src/Repository/DBElementRepository.php @@ -52,7 +52,7 @@ class DBElementRepository extends EntityRepository /** * Find all elements that match a list of IDs. - * @param array $ids + * * @return AbstractDBElement[] */ public function getElementsFromIDArray(array $ids): array diff --git a/src/Repository/LabelProfileRepository.php b/src/Repository/LabelProfileRepository.php index fad62359..e4d6f784 100644 --- a/src/Repository/LabelProfileRepository.php +++ b/src/Repository/LabelProfileRepository.php @@ -1,4 +1,7 @@ findBy(['options.supported_element' => $type, 'show_in_dropdown' => true], ['name' => 'ASC']); } @@ -62,9 +64,9 @@ class LabelProfileRepository extends NamedDBElementRepository $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 - $tmp = new TreeViewNode('$$' . $type . '.label', null, $type_children); + $tmp = new TreeViewNode('$$'.$type.'.label', null, $type_children); $result[] = $tmp; } @@ -74,16 +76,19 @@ class LabelProfileRepository extends NamedDBElementRepository } /** - * 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 + * 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 + * * @return array */ public function findForSupportedElement(string $type, array $order_by = ['name' => 'ASC']): array { - if (!in_array($type, LabelOptions::SUPPORTED_ELEMENTS)) { - throw new \InvalidArgumentException('Invalid supported_element type given.'); + if (! in_array($type, LabelOptions::SUPPORTED_ELEMENTS, true)) { + throw new \InvalidArgumentException('Invalid supported_element type given.'); } + return $this->findBy(['options.supported_element' => $type], $order_by); } -} \ No newline at end of file +} diff --git a/src/Security/Voter/LabelProfileVoter.php b/src/Security/Voter/LabelProfileVoter.php index d8abc7ea..837bbe90 100644 --- a/src/Security/Voter/LabelProfileVoter.php +++ b/src/Security/Voter/LabelProfileVoter.php @@ -1,4 +1,7 @@ 'read_profiles', 'create' => 'create_profiles', @@ -36,21 +37,15 @@ class LabelProfileVoter extends ExtendedVoter 'revert_element' => 'revert_element', ]; - /** - * @inheritDoc - */ protected function voteOnUser($attribute, $subject, User $user): bool { return $this->resolver->inherit($user, 'labels', self::MAPPING[$attribute]) ?? false; } - /** - * @inheritDoc - */ protected function supports($attribute, $subject) { if ($subject instanceof LabelProfile) { - if (!isset(self::MAPPING[$attribute])) { + if (! isset(self::MAPPING[$attribute])) { return false; } @@ -59,4 +54,4 @@ class LabelProfileVoter extends ExtendedVoter return false; } -} \ No newline at end of file +} diff --git a/src/Security/Voter/OrderdetailVoter.php b/src/Security/Voter/OrderdetailVoter.php index 256d406f..0d54d391 100644 --- a/src/Security/Voter/OrderdetailVoter.php +++ b/src/Security/Voter/OrderdetailVoter.php @@ -28,7 +28,9 @@ use App\Entity\UserSystem\User; 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 function voteOnUser($attribute, $subject, User $user): bool diff --git a/src/Security/Voter/PartLotVoter.php b/src/Security/Voter/PartLotVoter.php index 0e985e48..035d25b5 100644 --- a/src/Security/Voter/PartLotVoter.php +++ b/src/Security/Voter/PartLotVoter.php @@ -28,7 +28,9 @@ use App\Entity\UserSystem\User; 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 function voteOnUser($attribute, $subject, User $user): bool diff --git a/src/Security/Voter/PricedetailVoter.php b/src/Security/Voter/PricedetailVoter.php index d222df54..c6a9cbdc 100644 --- a/src/Security/Voter/PricedetailVoter.php +++ b/src/Security/Voter/PricedetailVoter.php @@ -28,7 +28,9 @@ use App\Entity\UserSystem\User; 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 function voteOnUser($attribute, $subject, User $user): bool diff --git a/src/Services/AmountFormatter.php b/src/Services/AmountFormatter.php index 2dae342a..4cb7c36e 100644 --- a/src/Services/AmountFormatter.php +++ b/src/Services/AmountFormatter.php @@ -62,9 +62,9 @@ class AmountFormatter /** * Formats the given value using the measurement unit and options. * - * @param float|string|int $value - * @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. + * @param float|string|int $value + * @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. * * @return string The formatted string * diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index 96ac6ff1..5151a463 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -242,7 +242,7 @@ class EntityURLGenerator Currency::class => 'currency_edit', MeasurementUnit::class => 'measurement_unit_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()]); @@ -272,7 +272,7 @@ class EntityURLGenerator Currency::class => 'currency_edit', MeasurementUnit::class => 'measurement_unit_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()]); @@ -302,7 +302,7 @@ class EntityURLGenerator Currency::class => 'currency_new', MeasurementUnit::class => 'measurement_unit_new', Group::class => 'group_new', - LabelProfile::class => 'label_profile_new' + LabelProfile::class => 'label_profile_new', ]; return $this->urlGenerator->generate($this->mapToController($map, $entity)); @@ -333,7 +333,7 @@ class EntityURLGenerator Currency::class => 'currency_clone', MeasurementUnit::class => 'measurement_unit_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()]); @@ -376,7 +376,7 @@ class EntityURLGenerator Currency::class => 'currency_delete', MeasurementUnit::class => 'measurement_unit_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()]); diff --git a/src/Services/LabelSystem/BarcodeGenerator.php b/src/Services/LabelSystem/BarcodeGenerator.php index 70f68d27..4d82dc3b 100644 --- a/src/Services/LabelSystem/BarcodeGenerator.php +++ b/src/Services/LabelSystem/BarcodeGenerator.php @@ -1,4 +1,7 @@ getBarcodeType()) { case 'qr': $type = 'QRCODE'; + break; case 'datamatrix': $type = 'DATAMATRIX'; + break; case 'code39': $type = 'C39'; + break; case 'code93': $type = 'C93'; + break; case 'code128': $type = 'C128A'; + break; case 'none': return null; @@ -80,5 +88,4 @@ final class BarcodeGenerator throw new \InvalidArgumentException('Unknown label type!'); } } - -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php b/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php index 90838d9a..f4260563 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php @@ -1,4 +1,7 @@ 'P', PartLot::class => 'L', - Storelocation::class => 'S' + Storelocation::class => 'S', ]; private const URL_MAP = [ @@ -45,6 +42,7 @@ final class BarcodeContentGenerator PartLot::class => 'lot', Storelocation::class => 'location', ]; + private $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). - * @param AbstractDBElement $target + * * @return 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. - * The return value has a format of "L0123" - * @param AbstractDBElement $target + * The return value has a format of "L0123". + * * @return string */ public function get1DBarcodeContent(AbstractDBElement $target): string { $prefix = $this->classToString(self::PREFIX_MAP, $target); $id = sprintf('%04d', $target->getID() ?? 0); - return $prefix . $id; + + return $prefix.$id; } private function classToString(array $map, object $target): string @@ -87,12 +86,12 @@ final class BarcodeContentGenerator return $map[$class]; } - foreach($map as $class => $string) { + foreach ($map as $class => $string) { if (is_a($target, $class)) { return $string; } } - throw new \InvalidArgumentException('Unknown object class ' . get_class($target)); + throw new \InvalidArgumentException('Unknown object class '.get_class($target)); } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/Barcodes/BarcodeExampleElementsGenerator.php b/src/Services/LabelSystem/Barcodes/BarcodeExampleElementsGenerator.php index 96644960..118b1a24 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeExampleElementsGenerator.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeExampleElementsGenerator.php @@ -1,4 +1,7 @@ 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 { $part = new Part(); @@ -98,7 +68,6 @@ final class BarcodeExampleElementsGenerator $part->setMinAmount(100); $part->setNeedsReview(true); - return $part; } @@ -115,4 +84,37 @@ final class BarcodeExampleElementsGenerator return $lot; } -} \ No newline at end of file + + 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; + } +} diff --git a/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php b/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php index 2170bcaf..e8c69a8f 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php @@ -1,4 +1,7 @@ urlGenerator = $urlGenerator; @@ -39,10 +40,13 @@ final class BarcodeRedirector } /** - * 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 + * 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 + * * @return string The URL to which should be redirected. + * * @throws EntityNotFoundException */ public function getRedirectURL(string $type, int $id): string @@ -53,7 +57,7 @@ final class BarcodeRedirector case 'lot': //Try to determine the part to the given lot $lot = $this->em->find(PartLot::class, $id); - if ($lot === null) { + if (null === $lot) { throw new EntityNotFoundException(); } @@ -63,7 +67,7 @@ final class BarcodeRedirector return $this->urlGenerator->generate('part_list_store_location', ['id' => $id]); default: - throw new \InvalidArgumentException('Unknown $type: ' . $type); + throw new \InvalidArgumentException('Unknown $type: '.$type); } } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/LabelGenerator.php b/src/Services/LabelSystem/LabelGenerator.php index 8c8dd70e..f3049166 100644 --- a/src/Services/LabelSystem/LabelGenerator.php +++ b/src/Services/LabelSystem/LabelGenerator.php @@ -1,4 +1,7 @@ supports($options, $element)) { + if (! $this->supports($options, $element)) { throw new \InvalidArgumentException('The given options are not compatible with the given element!'); } } - $dompdf = new Dompdf(); $dompdf->setPaper($this->mmToPointsArray($options->getWidth(), $options->getHeight())); $dompdf->loadHtml($this->labelHTMLGenerator->getLabelHTML($options, $elements)); $dompdf->render(); + return $dompdf->output(); } /** * Check if the given LabelOptions can be used with $element. - * @param LabelOptions $options - * @param object $element + * * @return bool */ public function supports(LabelOptions $options, object $element) { $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!'); } @@ -93,13 +91,15 @@ final class LabelGenerator } /** - * 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 + * 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 + * * @return float[] */ public function mmToPointsArray(float $width, float $height): array { return [0.0, 0.0, $width * self::MM_TO_POINTS_FACTOR, $height * self::MM_TO_POINTS_FACTOR]; } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/LabelHTMLGenerator.php b/src/Services/LabelSystem/LabelHTMLGenerator.php index ef161940..5076971b 100644 --- a/src/Services/LabelSystem/LabelHTMLGenerator.php +++ b/src/Services/LabelSystem/LabelHTMLGenerator.php @@ -1,4 +1,7 @@ getLinesMode() === 'twig') { + if ('twig' === $options->getLinesMode()) { $sandboxed_twig = $this->sandboxedTwigProvider->getTwig($options); $current_user = $this->security->getUser(); } $page = 1; 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 { $lines = $sandboxed_twig->render( 'lines', @@ -92,10 +93,9 @@ final class LabelHTMLGenerator 'barcode_content' => $this->barcodeGenerator->getContent($options, $element), ]; - $page++; + ++$page; } - return $this->twig->render('LabelSystem/labels/base_label.html.twig', [ 'meta_title' => $this->getPDFTitle($options, $elements[0]), 'elements' => $twig_elements, @@ -103,8 +103,7 @@ final class LabelHTMLGenerator ]); } - - protected function getPDFTitle(LabelOptions $options, object $element) + private function getPDFTitle(LabelOptions $options, object $element) { if ($element instanceof NamedElementInterface) { return $this->elementTypeNameGenerator->getTypeNameCombination($element, false); @@ -112,4 +111,4 @@ final class LabelHTMLGenerator return 'Part-DB label'; } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/LabelProfileDropdownHelper.php b/src/Services/LabelSystem/LabelProfileDropdownHelper.php index 21c33592..6dc116f9 100644 --- a/src/Services/LabelSystem/LabelProfileDropdownHelper.php +++ b/src/Services/LabelSystem/LabelProfileDropdownHelper.php @@ -1,4 +1,7 @@ keyGenerator->generateKey().'_'.$secure_class_name . '_' . $type; + $key = 'profile_dropdown_'.$this->keyGenerator->generateKey().'_'.$secure_class_name.'_'.$type; /** @var LabelProfileRepository $repo */ $repo = $this->entityManager->getRepository(LabelProfile::class); @@ -56,4 +58,4 @@ final class LabelProfileDropdownHelper return $repo->getDropdownProfiles($type); }); } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/LabelTextReplacer.php b/src/Services/LabelSystem/LabelTextReplacer.php index abf4c401..1413d7ab 100644 --- a/src/Services/LabelSystem/LabelTextReplacer.php +++ b/src/Services/LabelSystem/LabelTextReplacer.php @@ -1,4 +1,7 @@ providers as $provider) { /** @var PlaceholderProviderInterface $provider */ $ret = $provider->replace($placeholder, $target); - if ($ret !== null) { + if (null !== $ret) { return $ret; } } @@ -58,8 +62,10 @@ final class LabelTextReplacer /** * 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. */ public function replace(string $lines, object $target): string @@ -72,4 +78,4 @@ final class LabelTextReplacer return preg_replace_callback_array($patterns, $lines); } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/PlaceholderProviders/AbstractDBElementProvider.php b/src/Services/LabelSystem/PlaceholderProviders/AbstractDBElementProvider.php index 1b60dfd3..734edcf9 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/AbstractDBElementProvider.php +++ b/src/Services/LabelSystem/PlaceholderProviders/AbstractDBElementProvider.php @@ -1,4 +1,7 @@ elementTypeNameGenerator = $elementTypeNameGenerator; } - /** - * @inheritDoc - */ public function replace(string $placeholder, object $label_target, array $options = []): ?string { if ($label_target instanceof AbstractDBElement) { - - if ($placeholder === '[[TYPE]]') { + if ('[[TYPE]]' === $placeholder) { return $this->elementTypeNameGenerator->getLocalizedTypeLabel($label_target); } - if ($placeholder === '[[ID]]') { + if ('[[ID]]' === $placeholder) { return (string) ($label_target->getID() ?? 'unknown'); } - } return null; } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/PlaceholderProviders/GlobalProviders.php b/src/Services/LabelSystem/PlaceholderProviders/GlobalProviders.php index 3b6093e0..919ba58c 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/GlobalProviders.php +++ b/src/Services/LabelSystem/PlaceholderProviders/GlobalProviders.php @@ -1,4 +1,7 @@ security = $security; } - /** - * @inheritDoc - */ public function replace(string $placeholder, object $label_target, array $options = []): ?string { - if ($placeholder === "[[INSTALL_NAME]]") { + if ('[[INSTALL_NAME]]' === $placeholder) { return $this->partdb_title; } - $user = $this->security->getUser(); - if ($placeholder === "[[USERNAME]]") { + if ('[[USERNAME]]' === $placeholder) { if ($user instanceof User) { return $user->getName(); } + return 'anonymous'; } - if ($placeholder === "[[USERNAME_FULL]]") { + if ('[[USERNAME_FULL]]' === $placeholder) { if ($user instanceof User) { return $user->getFullName(true); } + return 'anonymous'; } $now = new \DateTime(); - if ($placeholder === '[[DATETIME]]') { + if ('[[DATETIME]]' === $placeholder) { $formatter = IntlDateFormatter::create( Locale::getDefault(), IntlDateFormatter::SHORT, @@ -80,7 +78,7 @@ final class GlobalProviders implements PlaceholderProviderInterface return $formatter->format($now); } - if ($placeholder === '[[DATE]]') { + if ('[[DATE]]' === $placeholder) { $formatter = IntlDateFormatter::create( Locale::getDefault(), IntlDateFormatter::SHORT, @@ -91,7 +89,7 @@ final class GlobalProviders implements PlaceholderProviderInterface return $formatter->format($now); } - if ($placeholder === '[[TIME]]') { + if ('[[TIME]]' === $placeholder) { $formatter = IntlDateFormatter::create( Locale::getDefault(), IntlDateFormatter::NONE, @@ -104,4 +102,4 @@ final class GlobalProviders implements PlaceholderProviderInterface return null; } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/PlaceholderProviders/NamedElementProvider.php b/src/Services/LabelSystem/PlaceholderProviders/NamedElementProvider.php index fdaf6031..ca77f83d 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/NamedElementProvider.php +++ b/src/Services/LabelSystem/PlaceholderProviders/NamedElementProvider.php @@ -1,4 +1,7 @@ getName(); } return null; } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/PlaceholderProviders/PartLotProvider.php b/src/Services/LabelSystem/PlaceholderProviders/PartLotProvider.php index 0635a91c..38dc9cf7 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/PartLotProvider.php +++ b/src/Services/LabelSystem/PlaceholderProviders/PartLotProvider.php @@ -1,4 +1,7 @@ getID() ?? 'unknown'; } - if ($placeholder === '[[LOT_NAME]]') { + if ('[[LOT_NAME]]' === $placeholder) { return $label_target->getName(); } - if ($placeholder === '[[LOT_COMMENT]]') { + if ('[[LOT_COMMENT]]' === $placeholder) { return $label_target->getComment(); } - if ($placeholder === '[[EXPIRATION_DATE]]') { - if ($label_target->getExpirationDate() === null) { + if ('[[EXPIRATION_DATE]]' === $placeholder) { + if (null === $label_target->getExpirationDate()) { return ''; } $formatter = IntlDateFormatter::create( @@ -67,25 +69,25 @@ final class PartLotProvider implements PlaceholderProviderInterface return $formatter->format($label_target->getExpirationDate()); } - if ($placeholder === '[[AMOUNT]]') { + if ('[[AMOUNT]]' === $placeholder) { if ($label_target->isInstockUnknown()) { return '?'; } + 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() : ''; } - if ($placeholder === '[[LOCATION_FULL]]') { + if ('[[LOCATION_FULL]]' === $placeholder) { return $label_target->getStorageLocation() ? $label_target->getStorageLocation()->getFullPath() : ''; } - return $this->labelTextReplacer->handlePlaceholder($placeholder, $label_target->getPart()); } return null; } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/PlaceholderProviders/PartProvider.php b/src/Services/LabelSystem/PlaceholderProviders/PartProvider.php index b6fb5e02..3098c1cc 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/PartProvider.php +++ b/src/Services/LabelSystem/PlaceholderProviders/PartProvider.php @@ -1,4 +1,7 @@ translator = $translator; } - /** - * @inheritDoc - */ public function replace(string $placeholder, object $part, array $options = []): ?string { - if (!$part instanceof Part) { + if (! $part instanceof Part) { return null; } - if ($placeholder === '[[CATEGORY]]') { + if ('[[CATEGORY]]' === $placeholder) { return $part->getCategory() ? $part->getCategory()->getName() : ''; } - if ($placeholder === '[[CATEGORY_FULL]]') { + if ('[[CATEGORY_FULL]]' === $placeholder) { return $part->getCategory() ? $part->getCategory()->getFullPath() : ''; } - if ($placeholder === '[[MANUFACTURER]]') { + if ('[[MANUFACTURER]]' === $placeholder) { return $part->getManufacturer() ? $part->getManufacturer()->getName() : ''; } - if ($placeholder === '[[MANUFACTURER_FULL]]') { + if ('[[MANUFACTURER_FULL]]' === $placeholder) { return $part->getManufacturer() ? $part->getManufacturer()->getFullPath() : ''; } - if ($placeholder === '[[FOOTPRINT]]') { + if ('[[FOOTPRINT]]' === $placeholder) { return $part->getFootprint() ? $part->getFootprint()->getName() : ''; } - if ($placeholder === '[[FOOTPRINT_FULL]]') { + if ('[[FOOTPRINT_FULL]]' === $placeholder) { return $part->getFootprint() ? $part->getFootprint()->getFullPath() : ''; } - if ($placeholder === '[[MASS]]') { + if ('[[MASS]]' === $placeholder) { return $part->getMass() ? $this->siFormatter->format($part->getMass(), 'g', 1) : ''; } - if ($placeholder === '[[MPN]]') { + if ('[[MPN]]' === $placeholder) { return $part->getManufacturerProductNumber(); } - if ($placeholder === '[[TAGS]]') { + if ('[[TAGS]]' === $placeholder) { return $part->getTags(); } - if ($placeholder === '[[M_STATUS]]') { - if ($part->getManufacturingStatus() === '') { + if ('[[M_STATUS]]' === $placeholder) { + if ('' === $part->getManufacturingStatus()) { return ''; } - return $this->translator->trans('m_status.' . $part->getManufacturingStatus()); + + return $this->translator->trans('m_status.'.$part->getManufacturingStatus()); } $parsedown = new \Parsedown(); - if ($placeholder === '[[DESCRIPTION]]') { + if ('[[DESCRIPTION]]' === $placeholder) { return $parsedown->line($part->getDescription()); } - if ($placeholder === '[[DESCRIPTION_T]]') { + if ('[[DESCRIPTION_T]]' === $placeholder) { return strip_tags($parsedown->line($part->getDescription())); } - if ($placeholder === '[[COMMENT]]') { + if ('[[COMMENT]]' === $placeholder) { return $parsedown->line($part->getComment()); } - if ($placeholder === '[[COMMENT_T]]') { + if ('[[COMMENT_T]]' === $placeholder) { return strip_tags($parsedown->line($part->getComment())); } return null; } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/PlaceholderProviders/PlaceholderProviderInterface.php b/src/Services/LabelSystem/PlaceholderProviders/PlaceholderProviderInterface.php index 4bf62049..cb259dcc 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/PlaceholderProviderInterface.php +++ b/src/Services/LabelSystem/PlaceholderProviders/PlaceholderProviderInterface.php @@ -1,4 +1,7 @@ getComment(); } - if ($placeholder === '[[COMMENT_T]]') { + if ('[[COMMENT_T]]' === $placeholder) { return strip_tags($label_target->getComment()); } - if ($placeholder === '[[FULL_PATH]]') { + if ('[[FULL_PATH]]' === $placeholder) { return $label_target->getFullPath(); } - if ($placeholder === '[[PARENT]]') { + if ('[[PARENT]]' === $placeholder) { 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 null; } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/PlaceholderProviders/TimestampableElementProvider.php b/src/Services/LabelSystem/PlaceholderProviders/TimestampableElementProvider.php index 4cb295cb..d4b5ac0a 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/TimestampableElementProvider.php +++ b/src/Services/LabelSystem/PlaceholderProviders/TimestampableElementProvider.php @@ -1,4 +1,7 @@ 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 null; } -} \ No newline at end of file +} diff --git a/src/Services/LabelSystem/SandboxedTwigProvider.php b/src/Services/LabelSystem/SandboxedTwigProvider.php index 630820fe..c794741c 100644 --- a/src/Services/LabelSystem/SandboxedTwigProvider.php +++ b/src/Services/LabelSystem/SandboxedTwigProvider.php @@ -1,4 +1,7 @@ ['getID', '__toString'], TimeStampableInterface::class => ['getLastModified', 'getAddedDate'], AbstractStructuralDBElement::class => ['isChildOf', 'isRoot', 'getParent', 'getComment', 'getLevel', - 'getFullPath', 'getPathArray', 'getChildren', 'isNotSelectable'], + 'getFullPath', 'getPathArray', 'getChildren', 'isNotSelectable', ], AbstractCompany::class => ['getAddress', 'getPhoneNumber', 'getFaxNumber', 'getEmailAddress', 'getWebsite'], AttachmentContainingDBElement::class => ['getAttachments', 'getMasterPictureAttachment'], 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', - 'getValueTypical', 'getUnit', 'getValueText'], + 'getValueTypical', 'getUnit', 'getValueText', ], MeasurementUnit::class => ['getUnit', 'isInteger', 'useSIPrefix'], PartLot::class => ['isExpired', 'getDescription', 'getComment', 'getExpirationDate', 'getStorageLocation', - 'getPart', 'isInstockUnknown', 'getAmount', 'getNeedsRefill'], + 'getPart', 'isInstockUnknown', 'getAmount', 'getNeedsRefill', ], Storelocation::class => ['isFull', 'isOnlySinglePart', 'isLimitToExistingParts', 'getStorageType'], Supplier::class => ['getShippingCosts', 'getDefaultCurrency'], Part::class => ['isNeedsReview', 'getTags', 'getMass', 'getDescription', 'isFavorite', 'getCategory', 'getFootprint', 'getPartLots', 'getPartUnit', 'useFloatAmount', 'getMinAmount', 'getAmountSum', 'getManufacturerProductUrl', 'getCustomProductURL', 'getManufacturingStatus', 'getManufacturer', - 'getManufacturerProductNumber', 'getOrderdetails', 'isObsolete'], + 'getManufacturerProductNumber', 'getOrderdetails', 'isObsolete', ], Currency::class => ['getIsoCode', 'getInverseExchangeRate', 'getExchangeRate'], Orderdetail::class => ['getPart', 'getSupplier', 'getSupplierPartNr', 'getObsolete', 'getPricedetails', 'findPriceForQty', ], Pricedetail::class => ['getOrderdetail', 'getPrice', 'getPricePerUnit', 'getPriceRelatedQuantity', - 'getMinDiscountQuantity', 'getCurrency'], + 'getMinDiscountQuantity', 'getCurrency', ], //Only allow very little information about users... User::class => ['isAnonymousUser', 'getUsername', 'getFullName', 'getFirstName', 'getLastName', - 'getDepartment', 'getEmail'] - + 'getDepartment', 'getEmail', ], ]; private const ALLOWED_PROPERTIES = []; @@ -104,14 +103,13 @@ final class SandboxedTwigProvider 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"!'); } - $loader = new \Twig\Loader\ArrayLoader([ - 'lines' => $options->getLines(), - ]); + 'lines' => $options->getLines(), + ]); $twig = new Environment($loader); //Second argument activate sandbox globally. @@ -127,7 +125,7 @@ final class SandboxedTwigProvider return $twig; } - protected function getSecurityPolicy(): SecurityPolicyInterface + private function getSecurityPolicy(): SecurityPolicyInterface { return new InheritanceSecurityPolicy( self::ALLOWED_TAGS, @@ -137,4 +135,4 @@ final class SandboxedTwigProvider self::ALLOWED_FUNCTIONS ); } -} \ No newline at end of file +} diff --git a/src/Services/Misc/RangeParser.php b/src/Services/Misc/RangeParser.php index 3714878f..ea857dbf 100644 --- a/src/Services/Misc/RangeParser.php +++ b/src/Services/Misc/RangeParser.php @@ -1,4 +1,7 @@ parse($range_str); + return true; } catch (\InvalidArgumentException $exception) { return false; @@ -86,9 +94,9 @@ class RangeParser $tmp = []; while ($min <= $max) { $tmp[] = $min; - $min++; - }; + ++$min; + } return $tmp; } -} \ No newline at end of file +} diff --git a/src/Services/SIFormatter.php b/src/Services/SIFormatter.php index 0a736d84..4a60b8b1 100644 --- a/src/Services/SIFormatter.php +++ b/src/Services/SIFormatter.php @@ -105,6 +105,7 @@ class SIFormatter * @param float $value The value that should be converted * @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 + * * @return string The formatted value */ public function format(float $value, string $unit = '', int $decimals = 2): string diff --git a/src/Services/Trees/ToolsTreeBuilder.php b/src/Services/Trees/ToolsTreeBuilder.php index 184359f8..f9388e11 100644 --- a/src/Services/Trees/ToolsTreeBuilder.php +++ b/src/Services/Trees/ToolsTreeBuilder.php @@ -211,7 +211,6 @@ class ToolsTreeBuilder ); } - return $nodes; } diff --git a/src/Services/Trees/TreeViewGenerator.php b/src/Services/Trees/TreeViewGenerator.php index 1aff2ab4..f0a406d2 100644 --- a/src/Services/Trees/TreeViewGenerator.php +++ b/src/Services/Trees/TreeViewGenerator.php @@ -118,13 +118,13 @@ class TreeViewGenerator $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()); $item->setHref($this->urlGenerator->getURL($entity, $href_type)); } //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))); } } diff --git a/src/Twig/Sandbox/InheritanceSecurityPolicy.php b/src/Twig/Sandbox/InheritanceSecurityPolicy.php index 3f0a32d8..5ad6d007 100644 --- a/src/Twig/Sandbox/InheritanceSecurityPolicy.php +++ b/src/Twig/Sandbox/InheritanceSecurityPolicy.php @@ -1,5 +1,7 @@ allowedTags)) { + if (! \in_array($tag, $this->allowedTags, true)) { throw new SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); } } 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); } } 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); } } @@ -103,7 +105,7 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface $method = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); foreach ($this->allowedMethods as $class => $methods) { 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 if ($allowed) { @@ -112,8 +114,9 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface } } - if (!$allowed) { + if (! $allowed) { $class = \get_class($obj); + 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; foreach ($this->allowedProperties as $class => $properties) { 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 if ($allowed) { @@ -132,8 +135,9 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface } } - if (!$allowed) { + if (! $allowed) { $class = \get_class($obj); + throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); } } diff --git a/src/Validator/Constraints/Misc/ValidRange.php b/src/Validator/Constraints/Misc/ValidRange.php index 9f7e33d5..d3760731 100644 --- a/src/Validator/Constraints/Misc/ValidRange.php +++ b/src/Validator/Constraints/Misc/ValidRange.php @@ -1,4 +1,7 @@ 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); } @@ -49,13 +50,13 @@ class ValidRangeValidator extends ConstraintValidator return; } - if (!is_string($value)) { + if (! is_string($value)) { throw new UnexpectedValueException($value, 'string'); } - if(!$this->rangeParser->isValidRange($value)) { + if (! $this->rangeParser->isValidRange($value)) { $this->context->buildViolation($constraint->message) ->addViolation(); } } -} \ No newline at end of file +} diff --git a/tests/Controller/AdminPages/LabelProfileControllerTest.php b/tests/Controller/AdminPages/LabelProfileControllerTest.php index 37328046..0441055d 100644 --- a/tests/Controller/AdminPages/LabelProfileControllerTest.php +++ b/tests/Controller/AdminPages/LabelProfileControllerTest.php @@ -1,4 +1,7 @@ assertSame($delete, $client->getResponse()->isRedirect(static::$base_path.'/new')); $this->assertSame($delete, ! $client->getResponse()->isForbidden(), 'Permission Checking not working!'); } -} \ No newline at end of file +} diff --git a/tests/Services/LabelSystem/BarcodeGeneratorTest.php b/tests/Services/LabelSystem/BarcodeGeneratorTest.php index 191d969d..06130587 100644 --- a/tests/Services/LabelSystem/BarcodeGeneratorTest.php +++ b/tests/Services/LabelSystem/BarcodeGeneratorTest.php @@ -1,4 +1,7 @@ services = self::$container->get(BarcodeGenerator::class); @@ -50,7 +53,7 @@ final class BarcodeGeneratorTest extends WebTestCase $content = $this->services->generateSVG($options, $part); //When type is none, service must return null. - if ($type === 'none') { + if ('none' === $type) { $this->assertNull($content); } else { $this->assertIsString($content); @@ -70,10 +73,10 @@ final class BarcodeGeneratorTest extends WebTestCase $svg = $this->services->generateSVG($options, $part); //When type is none, service must return null. - if ($type === "none") { + if ('none' === $type) { $this->assertNull($svg); } else { - $this->assertStringContainsStringIgnoringCase("SVG", $svg); + $this->assertStringContainsStringIgnoringCase('SVG', $svg); } } } diff --git a/tests/Services/LabelSystem/Barcodes/BarcodeContentGeneratorTest.php b/tests/Services/LabelSystem/Barcodes/BarcodeContentGeneratorTest.php index b90dc809..42f0e594 100644 --- a/tests/Services/LabelSystem/Barcodes/BarcodeContentGeneratorTest.php +++ b/tests/Services/LabelSystem/Barcodes/BarcodeContentGeneratorTest.php @@ -1,4 +1,7 @@ service = self::$container->get(BarcodeContentGenerator::class); } - public function Barcode1DDataProvider(): array { return [ @@ -53,7 +56,7 @@ class BarcodeContentGeneratorTest extends KernelTestCase return [ ['/scan/part/0', Part::class], ['/scan/lot/0', PartLot::class], - ['/scan/location/0', Storelocation::class] + ['/scan/location/0', Storelocation::class], ]; } diff --git a/tests/Services/LabelSystem/Barcodes/BarcodeNormalizerTest.php b/tests/Services/LabelSystem/Barcodes/BarcodeNormalizerTest.php index b1d78760..50ee6e1b 100644 --- a/tests/Services/LabelSystem/Barcodes/BarcodeNormalizerTest.php +++ b/tests/Services/LabelSystem/Barcodes/BarcodeNormalizerTest.php @@ -1,4 +1,7 @@ service = self::$container->get(BarcodeNormalizer::class); @@ -80,7 +83,7 @@ class BarcodeNormalizerTest extends WebTestCase /** * @dataProvider dataProvider */ - public function testNormalizeBarcodeContent(array $expected, string $input) + public function testNormalizeBarcodeContent(array $expected, string $input): void { $this->assertSame($expected, $this->service->normalizeBarcodeContent($input)); } @@ -88,7 +91,7 @@ class BarcodeNormalizerTest extends WebTestCase /** * @dataProvider invalidDataProvider */ - public function testInvalidFormats(string $input) + public function testInvalidFormats(string $input): void { $this->expectException(\InvalidArgumentException::class); $this->service->normalizeBarcodeContent($input); diff --git a/tests/Services/LabelSystem/Barcodes/BarcodeRedirectorTest.php b/tests/Services/LabelSystem/Barcodes/BarcodeRedirectorTest.php index 2e0e35dd..2ed38fb5 100644 --- a/tests/Services/LabelSystem/Barcodes/BarcodeRedirectorTest.php +++ b/tests/Services/LabelSystem/Barcodes/BarcodeRedirectorTest.php @@ -1,4 +1,7 @@ service = self::$container->get(BarcodeRedirector::class); @@ -42,7 +46,7 @@ class BarcodeRedirectorTest extends KernelTestCase ['part', '/en/part/1'], //Part lot redirects to Part info page (Part lot 1 is associated with part 3 ['lot', '/en/part/3'], - ['location', '/en/store_location/1/parts'] + ['location', '/en/store_location/1/parts'], ]; } diff --git a/tests/Services/LabelSystem/LabelGeneratorTest.php b/tests/Services/LabelSystem/LabelGeneratorTest.php index b9266b56..bb1d9ba6 100644 --- a/tests/Services/LabelSystem/LabelGeneratorTest.php +++ b/tests/Services/LabelSystem/LabelGeneratorTest.php @@ -1,4 +1,7 @@ service = self::$container->get(LabelGenerator::class); @@ -45,14 +49,14 @@ class LabelGeneratorTest extends WebTestCase return [ ['part', Part::class], ['part_lot', PartLot::class], - ['storelocation', Storelocation::class] + ['storelocation', Storelocation::class], ]; } /** * @dataProvider supportsDataProvider */ - public function testSupports(string $type, string $class) + public function testSupports(string $type, string $class): void { $options = new LabelOptions(); $options->setSupportedElement($type); @@ -61,18 +65,17 @@ class LabelGeneratorTest extends WebTestCase $this->assertTrue($this->service->supports($options, new $class())); //Ensure that another class is not supported - $not_supported = new class extends AbstractDBElement { - + $not_supported = new class() extends AbstractDBElement { public function getIDString(): string { - return "not_important"; + return 'not_important'; } }; $this->assertFalse($this->service->supports($options, $not_supported)); } - public function testMmToPointsArray() + public function testMmToPointsArray(): void { $this->assertSame( [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(); $options = new LabelOptions(); diff --git a/tests/Services/LabelSystem/LabelTextReplacerTest.php b/tests/Services/LabelSystem/LabelTextReplacerTest.php index 1d677f6c..8bf002e7 100644 --- a/tests/Services/LabelSystem/LabelTextReplacerTest.php +++ b/tests/Services/LabelSystem/LabelTextReplacerTest.php @@ -1,4 +1,7 @@ service = self::$container->get(AbstractDBElementProvider::class); - $this->target = new class extends AbstractDBElement { + $this->target = new class() extends AbstractDBElement { protected $id = 123; - /** - * @inheritDoc - */ public function getIDString(): string { return 'ignore'; diff --git a/tests/Services/LabelSystem/PlaceholderProviders/GlobalProvidersTest.php b/tests/Services/LabelSystem/PlaceholderProviders/GlobalProvidersTest.php index 07bd2a87..f338266a 100644 --- a/tests/Services/LabelSystem/PlaceholderProviders/GlobalProvidersTest.php +++ b/tests/Services/LabelSystem/PlaceholderProviders/GlobalProvidersTest.php @@ -1,4 +1,7 @@ service = self::$container->get(GlobalProviders::class); diff --git a/tests/Services/LabelSystem/PlaceholderProviders/NamedElementProviderTest.php b/tests/Services/LabelSystem/PlaceholderProviders/NamedElementProviderTest.php index 06308738..cc98be83 100644 --- a/tests/Services/LabelSystem/PlaceholderProviders/NamedElementProviderTest.php +++ b/tests/Services/LabelSystem/PlaceholderProviders/NamedElementProviderTest.php @@ -1,4 +1,7 @@ service = self::$container->get(NamedElementProvider::class); - $this->target = new class implements NamedElementInterface { - - /** - * @inheritDoc - */ + $this->target = new class() implements NamedElementInterface { public function getName(): string { return 'This is my Name'; @@ -53,7 +51,7 @@ class NamedElementProviderTest extends WebTestCase public function dataProvider(): array { return [ - ['This is my Name', '[[NAME]]'] + ['This is my Name', '[[NAME]]'], ]; } diff --git a/tests/Services/LabelSystem/PlaceholderProviders/PartLotProviderTest.php b/tests/Services/LabelSystem/PlaceholderProviders/PartLotProviderTest.php index c430fad2..95dca4cb 100644 --- a/tests/Services/LabelSystem/PlaceholderProviders/PartLotProviderTest.php +++ b/tests/Services/LabelSystem/PlaceholderProviders/PartLotProviderTest.php @@ -1,4 +1,7 @@ service = self::$container->get(PartProvider::class); diff --git a/tests/Services/LabelSystem/PlaceholderProviders/TimestampableElementProviderTest.php b/tests/Services/LabelSystem/PlaceholderProviders/TimestampableElementProviderTest.php index 2bf3bcaa..a4b9611b 100644 --- a/tests/Services/LabelSystem/PlaceholderProviders/TimestampableElementProviderTest.php +++ b/tests/Services/LabelSystem/PlaceholderProviders/TimestampableElementProviderTest.php @@ -1,4 +1,7 @@ service = self::$container->get(TimestampableElementProvider::class); - $this->target = new class implements TimeStampableInterface { - - /** - * @inheritDoc - */ + $this->target = new class() implements TimeStampableInterface { public function getLastModified(): ?DateTime { return new \DateTime('2000-01-01'); } - /** - * @inheritDoc - */ public function getAddedDate(): ?DateTime { return new \DateTime('2000-01-01'); diff --git a/tests/Services/LabelSystem/SandboxedTwigProviderTest.php b/tests/Services/LabelSystem/SandboxedTwigProviderTest.php index 43e1a8b3..b9cc6849 100644 --- a/tests/Services/LabelSystem/SandboxedTwigProviderTest.php +++ b/tests/Services/LabelSystem/SandboxedTwigProviderTest.php @@ -1,4 +1,7 @@ service = self::$container->get(SandboxedTwigProvider::class); @@ -65,26 +68,25 @@ class SandboxedTwigProviderTest extends WebTestCase '], [' {{ part.reviewNeeded }} {{ part.tags }} {{ part.mass }} - '] + '], ]; } public function twigNotAllowedDataProvider(): array { return [ - ["{% block test %} {% endblock %}"], - ["{% deprecated test %}"], - ["{% flush %}"], + ['{% block test %} {% endblock %}'], + ['{% deprecated test %}'], + ['{% flush %}'], ["{{ part.setName('test') }}"], - ["{{ part.setCategory(null) }}"] + ['{{ part.setCategory(null) }}'], ]; } - /** * @dataProvider twigDataProvider */ - public function testTwigFeatures(string $twig) + public function testTwigFeatures(string $twig): void { $options = new LabelOptions(); $options->setSupportedElement('part'); @@ -104,7 +106,7 @@ class SandboxedTwigProviderTest extends WebTestCase /** * @dataProvider twigNotAllowedDataProvider */ - public function testTwigForbidden(string $twig) + public function testTwigForbidden(string $twig): void { $this->expectException(SecurityError::class); diff --git a/tests/Services/Misc/RangeParserTest.php b/tests/Services/Misc/RangeParserTest.php index f4c28077..b6023534 100644 --- a/tests/Services/Misc/RangeParserTest.php +++ b/tests/Services/Misc/RangeParserTest.php @@ -1,4 +1,7 @@ service = self::$container->get(RangeParser::class); @@ -42,19 +45,19 @@ class RangeParserTest extends WebTestCase [[], ''], [[], ' '], [[], "\t"], - [[1], "1"], - [[1, 2, 3], "1,2, 3"], - [[1, 2, 3], "1-3"], - [[1, 2, 3, 4], "1- 3, 4"], - [[1, 2, 3, 4], "1, 2,3 - 4"], - [[1, 2, 3], " 1; 2, 3"], - [[-1, 0, 1, 2], "-1; 0; 1, 2"], - [[4,3, 1, 2], "4,3, 1;2"], - [[1, 2, 3, 4], "2-1, 3-4"], - [[1], "1-1"], - [[-3, -2, -1], "-3--1"], - [[1, 2, 3], "1,,2;;,,3"], - [[100, 1000, 1], "100, 1000, 1"], + [[1], '1'], + [[1, 2, 3], '1,2, 3'], + [[1, 2, 3], '1-3'], + [[1, 2, 3, 4], '1- 3, 4'], + [[1, 2, 3, 4], '1, 2,3 - 4'], + [[1, 2, 3], ' 1; 2, 3'], + [[-1, 0, 1, 2], '-1; 0; 1, 2'], + [[4, 3, 1, 2], '4,3, 1;2'], + [[1, 2, 3, 4], '2-1, 3-4'], + [[1], '1-1'], + [[-3, -2, -1], '-3--1'], + [[1, 2, 3], '1,,2;;,,3'], + [[100, 1000, 1], '100, 1000, 1'], [[], 'test', true], [[], '1-2-3-4,5', true], [[], '1 2 3, 455, 23', true], diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 469dccee..cc712a19 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,5 +1,7 @@