From e01b06fb85bd04b6bd0d5c87ae8e8dea46c99261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Fri, 21 Aug 2020 22:43:37 +0200 Subject: [PATCH] Fixed some inspection issues. --- assets/css/app.css | 6 +++--- src/Command/CleanAttachmentsCommand.php | 2 +- src/Configuration/PermissionsConfiguration.php | 2 +- .../AdminPages/AttachmentTypeController.php | 8 +++----- .../AdminPages/BaseAdminController.php | 4 ++-- .../AdminPages/CurrencyController.php | 8 +++----- .../AdminPages/ManufacturerController.php | 2 +- .../AdminPages/MeasurementUnitController.php | 4 ++-- .../AdminPages/StorelocationController.php | 5 +++-- .../AdminPages/SupplierController.php | 5 +++-- src/Controller/GroupController.php | 8 +++----- src/Controller/LabelController.php | 4 ++-- src/Controller/TypeaheadController.php | 4 ++-- src/Controller/UserController.php | 5 +++-- src/DataTables/Adapter/FetchJoinORMAdapter.php | 2 +- src/DataTables/Adapter/ORMAdapter.php | 10 ++++++---- src/DataTables/Column/EntityColumn.php | 2 +- src/DataTables/Column/IconLinkColumn.php | 8 ++++---- src/DataTables/LogDataTable.php | 6 +++--- src/DataTables/PartsDataTable.php | 2 +- src/Entity/LabelSystem/LabelProfile.php | 2 +- src/Entity/LogSystem/SecurityEventLogEntry.php | 6 +----- src/Entity/Parameters/ParametersTrait.php | 2 +- .../LogSystem/EventLoggerSubscriber.php | 9 +++------ .../SecurityEventLoggerSubscriber.php | 2 +- src/EventSubscriber/SetMailFromSubscriber.php | 2 +- .../SymfonyDebugToolbarSubscriber.php | 2 +- .../UserSystem/LoginSuccessSubscriber.php | 2 +- .../LogoutDisabledUserSubscriber.php | 2 +- .../PasswordChangeNeededSubscriber.php | 8 ++------ .../UserSystem/SetUserTimezoneSubscriber.php | 2 +- src/Events/SecurityEvent.php | 2 +- .../AdminPages/AttachmentTypeAdminForm.php | 2 +- src/Form/AttachmentFormType.php | 7 +++---- src/Form/CollectionTypeExtension.php | 1 - src/Form/LabelOptionsType.php | 2 +- src/Form/Part/PartBaseType.php | 1 - src/Form/Permissions/PermissionGroupType.php | 9 +++------ src/Form/Permissions/PermissionType.php | 4 ++-- src/Form/Permissions/PermissionsMapper.php | 4 ++-- src/Form/Permissions/PermissionsType.php | 2 +- src/Form/TFAGoogleSettingsType.php | 3 +-- src/Form/Type/MasterPictureAttachmentType.php | 9 +++++---- src/Form/Type/SIUnitType.php | 10 +++++----- src/Form/Type/StructuralEntityType.php | 5 +---- src/Form/UserAdminForm.php | 3 +-- src/Form/UserSettingsType.php | 2 +- src/Helpers/LabelResponse.php | 7 +++---- .../Trees/StructuralDBElementIterator.php | 2 +- src/Helpers/Trees/TreeViewNodeIterator.php | 2 +- .../ElementPermissionListener.php | 17 ++++++----------- src/Security/Voter/ExtendedVoter.php | 2 +- src/Security/Voter/PartVoter.php | 1 - src/Security/Voter/UserVoter.php | 18 ++++++++---------- src/Services/AmountFormatter.php | 10 +++++----- .../Attachments/AttachmentReverseSearch.php | 1 - .../Attachments/FileTypeFilterTools.php | 6 +++--- src/Services/CustomEnvVarProcessor.php | 3 ++- src/Services/EntityExporter.php | 9 +-------- src/Services/EntityImporter.php | 2 +- src/Services/GitVersionInfo.php | 4 ++-- src/Services/LabelSystem/LabelGenerator.php | 2 +- .../LabelSystem/LabelHTMLGenerator.php | 4 ++-- .../PlaceholderProviders/PartLotProvider.php | 2 +- .../LogSystem/LogEntryExtraFormatter.php | 14 ++++++-------- src/Services/LogSystem/TimeTravel.php | 15 +++++++-------- src/Services/MoneyFormatter.php | 2 +- src/Services/PricedetailHelper.php | 2 +- src/Services/TagFinder.php | 2 +- src/Services/Trees/TreeViewGenerator.php | 2 +- src/Twig/AppExtension.php | 10 +++++----- src/Twig/BarcodeExtension.php | 2 +- src/Twig/Sandbox/InheritanceSecurityPolicy.php | 3 ++- src/Twig/TypeLabelExtension.php | 2 +- .../Constraints/NoLockoutValidator.php | 14 ++++++++------ .../Constraints/NoneOfItsChildren.php | 5 ----- .../Constraints/SelectableValidator.php | 2 +- .../Constraints/ValidPartLotValidator.php | 14 ++++++-------- tests/Controller/RedirectControllerTest.php | 4 ++-- .../PasswordChangeNeededSubscriberTest.php | 4 ++-- 80 files changed, 173 insertions(+), 218 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index 7202e652..461dfb26 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -66,6 +66,7 @@ body { /** Hide scrollbar in old Firefox and Edge **/ -ms-overflow-style: none; overflow: -moz-scrollbars-none; + /*noinspection CssUnknownProperty*/ scrollbar-width: none; } @@ -764,7 +765,6 @@ div.dataTables_wrapper div.dataTables_info { margin-top: 4px; padding: 4px 0; background-color: #fff; - border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.2); -webkit-border-radius: 4px; -moz-border-radius: 4px; @@ -805,7 +805,7 @@ div.dataTables_wrapper div.dataTables_info { .markdown pre { display: block; - padding: 9.5px; + padding: 10px; margin: 0 0 10px; font-size: 13px; line-height: 1.42857143; @@ -825,7 +825,7 @@ div.dataTables_wrapper div.dataTables_info { .markdown blockquote { padding: 10px 10px; margin: 0 0 10px; - font-size: 17.5px; + font-size: 18px; border-left: 5px solid #aaa; } diff --git a/src/Command/CleanAttachmentsCommand.php b/src/Command/CleanAttachmentsCommand.php index 2622c99c..4c11ac36 100644 --- a/src/Command/CleanAttachmentsCommand.php +++ b/src/Command/CleanAttachmentsCommand.php @@ -148,7 +148,7 @@ class CleanAttachmentsCommand extends Command * * @return bool */ - protected function removeEmptySubFolders($path) + protected function removeEmptySubFolders($path): bool { $empty = true; foreach (glob($path.DIRECTORY_SEPARATOR.'*') as $file) { diff --git a/src/Configuration/PermissionsConfiguration.php b/src/Configuration/PermissionsConfiguration.php index dd01423d..b2aef933 100644 --- a/src/Configuration/PermissionsConfiguration.php +++ b/src/Configuration/PermissionsConfiguration.php @@ -52,7 +52,7 @@ final class PermissionsConfiguration implements ConfigurationInterface * * @return TreeBuilder The tree builder */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('permissions'); $rootNode = $treeBuilder->getRootNode(); diff --git a/src/Controller/AdminPages/AttachmentTypeController.php b/src/Controller/AdminPages/AttachmentTypeController.php index 2395ff3c..58fbb27b 100644 --- a/src/Controller/AdminPages/AttachmentTypeController.php +++ b/src/Controller/AdminPages/AttachmentTypeController.php @@ -113,12 +113,10 @@ class AttachmentTypeController extends BaseAdminController protected function deleteCheck(AbstractNamedDBElement $entity): bool { - if ($entity instanceof AttachmentType) { - if ($entity->getAttachmentsForType()->count() > 0) { - $this->addFlash('error', 'entity.delete.must_not_contain_attachments'); + if (($entity instanceof AttachmentType) && $entity->getAttachmentsForType()->count() > 0) { + $this->addFlash('error', 'entity.delete.must_not_contain_attachments'); - return false; - } + return false; } return true; diff --git a/src/Controller/AdminPages/BaseAdminController.php b/src/Controller/AdminPages/BaseAdminController.php index 3d3e34d4..c625da0d 100644 --- a/src/Controller/AdminPages/BaseAdminController.php +++ b/src/Controller/AdminPages/BaseAdminController.php @@ -192,7 +192,7 @@ abstract class BaseAdminController extends AbstractController $form_options = [ 'attachment_class' => $this->attachment_class, 'parameter_class' => $this->parameter_class, - 'disabled' => null !== $timeTravel_timestamp ? true : false, + 'disabled' => null !== $timeTravel_timestamp, ]; //Disable editing of options, if user is not allowed to use twig... @@ -476,7 +476,7 @@ abstract class BaseAdminController extends AbstractController return $exporter->exportEntityFromRequest($entities, $request); } - protected function _exportEntity(AbstractNamedDBElement $entity, EntityExporter $exporter, Request $request): \Symfony\Component\HttpFoundation\Response + protected function _exportEntity(AbstractNamedDBElement $entity, EntityExporter $exporter, Request $request): Response { $this->denyAccessUnlessGranted('read', $entity); diff --git a/src/Controller/AdminPages/CurrencyController.php b/src/Controller/AdminPages/CurrencyController.php index 98d08921..f523eaba 100644 --- a/src/Controller/AdminPages/CurrencyController.php +++ b/src/Controller/AdminPages/CurrencyController.php @@ -187,12 +187,10 @@ class CurrencyController extends BaseAdminController public function deleteCheck(AbstractNamedDBElement $entity): bool { - if ($entity instanceof Currency) { - if ($entity->getPricedetails()->count() > 0) { - $this->addFlash('error', 'entity.delete.must_not_contain_prices'); + if (($entity instanceof Currency) && $entity->getPricedetails()->count() > 0) { + $this->addFlash('error', 'entity.delete.must_not_contain_prices'); - return false; - } + return false; } return true; diff --git a/src/Controller/AdminPages/ManufacturerController.php b/src/Controller/AdminPages/ManufacturerController.php index 601ab92d..a008ac5e 100644 --- a/src/Controller/AdminPages/ManufacturerController.php +++ b/src/Controller/AdminPages/ManufacturerController.php @@ -82,7 +82,7 @@ class ManufacturerController extends BaseAdminController * * @return Response */ - public function edit(Manufacturer $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null) + public function edit(Manufacturer $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response { return $this->_edit($entity, $request, $em, $timestamp); } diff --git a/src/Controller/AdminPages/MeasurementUnitController.php b/src/Controller/AdminPages/MeasurementUnitController.php index f16af70a..fae7cad6 100644 --- a/src/Controller/AdminPages/MeasurementUnitController.php +++ b/src/Controller/AdminPages/MeasurementUnitController.php @@ -72,7 +72,7 @@ class MeasurementUnitController extends BaseAdminController * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function delete(Request $request, MeasurementUnit $entity, StructuralElementRecursionHelper $recursionHelper) + public function delete(Request $request, MeasurementUnit $entity, StructuralElementRecursionHelper $recursionHelper): \Symfony\Component\HttpFoundation\RedirectResponse { return $this->_delete($request, $entity, $recursionHelper); } @@ -83,7 +83,7 @@ class MeasurementUnitController extends BaseAdminController * * @return Response */ - public function edit(MeasurementUnit $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null) + public function edit(MeasurementUnit $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response { return $this->_edit($entity, $request, $em, $timestamp); } diff --git a/src/Controller/AdminPages/StorelocationController.php b/src/Controller/AdminPages/StorelocationController.php index b1ae63e2..9fe10e7e 100644 --- a/src/Controller/AdminPages/StorelocationController.php +++ b/src/Controller/AdminPages/StorelocationController.php @@ -49,6 +49,7 @@ use App\Services\EntityExporter; use App\Services\EntityImporter; use App\Services\StructuralElementRecursionHelper; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -70,7 +71,7 @@ class StorelocationController extends BaseAdminController * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function delete(Request $request, Storelocation $entity, StructuralElementRecursionHelper $recursionHelper) + public function delete(Request $request, Storelocation $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse { return $this->_delete($request, $entity, $recursionHelper); } @@ -81,7 +82,7 @@ class StorelocationController extends BaseAdminController * * @return Response */ - public function edit(Storelocation $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null) + public function edit(Storelocation $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response { return $this->_edit($entity, $request, $em, $timestamp); } diff --git a/src/Controller/AdminPages/SupplierController.php b/src/Controller/AdminPages/SupplierController.php index 6bad7e04..2d623b7a 100644 --- a/src/Controller/AdminPages/SupplierController.php +++ b/src/Controller/AdminPages/SupplierController.php @@ -50,6 +50,7 @@ use App\Services\EntityExporter; use App\Services\EntityImporter; use App\Services\StructuralElementRecursionHelper; use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -71,7 +72,7 @@ class SupplierController extends BaseAdminController * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function delete(Request $request, Supplier $entity, StructuralElementRecursionHelper $recursionHelper) + public function delete(Request $request, Supplier $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse { return $this->_delete($request, $entity, $recursionHelper); } @@ -82,7 +83,7 @@ class SupplierController extends BaseAdminController * * @return Response */ - public function edit(Supplier $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null) + public function edit(Supplier $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response { return $this->_edit($entity, $request, $em, $timestamp); } diff --git a/src/Controller/GroupController.php b/src/Controller/GroupController.php index 85b1897f..2b6cca8a 100644 --- a/src/Controller/GroupController.php +++ b/src/Controller/GroupController.php @@ -114,12 +114,10 @@ class GroupController extends BaseAdminController public function deleteCheck(AbstractNamedDBElement $entity): bool { - if ($entity instanceof Group) { - if ($entity->getUsers()->count() > 0) { - $this->addFlash('error', 'entity.delete.must_not_contain_users'); + if (($entity instanceof Group) && $entity->getUsers()->count() > 0) { + $this->addFlash('error', 'entity.delete.must_not_contain_users'); - return false; - } + return false; } return true; diff --git a/src/Controller/LabelController.php b/src/Controller/LabelController.php index 33b6d2d3..ac944f38 100644 --- a/src/Controller/LabelController.php +++ b/src/Controller/LabelController.php @@ -34,9 +34,9 @@ use App\Services\LabelSystem\LabelGenerator; use App\Services\Misc\RangeParser; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Form\Form; use Symfony\Component\Form\FormError; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; @@ -65,7 +65,7 @@ class LabelController extends AbstractController * @Route("/dialog", name="label_dialog") * @Route("/{profile}/dialog", name="label_dialog_profile") */ - public function generator(Request $request, ?LabelProfile $profile = null) + public function generator(Request $request, ?LabelProfile $profile = null): Response { $this->denyAccessUnlessGranted('@labels.create_labels'); diff --git a/src/Controller/TypeaheadController.php b/src/Controller/TypeaheadController.php index c68e4941..9f9f12bc 100644 --- a/src/Controller/TypeaheadController.php +++ b/src/Controller/TypeaheadController.php @@ -75,7 +75,7 @@ class TypeaheadController extends AbstractController * * @return JsonResponse */ - public function builtInResources(Request $request, BuiltinAttachmentsFinder $finder) + public function builtInResources(Request $request, BuiltinAttachmentsFinder $finder): JsonResponse { $query = $request->get('query'); $array = $finder->find($query); @@ -106,7 +106,7 @@ class TypeaheadController extends AbstractController * * @return JsonResponse */ - public function tags(string $query, TagFinder $finder) + public function tags(string $query, TagFinder $finder): JsonResponse { $array = $finder->searchTags($query); diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 7a51f6d3..21614807 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -58,6 +58,7 @@ use InvalidArgumentException; use Omines\DataTablesBundle\DataTableFactory; use Symfony\Component\Asset\Packages; use Symfony\Component\Form\FormInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -100,7 +101,7 @@ class UserController extends AdminPages\BaseAdminController * * @throws \Exception */ - public function edit(User $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null) + public function edit(User $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response { //Handle 2FA disabling @@ -170,7 +171,7 @@ class UserController extends AdminPages\BaseAdminController * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ - public function delete(Request $request, User $entity, StructuralElementRecursionHelper $recursionHelper) + public function delete(Request $request, User $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse { if (User::ID_ANONYMOUS === $entity->getID()) { throw new InvalidArgumentException('You can not delete the anonymous user! It is needed for permission checking without a logged in user'); diff --git a/src/DataTables/Adapter/FetchJoinORMAdapter.php b/src/DataTables/Adapter/FetchJoinORMAdapter.php index 9714dd36..c3041834 100644 --- a/src/DataTables/Adapter/FetchJoinORMAdapter.php +++ b/src/DataTables/Adapter/FetchJoinORMAdapter.php @@ -153,7 +153,7 @@ class FetchJoinORMAdapter extends ORMAdapter $query->setIdentifierPropertyPath($this->mapFieldToPropertyPath($identifier, $aliases)); } - protected function getSimpleTotalCount(QueryBuilder $queryBuilder) + protected function getSimpleTotalCount(QueryBuilder $queryBuilder): int { /** The paginator count queries can be rather slow, so when query for total count (100ms or longer), * just return the entity count. diff --git a/src/DataTables/Adapter/ORMAdapter.php b/src/DataTables/Adapter/ORMAdapter.php index 467398ef..141c202e 100644 --- a/src/DataTables/Adapter/ORMAdapter.php +++ b/src/DataTables/Adapter/ORMAdapter.php @@ -191,8 +191,8 @@ class ORMAdapter extends AbstractAdapter ; } - $query = $builder->getQuery(); - $event = new ORMAdapterQueryEvent($query); + $q = $builder->getQuery(); + $event = new ORMAdapterQueryEvent($q); $state->getDataTable()->getEventDispatcher()->dispatch($event, ORMAdapterEvents::PRE_QUERY); foreach ($query->iterate([], $this->hydrationMode) as $result) { @@ -301,7 +301,7 @@ class ORMAdapter extends AbstractAdapter ->setDefaults([ 'hydrate' => Query::HYDRATE_OBJECT, 'query' => [], - 'criteria' => function (Options $options) { + 'criteria' => static function (Options $options) { return [new SearchCriteriaProvider()]; }, ]) @@ -324,7 +324,9 @@ class ORMAdapter extends AbstractAdapter { if ($provider instanceof QueryBuilderProcessorInterface) { return $provider; - } elseif (is_callable($provider)) { + } + + if (is_callable($provider)) { return new class($provider) implements QueryBuilderProcessorInterface { private $callable; diff --git a/src/DataTables/Column/EntityColumn.php b/src/DataTables/Column/EntityColumn.php index 583f6ebd..37ba7ea1 100644 --- a/src/DataTables/Column/EntityColumn.php +++ b/src/DataTables/Column/EntityColumn.php @@ -79,7 +79,7 @@ class EntityColumn extends AbstractColumn $resolver->setRequired('property'); - $resolver->setDefault('field', function (Options $option) { + $resolver->setDefault('field', static function (Options $option) { return $option['property'].'.name'; }); diff --git a/src/DataTables/Column/IconLinkColumn.php b/src/DataTables/Column/IconLinkColumn.php index 7239f6a0..f97196f4 100644 --- a/src/DataTables/Column/IconLinkColumn.php +++ b/src/DataTables/Column/IconLinkColumn.php @@ -78,7 +78,7 @@ class IconLinkColumn extends AbstractColumn return $provider; } if (is_callable($provider)) { - return call_user_func($provider, $value, $context); + return $provider($value, $context); } return false; @@ -91,7 +91,7 @@ class IconLinkColumn extends AbstractColumn return $provider; } if (is_callable($provider)) { - return call_user_func($provider, $value, $context); + return $provider($value, $context); } return null; @@ -104,7 +104,7 @@ class IconLinkColumn extends AbstractColumn return $provider; } if (is_callable($provider)) { - return call_user_func($provider, $value, $context); + return $provider($value, $context); } return null; @@ -117,7 +117,7 @@ class IconLinkColumn extends AbstractColumn return $provider; } if (is_callable($provider)) { - return call_user_func($provider, $value, $context); + return $provider($value, $context); } return null; diff --git a/src/DataTables/LogDataTable.php b/src/DataTables/LogDataTable.php index bf8268d1..3b91c5f2 100644 --- a/src/DataTables/LogDataTable.php +++ b/src/DataTables/LogDataTable.php @@ -102,7 +102,7 @@ class LogDataTable implements DataTableTypeInterface $optionsResolver->setAllowedTypes('filter_elements', ['array', 'object']); $optionsResolver->setAllowedTypes('mode', 'string'); - $optionsResolver->setNormalizer('filter_elements', function (Options $options, $value) { + $optionsResolver->setNormalizer('filter_elements', static function (Options $options, $value) { if (!is_array($value)) { return [$value]; } @@ -121,7 +121,7 @@ class LogDataTable implements DataTableTypeInterface $dataTable->add('symbol', TextColumn::class, [ 'label' => '', - 'render' => function ($value, AbstractLogEntry $context) { + 'render' => static function ($value, AbstractLogEntry $context) { switch ($context->getLevelString()) { case LogLevel::DEBUG: $symbol = 'fa-bug'; @@ -191,7 +191,7 @@ class LogDataTable implements DataTableTypeInterface 'label' => $this->translator->trans('log.level'), 'visible' => 'system_log' === $options['mode'], 'propertyPath' => 'levelString', - 'render' => function (string $value, AbstractLogEntry $context) { + 'render' => static function (string $value, AbstractLogEntry $context) { return $value; }, ]); diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index d070ea60..0290b29e 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -118,7 +118,7 @@ final class PartsDataTable implements DataTableTypeInterface $optionsResolver->setAllowedTypes('search', ['null', 'string']); //Configure search options - $optionsResolver->setDefault('search_options', function (OptionsResolver $resolver): void { + $optionsResolver->setDefault('search_options', static function (OptionsResolver $resolver): void { $resolver->setDefaults([ 'name' => true, 'category' => true, diff --git a/src/Entity/LabelSystem/LabelProfile.php b/src/Entity/LabelSystem/LabelProfile.php index c964a3cd..e1a5f8ee 100644 --- a/src/Entity/LabelSystem/LabelProfile.php +++ b/src/Entity/LabelSystem/LabelProfile.php @@ -92,7 +92,7 @@ class LabelProfile extends AttachmentContainingDBElement return $this->comment; } - public function setComment(string $new_comment): string + public function setComment(string $new_comment): self { $this->comment = $new_comment; diff --git a/src/Entity/LogSystem/SecurityEventLogEntry.php b/src/Entity/LogSystem/SecurityEventLogEntry.php index 991bd9d2..a44fe80d 100644 --- a/src/Entity/LogSystem/SecurityEventLogEntry.php +++ b/src/Entity/LogSystem/SecurityEventLogEntry.php @@ -93,11 +93,7 @@ class SecurityEventLogEntry extends AbstractLogEntry public function getEventType(): string { $key = $this->extra['e']; - if (isset(static::SECURITY_TYPE_MAPPING[$key])) { - return static::SECURITY_TYPE_MAPPING[$key]; - } - - return 'unkown'; + return static::SECURITY_TYPE_MAPPING[$key] ?? 'unkown'; } /** diff --git a/src/Entity/Parameters/ParametersTrait.php b/src/Entity/Parameters/ParametersTrait.php index e3c7b95e..7b75f168 100644 --- a/src/Entity/Parameters/ParametersTrait.php +++ b/src/Entity/Parameters/ParametersTrait.php @@ -41,7 +41,7 @@ trait ParametersTrait * * @psalm-return Collection */ - public function getParameters(): \Doctrine\Common\Collections\Collection + public function getParameters(): Collection { return $this->parameters; } diff --git a/src/EventSubscriber/LogSystem/EventLoggerSubscriber.php b/src/EventSubscriber/LogSystem/EventLoggerSubscriber.php index 8f58f231..5f0e3bce 100644 --- a/src/EventSubscriber/LogSystem/EventLoggerSubscriber.php +++ b/src/EventSubscriber/LogSystem/EventLoggerSubscriber.php @@ -331,7 +331,8 @@ class EventLoggerSubscriber implements EventSubscriber $old_data = $this->filterFieldRestrictions($entity, $old_data); //Restrict length of string fields, to save memory... - $old_data = array_map(function ($value) { + $old_data = array_map( + static function ($value) { if (is_string($value)) { return mb_strimwidth($value, 0, self::MAX_STRING_LENGTH, '...'); } @@ -350,10 +351,6 @@ class EventLoggerSubscriber implements EventSubscriber protected function validEntity(object $entity): bool { //Dont log logentries itself! - if ($entity instanceof AbstractDBElement && !$entity instanceof AbstractLogEntry) { - return true; - } - - return false; + return $entity instanceof AbstractDBElement && !$entity instanceof AbstractLogEntry; } } diff --git a/src/EventSubscriber/LogSystem/SecurityEventLoggerSubscriber.php b/src/EventSubscriber/LogSystem/SecurityEventLoggerSubscriber.php index aca7bd83..e6cd54f2 100644 --- a/src/EventSubscriber/LogSystem/SecurityEventLoggerSubscriber.php +++ b/src/EventSubscriber/LogSystem/SecurityEventLoggerSubscriber.php @@ -46,7 +46,7 @@ final class SecurityEventLoggerSubscriber implements EventSubscriberInterface $this->eventLogger = $eventLogger; } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ SecurityEvents::U2F_ADDED => 'u2f_added', diff --git a/src/EventSubscriber/SetMailFromSubscriber.php b/src/EventSubscriber/SetMailFromSubscriber.php index 59d2e654..942694d3 100644 --- a/src/EventSubscriber/SetMailFromSubscriber.php +++ b/src/EventSubscriber/SetMailFromSubscriber.php @@ -71,7 +71,7 @@ final class SetMailFromSubscriber implements EventSubscriberInterface } } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ // should be the last one to allow header changes by other listeners first diff --git a/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php b/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php index b7157182..f66976b3 100644 --- a/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php +++ b/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php @@ -75,7 +75,7 @@ final class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface * * @return array The event names to listen to */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return ['kernel.response' => 'onKernelResponse']; } diff --git a/src/EventSubscriber/UserSystem/LoginSuccessSubscriber.php b/src/EventSubscriber/UserSystem/LoginSuccessSubscriber.php index e93b4712..89860613 100644 --- a/src/EventSubscriber/UserSystem/LoginSuccessSubscriber.php +++ b/src/EventSubscriber/UserSystem/LoginSuccessSubscriber.php @@ -102,7 +102,7 @@ final class LoginSuccessSubscriber implements EventSubscriberInterface * * @return array The event names to listen to */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [SecurityEvents::INTERACTIVE_LOGIN => 'onLogin']; } diff --git a/src/EventSubscriber/UserSystem/LogoutDisabledUserSubscriber.php b/src/EventSubscriber/UserSystem/LogoutDisabledUserSubscriber.php index adcd7573..a37946f6 100644 --- a/src/EventSubscriber/UserSystem/LogoutDisabledUserSubscriber.php +++ b/src/EventSubscriber/UserSystem/LogoutDisabledUserSubscriber.php @@ -94,7 +94,7 @@ final class LogoutDisabledUserSubscriber implements EventSubscriberInterface * * @return array The event names to listen to */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [KernelEvents::REQUEST => 'onRequest']; } diff --git a/src/EventSubscriber/UserSystem/PasswordChangeNeededSubscriber.php b/src/EventSubscriber/UserSystem/PasswordChangeNeededSubscriber.php index 90725478..1df033c8 100644 --- a/src/EventSubscriber/UserSystem/PasswordChangeNeededSubscriber.php +++ b/src/EventSubscriber/UserSystem/PasswordChangeNeededSubscriber.php @@ -147,14 +147,10 @@ final class PasswordChangeNeededSubscriber implements EventSubscriberInterface { $tfa_enabled = $user->isU2FAuthEnabled() || $user->isGoogleAuthenticatorEnabled(); - if (null !== $user->getGroup() && $user->getGroup()->isEnforce2FA() && !$tfa_enabled) { - return true; - } - - return false; + return null !== $user->getGroup() && $user->getGroup()->isEnforce2FA() && !$tfa_enabled; } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ KernelEvents::REQUEST => 'redirectToSettingsIfNeeded', diff --git a/src/EventSubscriber/UserSystem/SetUserTimezoneSubscriber.php b/src/EventSubscriber/UserSystem/SetUserTimezoneSubscriber.php index 7f0d5fb8..f82fce11 100644 --- a/src/EventSubscriber/UserSystem/SetUserTimezoneSubscriber.php +++ b/src/EventSubscriber/UserSystem/SetUserTimezoneSubscriber.php @@ -101,7 +101,7 @@ final class SetUserTimezoneSubscriber implements EventSubscriberInterface * * @return array The event names to listen to */ - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { //Set the timezone shortly before executing the controller return [ diff --git a/src/Events/SecurityEvent.php b/src/Events/SecurityEvent.php index efdb9029..a71e35c9 100644 --- a/src/Events/SecurityEvent.php +++ b/src/Events/SecurityEvent.php @@ -45,7 +45,7 @@ class SecurityEvent extends Event * * @return User */ - public function getTargetUser() + public function getTargetUser(): User { return $this->targetUser; } diff --git a/src/Form/AdminPages/AttachmentTypeAdminForm.php b/src/Form/AdminPages/AttachmentTypeAdminForm.php index e43db04d..a8967e29 100644 --- a/src/Form/AdminPages/AttachmentTypeAdminForm.php +++ b/src/Form/AdminPages/AttachmentTypeAdminForm.php @@ -76,7 +76,7 @@ class AttachmentTypeAdminForm extends BaseEntityAdminForm //Normalize data before writing it to database $builder->get('filetype_filter')->addViewTransformer(new CallbackTransformer( - function ($value) { + static function ($value) { return $value; }, function ($value) { diff --git a/src/Form/AttachmentFormType.php b/src/Form/AttachmentFormType.php index 2662120a..10366f02 100644 --- a/src/Form/AttachmentFormType.php +++ b/src/Form/AttachmentFormType.php @@ -176,19 +176,18 @@ class AttachmentFormType extends AbstractType $file_form = $form->get('file'); $file = $file_form->getData(); - if ($attachment instanceof Attachment && $file instanceof UploadedFile && $attachment->getAttachmentType()) { - if (!$this->submitHandler->isValidFileExtension($attachment->getAttachmentType(), $file)) { + if ($attachment instanceof Attachment && $file instanceof UploadedFile && $attachment->getAttachmentType( + ) && !$this->submitHandler->isValidFileExtension($attachment->getAttachmentType(), $file)) { $event->getForm()->get('file')->addError( new FormError($this->translator->trans('validator.file_ext_not_allowed')) ); } - } }); //Check the secure file checkbox, if file is in securefile location $builder->get('secureFile')->addEventListener( FormEvents::PRE_SET_DATA, - function (FormEvent $event): void { + static function (FormEvent $event): void { $attachment = $event->getForm()->getParent()->getData(); if ($attachment instanceof Attachment) { $event->setData($attachment->isSecure()); diff --git a/src/Form/CollectionTypeExtension.php b/src/Form/CollectionTypeExtension.php index fb47a012..ce121fe5 100644 --- a/src/Form/CollectionTypeExtension.php +++ b/src/Form/CollectionTypeExtension.php @@ -32,7 +32,6 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormConfigBuilder; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; -use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; diff --git a/src/Form/LabelOptionsType.php b/src/Form/LabelOptionsType.php index 0b2f0fc3..7425c940 100644 --- a/src/Form/LabelOptionsType.php +++ b/src/Form/LabelOptionsType.php @@ -83,7 +83,7 @@ class LabelOptionsType extends AbstractType 'label_options.barcode_type.code93' => 'code93', 'label_options.barcode_type.datamatrix' => 'datamatrix', ], - 'group_by' => function ($choice, $key, $value) { + 'group_by' => static function ($choice, $key, $value) { if (in_array($choice, ['qr', 'datamatrix'], true)) { return 'label_options.barcode_type.2D'; } diff --git a/src/Form/Part/PartBaseType.php b/src/Form/Part/PartBaseType.php index 655887a4..0ddafb74 100644 --- a/src/Form/Part/PartBaseType.php +++ b/src/Form/Part/PartBaseType.php @@ -42,7 +42,6 @@ declare(strict_types=1); namespace App\Form\Part; -use App\Entity\Attachments\Attachment; use App\Entity\Attachments\PartAttachment; use App\Entity\Parameters\PartParameter; use App\Entity\Parts\Category; diff --git a/src/Form/Permissions/PermissionGroupType.php b/src/Form/Permissions/PermissionGroupType.php index f952ddee..0a0e5d9f 100644 --- a/src/Form/Permissions/PermissionGroupType.php +++ b/src/Form/Permissions/PermissionGroupType.php @@ -69,11 +69,8 @@ class PermissionGroupType extends AbstractType if ($permission['group'] !== $options['group_name']) { continue; } - } else { - //Skip perrmissions without groups unless we have this as blanko group - if ('*' !== $options['group_name']) { - continue; - } + } elseif ('*' !== $options['group_name']) { + continue; } $builder->add($key, PermissionType::class, [ @@ -91,7 +88,7 @@ class PermissionGroupType extends AbstractType { parent::configureOptions($resolver); - $resolver->setDefault('group_name', function (Options $options) { + $resolver->setDefault('group_name', static function (Options $options) { return trim($options['name']); }); diff --git a/src/Form/Permissions/PermissionType.php b/src/Form/Permissions/PermissionType.php index 4a7af654..9914235a 100644 --- a/src/Form/Permissions/PermissionType.php +++ b/src/Form/Permissions/PermissionType.php @@ -66,7 +66,7 @@ class PermissionType extends AbstractType { parent::configureOptions($resolver); - $resolver->setDefault('perm_name', function (Options $options) { + $resolver->setDefault('perm_name', static function (Options $options) { return $options['name']; }); @@ -78,7 +78,7 @@ class PermissionType extends AbstractType return $options['name']; }); - $resolver->setDefault('multi_checkbox', function (Options $options) { + $resolver->setDefault('multi_checkbox', static function (Options $options) { return !$options['disabled']; }); diff --git a/src/Form/Permissions/PermissionsMapper.php b/src/Form/Permissions/PermissionsMapper.php index 657c68ea..f4803594 100644 --- a/src/Form/Permissions/PermissionsMapper.php +++ b/src/Form/Permissions/PermissionsMapper.php @@ -72,7 +72,7 @@ final class PermissionsMapper implements DataMapperInterface * @param mixed $viewData View data of the compound form being initialized * @param FormInterface[]|Traversable $forms A list of {@link FormInterface} instances */ - public function mapDataToForms($viewData, $forms): void + public function mapDataToForms($viewData, $forms) { foreach ($forms as $form) { if ($this->inherit) { @@ -119,7 +119,7 @@ final class PermissionsMapper implements DataMapperInterface * @param mixed $viewData The compound form's view data that get mapped * its children model data */ - public function mapFormsToData($forms, &$viewData): void + public function mapFormsToData($forms, &$viewData) :void { if ($this->inherit) { throw new RuntimeException('The permission type is readonly when it is showing read only data!'); diff --git a/src/Form/Permissions/PermissionsType.php b/src/Form/Permissions/PermissionsType.php index 6766ed03..59c25d88 100644 --- a/src/Form/Permissions/PermissionsType.php +++ b/src/Form/Permissions/PermissionsType.php @@ -66,7 +66,7 @@ class PermissionsType extends AbstractType { $resolver->setDefaults([ 'show_legend' => true, - 'constraints' => function (Options $options) { + 'constraints' => static function (Options $options) { if (!$options['disabled']) { return [new NoLockout()]; } diff --git a/src/Form/TFAGoogleSettingsType.php b/src/Form/TFAGoogleSettingsType.php index c2f35ecd..be0d99ed 100644 --- a/src/Form/TFAGoogleSettingsType.php +++ b/src/Form/TFAGoogleSettingsType.php @@ -46,7 +46,6 @@ use App\Entity\UserSystem\User; use App\Validator\Constraints\ValidGoogleAuthCode; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; -use Symfony\Component\Form\Extension\Core\Type\ResetType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; @@ -64,7 +63,7 @@ class TFAGoogleSettingsType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { + $builder->addEventListener(FormEvents::PRE_SET_DATA, static function (FormEvent $event): void { $form = $event->getForm(); /** @var User $user */ $user = $event->getData(); diff --git a/src/Form/Type/MasterPictureAttachmentType.php b/src/Form/Type/MasterPictureAttachmentType.php index 8bd8225d..c36e827b 100644 --- a/src/Form/Type/MasterPictureAttachmentType.php +++ b/src/Form/Type/MasterPictureAttachmentType.php @@ -65,8 +65,8 @@ class MasterPictureAttachmentType extends AbstractType 'class' => 'selectpicker', 'title' => 'selectpicker.nothing_selected', ], - 'choice_attr' => function (Options $options) { - return function ($choice, $key, $value) use ($options) { + 'choice_attr' => static function (Options $options) { + return static function ($choice, $key, $value) use ($options) { /** @var Attachment $choice */ $tmp = ['data-subtext' => $choice->getFilename() ?? 'URL']; @@ -80,8 +80,9 @@ class MasterPictureAttachmentType extends AbstractType }; }, 'choice_label' => 'name', - 'choice_loader' => function (Options $options) { - return new CallbackChoiceLoader(function () use ($options) { + 'choice_loader' => static function (Options $options) { + return new CallbackChoiceLoader( + static function () use ($options) { $entity = $options['entity']; if (!$entity instanceof AttachmentContainingDBElement) { throw new \RuntimeException('$entity must have Attachments! (be of type AttachmentContainingDBElement)'); diff --git a/src/Form/Type/SIUnitType.php b/src/Form/Type/SIUnitType.php index 1e14cf09..d0ae852c 100644 --- a/src/Form/Type/SIUnitType.php +++ b/src/Form/Type/SIUnitType.php @@ -69,7 +69,7 @@ final class SIUnitType extends AbstractType implements DataMapperInterface { $resolver->setDefaults([ 'measurement_unit' => null, - 'show_prefix' => function (Options $options) { + 'show_prefix' => static function (Options $options) { if (null !== $options['measurement_unit']) { /** @var MeasurementUnit $unit */ $unit = $options['measurement_unit']; @@ -79,7 +79,7 @@ final class SIUnitType extends AbstractType implements DataMapperInterface return false; }, - 'is_integer' => function (Options $options) { + 'is_integer' => static function (Options $options) { if (null !== $options['measurement_unit']) { /** @var MeasurementUnit $unit */ $unit = $options['measurement_unit']; @@ -89,7 +89,7 @@ final class SIUnitType extends AbstractType implements DataMapperInterface return false; }, - 'unit' => function (Options $options) { + 'unit' => static function (Options $options) { if (null !== $options['measurement_unit']) { /** @var MeasurementUnit $unit */ $unit = $options['measurement_unit']; @@ -111,7 +111,7 @@ final class SIUnitType extends AbstractType implements DataMapperInterface $resolver->setDefaults([ 'min' => 0, 'max' => '', - 'step' => function (Options $options) { + 'step' => static function (Options $options) { if (true === $options['is_integer']) { return 1; } @@ -185,7 +185,7 @@ final class SIUnitType extends AbstractType implements DataMapperInterface $forms['prefix']->setData(0); } - return null; + return; } $data = $this->si_formatter->convertValue((float) $viewData); diff --git a/src/Form/Type/StructuralEntityType.php b/src/Form/Type/StructuralEntityType.php index e9e641c1..d70f7e78 100644 --- a/src/Form/Type/StructuralEntityType.php +++ b/src/Form/Type/StructuralEntityType.php @@ -44,13 +44,11 @@ namespace App\Form\Type; use App\Entity\Attachments\AttachmentType; use App\Entity\Base\AbstractStructuralDBElement; -use App\Repository\StructuralDBElementRepository; use App\Services\Trees\NodesListBuilder; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader; -use Symfony\Component\Form\Exception; use Symfony\Component\Form\Exception\TransformationFailedException; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -58,7 +56,6 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\Validator\Constraints\Choice; /** * This class provides a choice form type similar to EntityType, with the difference, that the tree structure @@ -117,7 +114,7 @@ class StructuralEntityType extends AbstractType $resolver->setDefault('empty_message', null); - $resolver->setDefault('attr', function (Options $options) { + $resolver->setDefault('attr', static function (Options $options) { $tmp = [ 'class' => 'selectpicker', 'data-live-search' => true, diff --git a/src/Form/UserAdminForm.php b/src/Form/UserAdminForm.php index 497fb767..313760ef 100644 --- a/src/Form/UserAdminForm.php +++ b/src/Form/UserAdminForm.php @@ -49,7 +49,6 @@ use App\Entity\UserSystem\User; use App\Form\Permissions\PermissionsType; use App\Form\Type\CurrencyEntityType; use App\Form\Type\StructuralEntityType; -use FOS\CKEditorBundle\Form\Type\CKEditorType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -174,7 +173,7 @@ class UserAdminForm extends AbstractType ->add('theme', ChoiceType::class, [ 'required' => false, 'choices' => User::AVAILABLE_THEMES, - 'choice_label' => function ($entity, $key, $value) { + 'choice_label' => static function ($entity, $key, $value) { return $value; }, 'attr' => [ diff --git a/src/Form/UserSettingsType.php b/src/Form/UserSettingsType.php index 66048650..7cdb1764 100644 --- a/src/Form/UserSettingsType.php +++ b/src/Form/UserSettingsType.php @@ -124,7 +124,7 @@ class UserSettingsType extends AbstractType ], 'choice_translation_domain' => false, 'choices' => User::AVAILABLE_THEMES, - 'choice_label' => function ($entity, $key, $value) { + 'choice_label' => static function ($entity, $key, $value) { return $value; }, 'placeholder' => 'user_settings.theme.placeholder', diff --git a/src/Helpers/LabelResponse.php b/src/Helpers/LabelResponse.php index af07d25d..8561852c 100644 --- a/src/Helpers/LabelResponse.php +++ b/src/Helpers/LabelResponse.php @@ -23,7 +23,6 @@ declare(strict_types=1); namespace App\Helpers; -use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -62,7 +61,7 @@ class LabelResponse extends Response /** * Automatically sets the Last-Modified header according the file modification date. */ - public function setAutoLastModified() + public function setAutoLastModified(): LabelResponse { $this->setLastModified(new \DateTime()); @@ -72,7 +71,7 @@ class LabelResponse extends Response /** * Automatically sets the ETag header according to the checksum of the file. */ - public function setAutoEtag() + public function setAutoEtag(): LabelResponse { $this->setEtag(base64_encode(hash('sha256', $this->content, true))); @@ -88,7 +87,7 @@ class LabelResponse extends Response * * @return $this */ - public function setContentDisposition($disposition, $filename, $filenameFallback = '') + public function setContentDisposition($disposition, $filename, $filenameFallback = ''): self { if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || false !== strpos($filename, '%'))) { $encoding = mb_detect_encoding($filename, null, true) ?: '8bit'; diff --git a/src/Helpers/Trees/StructuralDBElementIterator.php b/src/Helpers/Trees/StructuralDBElementIterator.php index 433af404..488aec0c 100644 --- a/src/Helpers/Trees/StructuralDBElementIterator.php +++ b/src/Helpers/Trees/StructuralDBElementIterator.php @@ -54,7 +54,7 @@ final class StructuralDBElementIterator extends ArrayIterator implements Recursi parent::__construct($nodes); } - public function hasChildren() + public function hasChildren(): bool { /** @var AbstractStructuralDBElement $element */ $element = $this->current(); diff --git a/src/Helpers/Trees/TreeViewNodeIterator.php b/src/Helpers/Trees/TreeViewNodeIterator.php index a944f6c1..e57f8943 100644 --- a/src/Helpers/Trees/TreeViewNodeIterator.php +++ b/src/Helpers/Trees/TreeViewNodeIterator.php @@ -55,7 +55,7 @@ final class TreeViewNodeIterator extends ArrayIterator implements RecursiveItera parent::__construct($nodes); } - public function hasChildren() + public function hasChildren(): bool { /** @var TreeViewNode $element */ $element = $this->current(); diff --git a/src/Security/EntityListeners/ElementPermissionListener.php b/src/Security/EntityListeners/ElementPermissionListener.php index 8b71d551..375c267c 100644 --- a/src/Security/EntityListeners/ElementPermissionListener.php +++ b/src/Security/EntityListeners/ElementPermissionListener.php @@ -52,7 +52,6 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\PreFlushEventArgs; use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\PostLoad; -use Doctrine\ORM\Mapping\PreUpdate; use function get_class; use InvalidArgumentException; use ReflectionClass; @@ -162,14 +161,14 @@ class ElementPermissionListener $property->setAccessible(true); //If the user is not allowed to edit or read this property, reset all values. + //Set value to old value, so that there a no change to this property if ((!$this->isGranted('read', $annotation, $element) - || !$this->isGranted('edit', $annotation, $element))) { - //Set value to old value, so that there a no change to this property - if (isset($old_data[$property->getName()])) { + || !$this->isGranted('edit', $annotation, $element)) && isset( + $old_data[$property->getName()] + )) { $property->setValue($element, $old_data[$property->getName()]); $changed = true; } - } if ($changed) { //Schedule for update, so the post update method will be called @@ -184,13 +183,9 @@ class ElementPermissionListener * * @return bool Returns true if the current programm is running from CLI (terminal) */ - protected function isRunningFromCLI() + protected function isRunningFromCLI(): bool { - if (empty($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['HTTP_USER_AGENT']) && count($_SERVER['argv']) > 0) { - return true; - } - - return false; + return empty($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['HTTP_USER_AGENT']) && count($_SERVER['argv']) > 0; } /** diff --git a/src/Security/Voter/ExtendedVoter.php b/src/Security/Voter/ExtendedVoter.php index b2b17838..d7545b42 100644 --- a/src/Security/Voter/ExtendedVoter.php +++ b/src/Security/Voter/ExtendedVoter.php @@ -66,7 +66,7 @@ abstract class ExtendedVoter extends Voter $this->entityManager = $entityManager; } - final protected function voteOnAttribute($attribute, $subject, TokenInterface $token) + final protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool { $user = $token->getUser(); diff --git a/src/Security/Voter/PartVoter.php b/src/Security/Voter/PartVoter.php index ed29cdba..75de92fa 100644 --- a/src/Security/Voter/PartVoter.php +++ b/src/Security/Voter/PartVoter.php @@ -44,7 +44,6 @@ namespace App\Security\Voter; use App\Entity\Parts\Part; use App\Entity\UserSystem\User; -use Symfony\Component\Security\Core\Authorization\Voter\Voter; /** * A Voter that votes on Part entities. diff --git a/src/Security/Voter/UserVoter.php b/src/Security/Voter/UserVoter.php index 371a12ad..ecdd186d 100644 --- a/src/Security/Voter/UserVoter.php +++ b/src/Security/Voter/UserVoter.php @@ -76,16 +76,14 @@ class UserVoter extends ExtendedVoter */ protected function voteOnUser($attribute, $subject, User $user): bool { - if ($subject instanceof User) { - //Check if the checked user is the user itself - if ($subject->getID() === $user->getID() && - $this->resolver->isValidOperation('self', $attribute)) { - //Then we also need to check the self permission - $tmp = $this->resolver->inherit($user, 'self', $attribute) ?? false; - //But if the self value is not allowed then use just the user value: - if ($tmp) { - return $tmp; - } + //Check if the checked user is the user itself + if (($subject instanceof User) && $subject->getID() === $user->getID() && + $this->resolver->isValidOperation('self', $attribute)) { + //Then we also need to check the self permission + $tmp = $this->resolver->inherit($user, 'self', $attribute) ?? false; + //But if the self value is not allowed then use just the user value: + if ($tmp) { + return $tmp; } } diff --git a/src/Services/AmountFormatter.php b/src/Services/AmountFormatter.php index 5754ae7b..371389b3 100644 --- a/src/Services/AmountFormatter.php +++ b/src/Services/AmountFormatter.php @@ -70,7 +70,7 @@ class AmountFormatter * * @throws InvalidArgumentException thrown if $value is not numeric */ - public function format($value, ?MeasurementUnit $unit = null, array $options = []) + public function format($value, ?MeasurementUnit $unit = null, array $options = []): string { if (!is_numeric($value)) { throw new InvalidArgumentException('$value must be an numeric value!'); @@ -106,7 +106,7 @@ class AmountFormatter protected function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'show_prefix' => function (Options $options) { + 'show_prefix' => static function (Options $options) { if (null !== $options['measurement_unit']) { /** @var MeasurementUnit $unit */ $unit = $options['measurement_unit']; @@ -116,7 +116,7 @@ class AmountFormatter return false; }, - 'is_integer' => function (Options $options) { + 'is_integer' => static function (Options $options) { if (null !== $options['measurement_unit']) { /** @var MeasurementUnit $unit */ $unit = $options['measurement_unit']; @@ -126,7 +126,7 @@ class AmountFormatter return true; }, - 'unit' => function (Options $options) { + 'unit' => static function (Options $options) { if (null !== $options['measurement_unit']) { /** @var MeasurementUnit $unit */ $unit = $options['measurement_unit']; @@ -144,7 +144,7 @@ class AmountFormatter $resolver->setAllowedTypes('decimals', 'int'); - $resolver->setNormalizer('decimals', function (Options $options, $value) { + $resolver->setNormalizer('decimals', static function (Options $options, $value) { // If the unit is integer based, then dont show any decimals if ($options['is_integer']) { return 0; diff --git a/src/Services/Attachments/AttachmentReverseSearch.php b/src/Services/Attachments/AttachmentReverseSearch.php index 25e1dfb1..50d23912 100644 --- a/src/Services/Attachments/AttachmentReverseSearch.php +++ b/src/Services/Attachments/AttachmentReverseSearch.php @@ -48,7 +48,6 @@ use Doctrine\ORM\EntityManagerInterface; use Liip\ImagineBundle\Imagine\Cache\CacheManager; use SplFileInfo; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpFoundation\File\File; /** * This service provides functions to find attachments via an reverse search based on a file. diff --git a/src/Services/Attachments/FileTypeFilterTools.php b/src/Services/Attachments/FileTypeFilterTools.php index 61f24b38..49a2157e 100644 --- a/src/Services/Attachments/FileTypeFilterTools.php +++ b/src/Services/Attachments/FileTypeFilterTools.php @@ -92,7 +92,7 @@ class FileTypeFilterTools foreach ($elements as $element) { $element = trim($element); if (!preg_match('#^\.\w+$#', $element) // .ext is allowed - && !preg_match('#^[-\w.]+\/[-\w.]+#', $element) //Explicit MIME type is allowed + && !preg_match('#^[-\w.]+/[-\w.]+#', $element) //Explicit MIME type is allowed && !in_array($element, static::ALLOWED_MIME_PLACEHOLDERS, false)) { //image/* is allowed return false; } @@ -139,7 +139,7 @@ class FileTypeFilterTools $element = 'video/*'; } elseif ('audio' === $element || 'audio/' === $element) { $element = 'audio/*'; - } elseif (!preg_match('#^[-\w.]+\/[-\w.*]+#', $element) && 0 !== strpos($element, '.')) { + } elseif (!preg_match('#^[-\w.]+/[-\w.*]+#', $element) && 0 !== strpos($element, '.')) { //Convert jpg to .jpg $element = '.'.$element; } @@ -176,7 +176,7 @@ class FileTypeFilterTools $extensions = array_merge($extensions, static::AUDIO_EXTS); } elseif ('video/*' === $element) { $extensions = array_merge($extensions, static::VIDEO_EXTS); - } elseif (preg_match('#^[-\w.]+\/[-\w.*]+#', $element)) { + } elseif (preg_match('#^[-\w.]+/[-\w.*]+#', $element)) { $extensions = array_merge($extensions, $this->mimeTypes->getExtensions($element)); } } diff --git a/src/Services/CustomEnvVarProcessor.php b/src/Services/CustomEnvVarProcessor.php index 5f369943..1fbc9ebb 100644 --- a/src/Services/CustomEnvVarProcessor.php +++ b/src/Services/CustomEnvVarProcessor.php @@ -59,9 +59,10 @@ final class CustomEnvVarProcessor implements EnvVarProcessorInterface return false; } } + return false; } - public static function getProvidedTypes() + public static function getProvidedTypes(): array { return [ 'validMailDSN' => 'bool', diff --git a/src/Services/EntityExporter.php b/src/Services/EntityExporter.php index 707bf8c0..168d7794 100644 --- a/src/Services/EntityExporter.php +++ b/src/Services/EntityExporter.php @@ -51,13 +51,6 @@ use ReflectionException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; -use Symfony\Component\Serializer\Encoder\CsvEncoder; -use Symfony\Component\Serializer\Encoder\JsonEncoder; -use Symfony\Component\Serializer\Encoder\XmlEncoder; -use Symfony\Component\Serializer\Encoder\YamlEncoder; -use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; -use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; -use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerInterface; /** @@ -166,7 +159,7 @@ class EntityExporter $disposition = $response->headers->makeDisposition( ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, - $string = preg_replace('![^'.preg_quote('-').'a-z0-_9\s]+!', '', strtolower($filename)) + $string = preg_replace('![^'.preg_quote('-','!').'a-z0-_9\s]+!', '', strtolower($filename)) ); // Set the content disposition $response->headers->set('Content-Disposition', $disposition); diff --git a/src/Services/EntityImporter.php b/src/Services/EntityImporter.php index bac74f0e..711d3983 100644 --- a/src/Services/EntityImporter.php +++ b/src/Services/EntityImporter.php @@ -151,7 +151,7 @@ class EntityImporter $tmp = $this->validator->validate($entity); //When no validation error occured, persist entity to database (cascade must be set in entity) - if (empty($tmp)) { + if ($tmp === null) { $this->em->persist($entity); } else { //Log validation errors to global log. $errors[$entity->getFullPath()] = $tmp; diff --git a/src/Services/GitVersionInfo.php b/src/Services/GitVersionInfo.php index f9b1da38..f80eff86 100644 --- a/src/Services/GitVersionInfo.php +++ b/src/Services/GitVersionInfo.php @@ -58,7 +58,7 @@ class GitVersionInfo * * @return string|null The current git branch name. Null, if this is no Git installation */ - public function getGitBranchName() + public function getGitBranchName(): ?string { if (is_file($this->project_dir.'/.git/HEAD')) { $git = file($this->project_dir.'/.git/HEAD'); @@ -83,7 +83,7 @@ class GitVersionInfo * * @return string|null The hash of the last commit, null If this is no Git installation */ - public function getGitCommitHash(int $length = 7) + public function getGitCommitHash(int $length = 7): ?string { $filename = $this->project_dir.'/.git/refs/remotes/origin/'.$this->getGitBranchName(); if (is_file($filename)) { diff --git a/src/Services/LabelSystem/LabelGenerator.php b/src/Services/LabelSystem/LabelGenerator.php index f547bb8f..aa15dcec 100644 --- a/src/Services/LabelSystem/LabelGenerator.php +++ b/src/Services/LabelSystem/LabelGenerator.php @@ -78,7 +78,7 @@ final class LabelGenerator * * @return bool */ - public function supports(LabelOptions $options, object $element) + public function supports(LabelOptions $options, object $element): bool { $supported_type = $options->getSupportedElement(); if (!isset(static::CLASS_SUPPORT_MAPPING[$supported_type])) { diff --git a/src/Services/LabelSystem/LabelHTMLGenerator.php b/src/Services/LabelSystem/LabelHTMLGenerator.php index 5076971b..e41f8301 100644 --- a/src/Services/LabelSystem/LabelHTMLGenerator.php +++ b/src/Services/LabelSystem/LabelHTMLGenerator.php @@ -68,7 +68,7 @@ final class LabelHTMLGenerator $page = 1; foreach ($elements as $element) { - if ('twig' === $options->getLinesMode() && isset($sandboxed_twig) && isset($current_user)) { + if (isset($sandboxed_twig, $current_user) && 'twig' === $options->getLinesMode()) { try { $lines = $sandboxed_twig->render( 'lines', @@ -103,7 +103,7 @@ final class LabelHTMLGenerator ]); } - private function getPDFTitle(LabelOptions $options, object $element) + private function getPDFTitle(LabelOptions $options, object $element): string { if ($element instanceof NamedElementInterface) { return $this->elementTypeNameGenerator->getTypeNameCombination($element, false); diff --git a/src/Services/LabelSystem/PlaceholderProviders/PartLotProvider.php b/src/Services/LabelSystem/PlaceholderProviders/PartLotProvider.php index 6b67e287..d9137547 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/PartLotProvider.php +++ b/src/Services/LabelSystem/PlaceholderProviders/PartLotProvider.php @@ -44,7 +44,7 @@ final class PartLotProvider implements PlaceholderProviderInterface { if ($label_target instanceof PartLot) { if ('[[LOT_ID]]' === $placeholder) { - return $label_target->getID() ?? 'unknown'; + return (string) ($label_target->getID() ?? 'unknown'); } if ('[[LOT_NAME]]' === $placeholder) { diff --git a/src/Services/LogSystem/LogEntryExtraFormatter.php b/src/Services/LogSystem/LogEntryExtraFormatter.php index 39428681..08607968 100644 --- a/src/Services/LogSystem/LogEntryExtraFormatter.php +++ b/src/Services/LogSystem/LogEntryExtraFormatter.php @@ -147,13 +147,11 @@ class LogEntryExtraFormatter ); } - if ($context instanceof LogWithEventUndoInterface) { - if ($context->isUndoEvent()) { - if ('undo' === $context->getUndoMode()) { - $array['log.undo_mode.undo'] = (string) $context->getUndoEventID(); - } elseif ('revert' === $context->getUndoMode()) { - $array['log.undo_mode.revert'] = (string) $context->getUndoEventID(); - } + if (($context instanceof LogWithEventUndoInterface) && $context->isUndoEvent()) { + if ('undo' === $context->getUndoMode()) { + $array['log.undo_mode.undo'] = (string) $context->getUndoEventID(); + } elseif ('revert' === $context->getUndoMode()) { + $array['log.undo_mode.revert'] = (string) $context->getUndoEventID(); } } @@ -192,7 +190,7 @@ class LogEntryExtraFormatter $array['log.collection_deleted.deleted'] = sprintf( '%s: %s (%s)', $this->elementTypeNameGenerator->getLocalizedTypeLabel($context->getDeletedElementClass()), - $context->getOldName() ?? $context->getDeletedElementID(), + $context->getOldName() ?? (string) $context->getDeletedElementID(), $context->getCollectionName() ); } diff --git a/src/Services/LogSystem/TimeTravel.php b/src/Services/LogSystem/TimeTravel.php index 9cd63f74..b0edd54e 100644 --- a/src/Services/LogSystem/TimeTravel.php +++ b/src/Services/LogSystem/TimeTravel.php @@ -152,11 +152,12 @@ class TimeTravel foreach ($target_elements as $target_element) { if (null !== $target_element && $element->getLastModified() >= $timestamp) { //Remove the element from collection, if it did not existed at $timestamp - if (!$this->repo->getElementExistedAtTimestamp($target_element, $timestamp)) { - if ($target_elements instanceof Collection) { + if (!$this->repo->getElementExistedAtTimestamp( + $target_element, + $timestamp + ) && $target_elements instanceof Collection) { $target_elements->removeElement($target_element); } - } $this->revertEntityToTimestamp($target_element, $timestamp, $reverted_elements); } } @@ -183,11 +184,9 @@ class TimeTravel foreach ($old_data as $field => $data) { if ($metadata->hasField($field)) { - if ('big_decimal' === $metadata->getFieldMapping($field)['type']) { - //We need to convert the string to a BigDecimal first - if (!$data instanceof BigDecimal) { - $data = BigDecimal::of($data); - } + //We need to convert the string to a BigDecimal first + if (!$data instanceof BigDecimal && ('big_decimal' === $metadata->getFieldMapping($field)['type'])) { + $data = BigDecimal::of($data); } $this->setField($element, $field, $data); diff --git a/src/Services/MoneyFormatter.php b/src/Services/MoneyFormatter.php index 8f88b0f7..3b472e53 100644 --- a/src/Services/MoneyFormatter.php +++ b/src/Services/MoneyFormatter.php @@ -67,7 +67,7 @@ class MoneyFormatter * * @return string */ - public function format($value, ?Currency $currency = null, $decimals = 5, bool $show_all_digits = false) + public function format($value, ?Currency $currency = null, $decimals = 5, bool $show_all_digits = false): string { $iso_code = $this->base_currency; if (null !== $currency && !empty($currency->getIsoCode())) { diff --git a/src/Services/PricedetailHelper.php b/src/Services/PricedetailHelper.php index 81bf970d..a98273be 100644 --- a/src/Services/PricedetailHelper.php +++ b/src/Services/PricedetailHelper.php @@ -85,7 +85,7 @@ class PricedetailHelper } else { // We have to sort the pricedetails manually $array = $pricedetails->map( - function (Pricedetail $pricedetail) { + static function (Pricedetail $pricedetail) { return $pricedetail->getMinDiscountQuantity(); } )->toArray(); diff --git a/src/Services/TagFinder.php b/src/Services/TagFinder.php index fe97bb67..27743f59 100644 --- a/src/Services/TagFinder.php +++ b/src/Services/TagFinder.php @@ -66,7 +66,7 @@ class TagFinder * * @return string[] an array containing the tags that match the given keyword */ - public function searchTags(string $keyword, array $options = []) + public function searchTags(string $keyword, array $options = []): array { $results = []; $keyword_regex = '/^'.preg_quote($keyword, '/').'/'; diff --git a/src/Services/Trees/TreeViewGenerator.php b/src/Services/Trees/TreeViewGenerator.php index 3dc0a7ea..613ef7e1 100644 --- a/src/Services/Trees/TreeViewGenerator.php +++ b/src/Services/Trees/TreeViewGenerator.php @@ -124,7 +124,7 @@ class TreeViewGenerator } //Translate text if text starts with $$ - if ('$$' === substr($item->getText(), 0, 2)) { + if (strpos($item->getText(), '$$') === 0) { $item->setText($this->translator->trans(substr($item->getText(), 2))); } } diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 62ca61b9..5e6585d6 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -111,7 +111,7 @@ class AppExtension extends AbstractExtension public function getTests() { return [ - new TwigTest('instanceof', function ($var, $instance) { + new TwigTest('instanceof', static function ($var, $instance) { return $var instanceof $instance; }), ]; @@ -150,7 +150,7 @@ class AppExtension extends AbstractExtension return $this->entityURLGenerator->getURL($entity, $method); } - public function formatCurrency($amount, ?Currency $currency = null, int $decimals = 5) + public function formatCurrency($amount, ?Currency $currency = null, int $decimals = 5): string { if ($amount instanceof BigDecimal) { $amount = (string) $amount; @@ -159,12 +159,12 @@ class AppExtension extends AbstractExtension return $this->moneyFormatter->format($amount, $currency, $decimals); } - public function siFormat($value, $unit, $decimals = 2, bool $show_all_digits = false) + public function siFormat($value, $unit, $decimals = 2, bool $show_all_digits = false): string { - return $this->siformatter->format($value, $unit, $decimals, $show_all_digits); + return $this->siformatter->format($value, $unit, $decimals); } - public function amountFormat($value, ?MeasurementUnit $unit, array $options = []) + public function amountFormat($value, ?MeasurementUnit $unit, array $options = []): string { return $this->amountFormatter->format($value, $unit, $options); } diff --git a/src/Twig/BarcodeExtension.php b/src/Twig/BarcodeExtension.php index 30b60384..5a4fa88e 100644 --- a/src/Twig/BarcodeExtension.php +++ b/src/Twig/BarcodeExtension.php @@ -29,7 +29,7 @@ class BarcodeExtension extends AbstractExtension public function getFilters() { return [ - new TwigFilter('barcodeSVG', function (string $content, string $type = 'QRCODE') { + new TwigFilter('barcodeSVG', static function (string $content, string $type = 'QRCODE') { $barcodeFactory = new Barcode(); $barcode = $barcodeFactory->getBarcodeObj($type, $content); diff --git a/src/Twig/Sandbox/InheritanceSecurityPolicy.php b/src/Twig/Sandbox/InheritanceSecurityPolicy.php index cbaf5424..ff20e059 100644 --- a/src/Twig/Sandbox/InheritanceSecurityPolicy.php +++ b/src/Twig/Sandbox/InheritanceSecurityPolicy.php @@ -60,7 +60,8 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface { $this->allowedMethods = []; foreach ($methods as $class => $m) { - $this->allowedMethods[$class] = array_map(function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, \is_array($m) ? $m : [$m]); + $this->allowedMethods[$class] = array_map( + static function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, \is_array($m) ? $m : [$m]); } } diff --git a/src/Twig/TypeLabelExtension.php b/src/Twig/TypeLabelExtension.php index 3b25a60b..4c4ce5d6 100644 --- a/src/Twig/TypeLabelExtension.php +++ b/src/Twig/TypeLabelExtension.php @@ -15,7 +15,7 @@ final class TypeLabelExtension extends AbstractExtension $this->nameGenerator = $elementTypeNameGenerator; } - public function getFunctions() + public function getFunctions(): array { return [ new TwigFunction('elementType', [$this->nameGenerator, 'getLocalizedTypeLabel']), diff --git a/src/Validator/Constraints/NoLockoutValidator.php b/src/Validator/Constraints/NoLockoutValidator.php index 62539a6c..d2c025e6 100644 --- a/src/Validator/Constraints/NoLockoutValidator.php +++ b/src/Validator/Constraints/NoLockoutValidator.php @@ -88,12 +88,14 @@ class NoLockoutValidator extends ConstraintValidator $user = $this->entityManager->getRepository(User::class)->getAnonymousUser(); } - if ($user instanceof User) { - //Check if we the change_permission permission has changed from allow to disallow - if (false === ($this->resolver->inherit($user, 'users', 'edit_permissions') ?? false)) { - $this->context->addViolation($constraint->message); - } - } + //Check if we the change_permission permission has changed from allow to disallow + if (($user instanceof User) && false === ($this->resolver->inherit( + $user, + 'users', + 'edit_permissions' + ) ?? false)) { + $this->context->addViolation($constraint->message); + } } } } diff --git a/src/Validator/Constraints/NoneOfItsChildren.php b/src/Validator/Constraints/NoneOfItsChildren.php index b53f576c..7ad107c3 100644 --- a/src/Validator/Constraints/NoneOfItsChildren.php +++ b/src/Validator/Constraints/NoneOfItsChildren.php @@ -60,9 +60,4 @@ class NoneOfItsChildren extends Constraint * @var string The message used if it is tried to use one of the children for as parent */ public $children_message = 'validator.noneofitschild.children'; - - public function validatedBy() - { - return parent::validatedBy(); // TODO: Change the autogenerated stub - } } diff --git a/src/Validator/Constraints/SelectableValidator.php b/src/Validator/Constraints/SelectableValidator.php index 713c9f24..85bdf585 100644 --- a/src/Validator/Constraints/SelectableValidator.php +++ b/src/Validator/Constraints/SelectableValidator.php @@ -57,7 +57,7 @@ class SelectableValidator extends ConstraintValidator * Checks if the passed value is valid. * * @param mixed $value The value that should be validated - * @param \Symfony\Component\Validator\Constraint $constraint The constraint for the validation + * @param Constraint $constraint The constraint for the validation */ public function validate($value, Constraint $constraint): void { diff --git a/src/Validator/Constraints/ValidPartLotValidator.php b/src/Validator/Constraints/ValidPartLotValidator.php index 84a53b2d..03940c89 100644 --- a/src/Validator/Constraints/ValidPartLotValidator.php +++ b/src/Validator/Constraints/ValidPartLotValidator.php @@ -104,20 +104,18 @@ class ValidPartLotValidator extends ConstraintValidator } //Check for onlyExisting - if ($value->getStorageLocation()->isLimitToExistingParts()) { - if (!$parts->contains($value->getPart())) { - $this->context->buildViolation('validator.part_lot.only_existing') - ->atPath('storage_location')->addViolation(); - } + if ($value->getStorageLocation()->isLimitToExistingParts() && !$parts->contains($value->getPart())) { + $this->context->buildViolation('validator.part_lot.only_existing') + ->atPath('storage_location')->addViolation(); } //Check for only single part - if ($value->getStorageLocation()->isOnlySinglePart()) { - if (($parts->count() > 0) && !$parts->contains($value->getPart())) { + if ($value->getStorageLocation()->isOnlySinglePart() && ($parts->count() > 0) && !$parts->contains( + $value->getPart() + )) { $this->context->buildViolation('validator.part_lot.single_part') ->atPath('storage_location')->addViolation(); } - } } } } diff --git a/tests/Controller/RedirectControllerTest.php b/tests/Controller/RedirectControllerTest.php index cfc878aa..c90cc054 100644 --- a/tests/Controller/RedirectControllerTest.php +++ b/tests/Controller/RedirectControllerTest.php @@ -68,7 +68,7 @@ class RedirectControllerTest extends WebTestCase $this->userRepo = $this->em->getRepository(User::class); } - public function urlMatchDataProvider() + public function urlMatchDataProvider(): array { return [ ['/', true], @@ -99,7 +99,7 @@ class RedirectControllerTest extends WebTestCase $this->assertSame($expect_redirect, $response->isRedirect()); } - public function urlAddLocaleDataProvider() + public function urlAddLocaleDataProvider(): array { return [ //User locale, original target, redirect target diff --git a/tests/EventSubscriber/PasswordChangeNeededSubscriberTest.php b/tests/EventSubscriber/PasswordChangeNeededSubscriberTest.php index 916ca5c1..060e605b 100644 --- a/tests/EventSubscriber/PasswordChangeNeededSubscriberTest.php +++ b/tests/EventSubscriber/PasswordChangeNeededSubscriberTest.php @@ -57,11 +57,11 @@ class PasswordChangeNeededSubscriberTest extends TestCase //A user without a group must not redirect $user->setGroup(null); - $this->assertFalse(\App\EventSubscriber\UserSystem\PasswordChangeNeededSubscriber::TFARedirectNeeded($user)); + $this->assertFalse(PasswordChangeNeededSubscriber::TFARedirectNeeded($user)); //When the group does not enforce the redirect the user must not be redirected $user->setGroup($group); - $this->assertFalse(\App\EventSubscriber\UserSystem\PasswordChangeNeededSubscriber::TFARedirectNeeded($user)); + $this->assertFalse(PasswordChangeNeededSubscriber::TFARedirectNeeded($user)); //The user must be redirected if the group enforces 2FA and it does not have a method $group->setEnforce2FA(true);