From f2ff77a8b3b3b77f4a081cd97276ab48258b8c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 1 Feb 2020 16:17:20 +0100 Subject: [PATCH] Fixed coding style. --- ecs.yaml | 2 +- src/Command/ShowEventLogCommand.php | 50 +++++----- src/Controller/LogController.php | 10 +- .../Adapter/FetchJoinORMAdapter.php | 92 ++++++++--------- src/DataTables/Adapter/ORMAdapter.php | 73 +++++++------- src/DataTables/AttachmentDataTable.php | 12 +-- src/DataTables/Column/LogEntryExtraColumn.php | 18 +--- .../Column/LogEntryTargetColumn.php | 16 ++- src/DataTables/LogDataTable.php | 47 +++++---- src/DataTables/PartsDataTable.php | 17 ++-- src/Entity/Base/StructuralDBElement.php | 3 +- src/Entity/LogSystem/AbstractLogEntry.php | 99 +++++++++++-------- .../LogSystem/ConfigChangedLogEntry.php | 8 +- .../LogSystem/DatabaseUpdatedLogEntry.php | 12 ++- .../LogSystem/ElementCreatedLogEntry.php | 15 +-- .../LogSystem/ElementDeletedLogEntry.php | 8 +- .../LogSystem/ElementEditedLogEntry.php | 13 ++- src/Entity/LogSystem/ExceptionLogEntry.php | 16 +-- .../LogSystem/InstockChangedLogEntry.php | 32 +++--- src/Entity/LogSystem/UserLoginLogEntry.php | 19 ++-- src/Entity/LogSystem/UserLogoutLogEntry.php | 21 ++-- .../LogSystem/UserNotAllowedLogEntry.php | 7 +- src/Entity/Parts/Part.php | 2 +- src/Entity/UserSystem/User.php | 2 +- src/EventSubscriber/LoginSuccessListener.php | 8 +- src/EventSubscriber/LogoutListener.php | 11 +-- .../LogoutOnDisabledUserListener.php | 8 +- src/EventSubscriber/MailFromListener.php | 4 +- src/EventSubscriber/MigrationListener.php | 19 ++-- .../PasswordChangeNeededSubscriber.php | 6 +- .../SymfonyDebugToolbarSubscriber.php | 2 +- src/EventSubscriber/TimezoneListener.php | 4 +- .../U2FRegistrationSubscriber.php | 9 +- src/Exceptions/LogEntryObsoleteException.php | 8 +- src/Form/Permissions/PermissionsMapper.php | 4 +- src/Helpers/Trees/TreeViewNode.php | 12 +-- src/Helpers/Trees/TreeViewNodeState.php | 8 +- src/Kernel.php | 2 + src/Migrations/Version20200126191823.php | 10 +- src/Repository/LogEntryRepository.php | 37 ++++--- src/Security/Voter/LogEntryVoter.php | 21 ++-- src/Services/LogSystem/EventLogger.php | 30 +++--- .../LogSystem/LogEntryExtraFormatter.php | 21 ++-- .../PermissionExtractor.php | 4 +- 44 files changed, 435 insertions(+), 387 deletions(-) diff --git a/ecs.yaml b/ecs.yaml index 78da12eb..3241e701 100644 --- a/ecs.yaml +++ b/ecs.yaml @@ -6,7 +6,7 @@ parameters: - "clean-code" - "common" # very nice to have ↓ - - "symplify" + # - "symplify" - "symfony" skip: diff --git a/src/Command/ShowEventLogCommand.php b/src/Command/ShowEventLogCommand.php index e9cc82f0..50c0d592 100644 --- a/src/Command/ShowEventLogCommand.php +++ b/src/Command/ShowEventLogCommand.php @@ -1,4 +1,7 @@ setDescription('List the last event log entries.') - ->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'How many log entries should be shown per page.', 50 ) - ->addOption('oldest_first', null, InputOption::VALUE_NONE,'Show older entries first.') - ->addOption('page', 'p', InputOption::VALUE_REQUIRED, 'Which page should be shown?', 1) - ->addOption('onePage', null, InputOption::VALUE_NONE, 'Show only one page (dont ask to go to next).') - ->addOption('showExtra', 'x', InputOption::VALUE_NONE, 'Show a column with the extra data.'); - ; - } - public function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); @@ -83,11 +73,12 @@ class ShowEventLogCommand extends Command $max_page = ceil($total_count / $limit); if ($page > $max_page) { - $io->error("There is no page $page! The maximum page is $max_page."); + $io->error("There is no page ${page}! The maximum page is ${max_page}."); + return 1; } - $io->note("There are a total of $total_count log entries in the DB."); + $io->note("There are a total of ${total_count} log entries in the DB."); $continue = true; while ($continue && $page <= $max_page) { @@ -98,12 +89,23 @@ class ShowEventLogCommand extends Command } $continue = $io->confirm('Do you want to show the next page?'); - $page++; + ++$page; } return 0; } + protected function configure(): void + { + $this + ->setDescription('List the last event log entries.') + ->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'How many log entries should be shown per page.', 50) + ->addOption('oldest_first', null, InputOption::VALUE_NONE, 'Show older entries first.') + ->addOption('page', 'p', InputOption::VALUE_REQUIRED, 'Which page should be shown?', 1) + ->addOption('onePage', null, InputOption::VALUE_NONE, 'Show only one page (dont ask to go to next).') + ->addOption('showExtra', 'x', InputOption::VALUE_NONE, 'Show a column with the extra data.'); + } + protected function showPage(OutputInterface $output, bool $desc, int $limit, int $page, int $max_page, bool $showExtra): void { $sorting = $desc ? 'ASC' : 'DESC'; @@ -113,7 +115,7 @@ class ShowEventLogCommand extends Command $entries = $this->repo->getLogsOrderedByTimestamp($sorting, $limit, $offset); $table = new Table($output); - $table->setHeaderTitle("Page $page / $max_page"); + $table->setHeaderTitle("Page ${page} / ${max_page}"); $headers = ['ID', 'Timestamp', 'Type', 'User', 'Target Type', 'Target']; if ($showExtra) { $headers[] = 'Extra data'; @@ -130,15 +132,15 @@ class ShowEventLogCommand extends Command protected function addTableRow(Table $table, AbstractLogEntry $entry, bool $showExtra): void { $target = $this->repo->getTargetElement($entry); - $target_name = ""; + $target_name = ''; if ($target instanceof NamedDBElement) { - $target_name = $target->getName() . ' (' . $target->getID() . ')'; + $target_name = $target->getName().' ('.$target->getID().')'; } elseif ($entry->getTargetID()) { - $target_name = '(' . $entry->getTargetID() . ')'; + $target_name = '('.$entry->getTargetID().')'; } - $target_class = ""; - if ($entry->getTargetClass() !== null) { + $target_class = ''; + if (null !== $entry->getTargetClass()) { $target_class = $this->elementTypeNameGenerator->getLocalizedTypeLabel($entry->getTargetClass()); } @@ -148,7 +150,7 @@ class ShowEventLogCommand extends Command $entry->getType(), $entry->getUser()->getFullName(true), $target_class, - $target_name + $target_name, ]; if ($showExtra) { @@ -157,4 +159,4 @@ class ShowEventLogCommand extends Command $table->addRow($row); } -} \ No newline at end of file +} diff --git a/src/Controller/LogController.php b/src/Controller/LogController.php index b1f7e343..f3a867cf 100644 --- a/src/Controller/LogController.php +++ b/src/Controller/LogController.php @@ -1,4 +1,7 @@ render('LogSystem/log_list.html.twig', [ - 'datatable' => $table + 'datatable' => $table, ]); } -} \ No newline at end of file +} diff --git a/src/DataTables/Adapter/FetchJoinORMAdapter.php b/src/DataTables/Adapter/FetchJoinORMAdapter.php index e3c04579..fb5c06e4 100644 --- a/src/DataTables/Adapter/FetchJoinORMAdapter.php +++ b/src/DataTables/Adapter/FetchJoinORMAdapter.php @@ -1,4 +1,7 @@ use_simple_total = $options['simple_total_query']; } - protected function configureOptions(OptionsResolver $resolver) + public function getResults(AdapterQuery $query): \Traversable + { + $builder = $query->get('qb'); + $state = $query->getState(); + + // Apply definitive view state for current 'page' of the table + foreach ($state->getOrderBy() as [$column, $direction]) { + /** @var AbstractColumn $column */ + if ($column->isOrderable()) { + $builder->addOrderBy($column->getOrderField(), $direction); + } + } + if ($state->getLength() > 0) { + $builder + ->setFirstResult($state->getStart()) + ->setMaxResults($state->getLength()); + } + + $query = $builder->getQuery(); + $event = new ORMAdapterQueryEvent($query); + $state->getDataTable()->getEventDispatcher()->dispatch($event, ORMAdapterEvents::PRE_QUERY); + + //Use Doctrine paginator for result iteration + $paginator = new Paginator($query); + + foreach ($paginator->getIterator() as $result) { + yield $result; + $this->manager->detach($result); + } + } + + public function getCount(QueryBuilder $queryBuilder, $identifier) + { + $paginator = new Paginator($queryBuilder); + + return $paginator->count(); + } + + protected function configureOptions(OptionsResolver $resolver): void { parent::configureOptions($resolver); //Enforce object hydration mode (fetch join only works for objects) $resolver->addAllowedValues('hydrate', Query::HYDRATE_OBJECT); - /** + /* * Add the possibility to replace the query for total entity count through a very simple one, to improve performance. * You can only use this option, if you did not apply any criteria to your total count. */ $resolver->setDefault('simple_total_query', false); - - return $resolver; } - protected function prepareQuery(AdapterQuery $query) + protected function prepareQuery(AdapterQuery $query): void { $state = $query->getState(); $query->set('qb', $builder = $this->createQueryBuilder($state)); @@ -96,43 +136,6 @@ class FetchJoinORMAdapter extends ORMAdapter $query->setIdentifierPropertyPath($this->mapFieldToPropertyPath($identifier, $aliases)); } - public function getResults(AdapterQuery $query): \Traversable - { - $builder = $query->get('qb'); - $state = $query->getState(); - - // Apply definitive view state for current 'page' of the table - foreach ($state->getOrderBy() as list($column, $direction)) { - /** @var AbstractColumn $column */ - if ($column->isOrderable()) { - $builder->addOrderBy($column->getOrderField(), $direction); - } - } - if ($state->getLength() > 0) { - $builder - ->setFirstResult($state->getStart()) - ->setMaxResults($state->getLength()); - } - - $query = $builder->getQuery(); - $event = new ORMAdapterQueryEvent($query); - $state->getDataTable()->getEventDispatcher()->dispatch($event, ORMAdapterEvents::PRE_QUERY); - - //Use Doctrine paginator for result iteration - $paginator = new Paginator($query); - - foreach ($paginator->getIterator() as $result) { - yield $result; - $this->manager->detach($result); - } - } - - public function getCount(QueryBuilder $queryBuilder, $identifier) - { - $paginator = new Paginator($queryBuilder); - return $paginator->count(); - } - protected function getSimpleTotalCount(QueryBuilder $queryBuilder) { /** The paginator count queries can be rather slow, so when query for total count (100ms or longer), @@ -140,6 +143,7 @@ class FetchJoinORMAdapter extends ORMAdapter */ /** @var Query\Expr\From $from_expr */ $from_expr = $queryBuilder->getDQLPart('from')[0]; + return $this->manager->getRepository($from_expr->getFrom())->count([]); } -} \ No newline at end of file +} diff --git a/src/DataTables/Adapter/ORMAdapter.php b/src/DataTables/Adapter/ORMAdapter.php index a6fff5c0..38c30c7d 100644 --- a/src/DataTables/Adapter/ORMAdapter.php +++ b/src/DataTables/Adapter/ORMAdapter.php @@ -37,28 +37,27 @@ use Symfony\Component\OptionsResolver\OptionsResolver; */ class ORMAdapter extends AbstractAdapter { - /** @var ManagerRegistry */ - private $registry; - /** @var EntityManager */ protected $manager; /** @var \Doctrine\ORM\Mapping\ClassMetadata */ protected $metadata; + /** @var QueryBuilderProcessorInterface[] */ + protected $criteriaProcessors; + /** @var ManagerRegistry */ + private $registry; + /** @var int */ private $hydrationMode; /** @var QueryBuilderProcessorInterface[] */ private $queryBuilderProcessors; - /** @var QueryBuilderProcessorInterface[] */ - protected $criteriaProcessors; - /** * DoctrineAdapter constructor. */ - public function __construct(ManagerRegistry $registry = null) + public function __construct(?ManagerRegistry $registry = null) { if (null === $registry) { throw new MissingDependencyException('Install doctrine/doctrine-bundle to use the ORMAdapter'); @@ -68,10 +67,7 @@ class ORMAdapter extends AbstractAdapter $this->registry = $registry; } - /** - * {@inheritdoc} - */ - public function configure(array $options) + public function configure(array $options): void { $resolver = new OptionsResolver(); $this->configureOptions($resolver); @@ -92,15 +88,12 @@ class ORMAdapter extends AbstractAdapter $this->criteriaProcessors = $options['criteria']; } - /** - * @param mixed $processor - */ - public function addCriteriaProcessor($processor) + public function addCriteriaProcessor($processor): void { $this->criteriaProcessors[] = $this->normalizeProcessor($processor); } - protected function prepareQuery(AdapterQuery $query) + protected function prepareQuery(AdapterQuery $query): void { $state = $query->getState(); $query->set('qb', $builder = $this->createQueryBuilder($state)); @@ -150,7 +143,7 @@ class ORMAdapter extends AbstractAdapter continue; } - list($origin, $target) = explode('.', $join->getJoin()); + [$origin, $target] = explode('.', $join->getJoin()); $mapping = $aliases[$origin][1]->getAssociationMapping($target); $aliases[$join->getAlias()] = [$join->getJoin(), $this->manager->getMetadataFactory()->getMetadataFor($mapping['targetEntity'])]; @@ -160,9 +153,6 @@ class ORMAdapter extends AbstractAdapter return $aliases; } - /** - * {@inheritdoc} - */ protected function mapPropertyPath(AdapterQuery $query, AbstractColumn $column) { return $this->mapFieldToPropertyPath($column->getField(), $query->get('aliases')); @@ -175,7 +165,7 @@ class ORMAdapter extends AbstractAdapter $state = $query->getState(); // Apply definitive view state for current 'page' of the table - foreach ($state->getOrderBy() as list($column, $direction)) { + foreach ($state->getOrderBy() as [$column, $direction]) { /** @var AbstractColumn $column */ if ($column->isOrderable()) { $builder->addOrderBy($column->getOrderField(), $direction); @@ -200,7 +190,7 @@ class ORMAdapter extends AbstractAdapter } } - protected function buildCriteria(QueryBuilder $queryBuilder, DataTableState $state) + protected function buildCriteria(QueryBuilder $queryBuilder, DataTableState $state): void { foreach ($this->criteriaProcessors as $provider) { $provider->process($queryBuilder, $state); @@ -222,6 +212,7 @@ class ORMAdapter extends AbstractAdapter /** * @param $identifier + * * @return int */ protected function getCount(QueryBuilder $queryBuilder, $identifier) @@ -230,21 +221,21 @@ class ORMAdapter extends AbstractAdapter $qb->resetDQLPart('orderBy'); $gb = $qb->getDQLPart('groupBy'); - if (empty($gb) || !$this->hasGroupByPart($identifier, $gb)) { + if (empty($gb) || ! $this->hasGroupByPart($identifier, $gb)) { $qb->select($qb->expr()->count($identifier)); - return (int) $qb->getQuery()->getSingleScalarResult(); - } else { - $qb->resetDQLPart('groupBy'); - $qb->select($qb->expr()->countDistinct($identifier)); - return (int) $qb->getQuery()->getSingleScalarResult(); } + $qb->resetDQLPart('groupBy'); + $qb->select($qb->expr()->countDistinct($identifier)); + + return (int) $qb->getQuery()->getSingleScalarResult(); } /** * @param $identifier * @param Query\Expr\GroupBy[] $gbList + * * @return bool */ protected function hasGroupByPart($identifier, array $gbList) @@ -260,6 +251,7 @@ class ORMAdapter extends AbstractAdapter /** * @param string $field + * * @return string */ protected function mapFieldToPropertyPath($field, array $aliases = []) @@ -268,25 +260,25 @@ class ORMAdapter extends AbstractAdapter if (count($parts) < 2) { throw new InvalidConfigurationException(sprintf("Field name '%s' must consist at least of an alias and a field separated with a period", $field)); } - list($origin, $target) = $parts; + [$origin, $target] = $parts; $path = [$target]; $current = $aliases[$origin][0]; while (null !== $current) { - list($origin, $target) = explode('.', $current); + [$origin, $target] = explode('.', $current); $path[] = $target; $current = $aliases[$origin][0]; } if (Query::HYDRATE_ARRAY === $this->hydrationMode) { - return '[' . implode('][', array_reverse($path)) . ']'; - } else { - return implode('.', array_reverse($path)); + return '['.implode('][', array_reverse($path)).']'; } + + return implode('.', array_reverse($path)); } - protected function configureOptions(OptionsResolver $resolver) + protected function configureOptions(OptionsResolver $resolver): void { $providerNormalizer = function (Options $options, $value) { return array_map([$this, 'normalizeProcessor'], (array) $value); @@ -294,12 +286,12 @@ class ORMAdapter extends AbstractAdapter $resolver ->setDefaults([ - 'hydrate' => Query::HYDRATE_OBJECT, - 'query' => [], - 'criteria' => function (Options $options) { - return [new SearchCriteriaProvider()]; - }, - ]) + 'hydrate' => Query::HYDRATE_OBJECT, + 'query' => [], + 'criteria' => function (Options $options) { + return [new SearchCriteriaProvider()]; + }, + ]) ->setRequired('entity') ->setAllowedTypes('entity', ['string']) ->setAllowedTypes('hydrate', 'int') @@ -312,6 +304,7 @@ class ORMAdapter extends AbstractAdapter /** * @param callable|QueryBuilderProcessorInterface $provider + * * @return QueryBuilderProcessorInterface */ private function normalizeProcessor($provider) diff --git a/src/DataTables/AttachmentDataTable.php b/src/DataTables/AttachmentDataTable.php index 14bdd9ab..83da8ceb 100644 --- a/src/DataTables/AttachmentDataTable.php +++ b/src/DataTables/AttachmentDataTable.php @@ -40,11 +40,11 @@ use Symfony\Contracts\Translation\TranslatorInterface; final class AttachmentDataTable implements DataTableTypeInterface { - protected $translator; - protected $entityURLGenerator; - protected $attachmentHelper; - protected $elementTypeNameGenerator; - protected $attachmentURLGenerator; + private $translator; + private $entityURLGenerator; + private $attachmentHelper; + private $elementTypeNameGenerator; + private $attachmentURLGenerator; public function __construct(TranslatorInterface $translator, EntityURLGenerator $entityURLGenerator, AttachmentManager $attachmentHelper, AttachmentURLGenerator $attachmentURLGenerator, @@ -203,7 +203,7 @@ final class AttachmentDataTable implements DataTableTypeInterface ]); } - protected function getQuery(QueryBuilder $builder): void + private function getQuery(QueryBuilder $builder): void { $builder->distinct()->select('attachment') ->addSelect('attachment_type') diff --git a/src/DataTables/Column/LogEntryExtraColumn.php b/src/DataTables/Column/LogEntryExtraColumn.php index e3d9d5c9..002f480d 100644 --- a/src/DataTables/Column/LogEntryExtraColumn.php +++ b/src/DataTables/Column/LogEntryExtraColumn.php @@ -1,4 +1,7 @@ formatter = $formatter; } - /** - * @inheritDoc - */ public function normalize($value) { return $value; @@ -58,4 +48,4 @@ class LogEntryExtraColumn extends AbstractColumn { return $this->formatter->format($context); } -} \ No newline at end of file +} diff --git a/src/DataTables/Column/LogEntryTargetColumn.php b/src/DataTables/Column/LogEntryTargetColumn.php index 75d9535d..327b7f07 100644 --- a/src/DataTables/Column/LogEntryTargetColumn.php +++ b/src/DataTables/Column/LogEntryTargetColumn.php @@ -1,4 +1,7 @@ translator = $translator; } - /** - * @inheritDoc - */ public function normalize($value) { return $value; } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { parent::configureOptions($resolver); } @@ -89,7 +87,7 @@ class LogEntryTargetColumn extends AbstractColumn } //Element was deleted - if ($target === null && $context->hasTarget()) { + if (null === $target && $context->hasTarget()) { return sprintf( '%s: %s [%s]', $this->elementTypeNameGenerator->getLocalizedTypeLabel($context->getTargetClass()), @@ -99,6 +97,6 @@ class LogEntryTargetColumn extends AbstractColumn } //Log is not associated with an element - return ""; + return ''; } -} \ No newline at end of file +} diff --git a/src/DataTables/LogDataTable.php b/src/DataTables/LogDataTable.php index d6c0306a..2824a153 100644 --- a/src/DataTables/LogDataTable.php +++ b/src/DataTables/LogDataTable.php @@ -1,4 +1,7 @@ urlGenerator = $urlGenerator; } - public function configure(DataTable $dataTable, array $options) + public function configure(DataTable $dataTable, array $options): void { $dataTable->add('symbol', TextColumn::class, [ 'label' => '', @@ -62,35 +60,44 @@ class LogDataTable implements DataTableTypeInterface switch ($context->getLevelString()) { case LogLevel::DEBUG: $symbol = 'fa-bug'; + break; case LogLevel::INFO: $symbol = 'fa-info'; + break; case LogLevel::NOTICE: $symbol = 'fa-flag'; + break; case LogLevel::WARNING: $symbol = 'fa-exclamation-circle'; + break; case LogLevel::ERROR: $symbol = 'fa-exclamation-triangle'; + break; case LogLevel::CRITICAL: $symbol = 'fa-bolt'; + break; case LogLevel::ALERT: $symbol = 'fa-radiation'; + break; case LogLevel::EMERGENCY: $symbol = 'fa-skull-crossbones'; + break; default: $symbol = 'fa-question-circle'; + break; } return sprintf('', $symbol); - } + }, ]); $dataTable->add('id', TextColumn::class, [ @@ -100,16 +107,15 @@ class LogDataTable implements DataTableTypeInterface $dataTable->add('timestamp', LocaleDateTimeColumn::class, [ 'label' => $this->translator->trans('log.timestamp'), - 'timeFormat' => 'medium' + 'timeFormat' => 'medium', ]); $dataTable->add('type', TextColumn::class, [ 'label' => $this->translator->trans('log.type'), 'propertyPath' => 'type', 'render' => function (string $value, AbstractLogEntry $context) { - return $this->translator->trans('log.type.' . $value); - } - + return $this->translator->trans('log.type.'.$value); + }, ]); $dataTable->add('level', TextColumn::class, [ @@ -117,42 +123,41 @@ class LogDataTable implements DataTableTypeInterface 'propertyPath' => 'levelString', 'render' => function (string $value, AbstractLogEntry $context) { return $value; - } + }, ]); - $dataTable->add('user', TextColumn::class, [ 'label' => $this->translator->trans('log.user'), 'render' => function ($value, AbstractLogEntry $context) { $user = $context->getUser(); + return sprintf( '%s', $this->urlGenerator->generate('user_info', ['id' => $user->getID()]), $user->getFullName(true) ); - } + }, ]); - - $dataTable->add('target_type', TextColumn::class, [ 'label' => $this->translator->trans('log.target_type'), 'visible' => false, 'render' => function ($value, AbstractLogEntry $context) { $class = $context->getTargetClass(); - if ($class !== null) { + if (null !== $class) { return $this->elementTypeNameGenerator->getLocalizedTypeLabel($class); } + return ''; - } + }, ]); $dataTable->add('target', LogEntryTargetColumn::class, [ - 'label' => $this->translator->trans('log.target') + 'label' => $this->translator->trans('log.target'), ]); $dataTable->add('extra', LogEntryExtraColumn::class, [ - 'label' => $this->translator->trans('log.extra') + 'label' => $this->translator->trans('log.extra'), ]); $dataTable->addOrderBy('timestamp', DataTable::SORT_DESCENDING); @@ -172,4 +177,4 @@ class LogDataTable implements DataTableTypeInterface ->from(AbstractLogEntry::class, 'log') ->leftJoin('log.user', 'user'); } -} \ No newline at end of file +} diff --git a/src/DataTables/PartsDataTable.php b/src/DataTables/PartsDataTable.php index fe17453c..be1e8b61 100644 --- a/src/DataTables/PartsDataTable.php +++ b/src/DataTables/PartsDataTable.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace App\DataTables; -use App\DataTables\Adapter\CustomORMAdapter; use App\DataTables\Adapter\FetchJoinORMAdapter; use App\DataTables\Column\EntityColumn; use App\DataTables\Column\LocaleDateTimeColumn; @@ -53,15 +52,15 @@ use Symfony\Contracts\Translation\TranslatorInterface; final class PartsDataTable implements DataTableTypeInterface { - protected $translator; - protected $treeBuilder; - protected $amountFormatter; - protected $previewGenerator; - protected $attachmentURLGenerator; + private $translator; + private $treeBuilder; + private $amountFormatter; + private $previewGenerator; + private $attachmentURLGenerator; /** * @var EntityURLGenerator */ - protected $urlGenerator; + private $urlGenerator; public function __construct(EntityURLGenerator $urlGenerator, TranslatorInterface $translator, NodesListBuilder $treeBuilder, AmountFormatter $amountFormatter, @@ -231,7 +230,7 @@ final class PartsDataTable implements DataTableTypeInterface ]); } - protected function getQuery(QueryBuilder $builder): void + private function getQuery(QueryBuilder $builder): void { $builder->distinct()->select('part') ->addSelect('category') @@ -257,7 +256,7 @@ final class PartsDataTable implements DataTableTypeInterface ->leftJoin('part.partUnit', 'partUnit'); } - protected function buildCriteria(QueryBuilder $builder, array $options): void + private function buildCriteria(QueryBuilder $builder, array $options): void { $em = $builder->getEntityManager(); diff --git a/src/Entity/Base/StructuralDBElement.php b/src/Entity/Base/StructuralDBElement.php index 6a74ff9e..53d14b58 100644 --- a/src/Entity/Base/StructuralDBElement.php +++ b/src/Entity/Base/StructuralDBElement.php @@ -31,7 +31,6 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use function get_class; use InvalidArgumentException; -use function is_array; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Serializer\Annotation\Groups; @@ -55,7 +54,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement public const ID_ROOT_ELEMENT = 0; /** - * This is a not standard character, so build a const, so a dev can easily use it + * This is a not standard character, so build a const, so a dev can easily use it. */ public const PATH_DELIMITER_ARROW = ' → '; diff --git a/src/Entity/LogSystem/AbstractLogEntry.php b/src/Entity/LogSystem/AbstractLogEntry.php index a7750b04..15bd4b2c 100644 --- a/src/Entity/LogSystem/AbstractLogEntry.php +++ b/src/Entity/LogSystem/AbstractLogEntry.php @@ -1,4 +1,5 @@ LogLevel::DEBUG, ]; - protected const TARGET_CLASS_MAPPING = [ self::TARGET_TYPE_USER => User::class, self::TARGET_TYPE_ATTACHEMENT => Attachment::class, @@ -113,7 +113,7 @@ abstract class AbstractLogEntry extends DBElement self::TARGET_TYPE_SUPPLIER => Supplier::class, ]; - /** @var User $user The user which has caused this log entry + /** @var User The user which has caused this log entry * @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User") * @ORM\JoinColumn(name="id_user", nullable=false) */ @@ -124,17 +124,17 @@ abstract class AbstractLogEntry extends DBElement */ protected $timestamp; - /** @var integer The priority level of the associated level. 0 is highest, 7 lowest + /** @var int The priority level of the associated level. 0 is highest, 7 lowest * @ORM\Column(type="integer", name="level", columnDefinition="TINYINT") */ protected $level; - /** @var int $target_id The ID of the element targeted by this event + /** @var int The ID of the element targeted by this event * @ORM\Column(name="target_id", type="integer", nullable=false) */ protected $target_id = 0; - /** @var int $target_type The Type of the targeted element + /** @var int The Type of the targeted element * @ORM\Column(name="target_type", type="smallint", nullable=false) */ protected $target_type = 0; @@ -143,7 +143,7 @@ abstract class AbstractLogEntry extends DBElement * The mapping between the log entry class and the discriminator column is done by doctrine. * Each subclass should override this string to specify a better string. */ - protected $typeString = "unknown"; + protected $typeString = 'unknown'; /** @var array The extra data in raw (short form) saved in the DB * @ORM\Column(name="extra", type="json") @@ -158,6 +158,7 @@ abstract class AbstractLogEntry extends DBElement /** * Get the user that caused the event associated with this log entry. + * * @return User */ public function getUser(): ?User @@ -167,17 +168,19 @@ abstract class AbstractLogEntry extends DBElement /** * Sets the user that caused the event. - * @param User $user + * * @return $this */ public function setUser(User $user): self { $this->user = $user; + return $this; } /** - * Returns the timestamp when the event that caused this log entry happened + * Returns the timestamp when the event that caused this log entry happened. + * * @return DateTime */ public function getTimestamp(): DateTime @@ -187,18 +190,20 @@ abstract class AbstractLogEntry extends DBElement /** * Sets the timestamp when the event happened. - * @param DateTime $timestamp + * * @return $this */ - public function setTimestamp(DateTime $timestamp): AbstractLogEntry + public function setTimestamp(DateTime $timestamp): self { $this->timestamp = $timestamp; + return $this; } /** * Get the priority level of this log entry. 0 is highest and 7 lowest level. - * See LEVEL_* consts in this class for more info + * See LEVEL_* consts in this class for more info. + * * @return int */ public function getLevel(): int @@ -207,25 +212,28 @@ abstract class AbstractLogEntry extends DBElement if ($this->level < 0 || $this->level > 7) { return self::LEVEL_ALERT; } + return $this->level; } /** * Sets the new level of this log entry. - * @param int $level + * * @return $this */ - public function setLevel(int $level): AbstractLogEntry + public function setLevel(int $level): self { if ($level < 0 || $this->level > 7) { throw new \InvalidArgumentException(sprintf('$level must be between 0 and 7! %d given!', $level)); } $this->level = $level; + return $this; } /** - * Get the priority level of this log entry as PSR3 compatible string + * Get the priority level of this log entry as PSR3 compatible string. + * * @return string */ public function getLevelString(): string @@ -234,18 +242,20 @@ abstract class AbstractLogEntry extends DBElement } /** - * Sets the priority level of this log entry as PSR3 compatible string - * @param string $level + * Sets the priority level of this log entry as PSR3 compatible string. + * * @return $this */ - public function setLevelString(string $level): AbstractLogEntry + public function setLevelString(string $level): self { $this->setLevel(self::levelStringToInt($level)); + return $this; } /** * Returns the type of the event this log entry is associated with. + * * @return string */ public function getType(): string @@ -253,22 +263,20 @@ abstract class AbstractLogEntry extends DBElement return $this->typeString; } - /** - * @inheritDoc - */ public function getIDString(): string { - return "LOG".$this->getID(); + return 'LOG'.$this->getID(); } /** * Returns the class name of the target element associated with this log entry. * Returns null, if this log entry is not associated with an log entry. + * * @return string|null The class name of the target class. */ public function getTargetClass(): ?string { - if ($this->target_type === self::TARGET_TYPE_NONE) { + if (self::TARGET_TYPE_NONE === $this->target_type) { return null; } @@ -278,11 +286,12 @@ abstract class AbstractLogEntry extends DBElement /** * Returns the ID of the target element associated with this log entry. * Returns null, if this log entry is not associated with an log entry. + * * @return int|null The ID of the associated element. */ public function getTargetID(): ?int { - if ($this->target_id === 0) { + if (0 === $this->target_id) { return null; } @@ -290,24 +299,28 @@ abstract class AbstractLogEntry extends DBElement } /** - * Checks if this log entry is associated with an element + * Checks if this log entry is associated with an element. + * * @return bool True if this log entry is associated with an element, false otherwise. */ public function hasTarget(): bool { - return $this->getTargetID() !== null && $this->getTargetClass() !== null; + return null !== $this->getTargetID() && null !== $this->getTargetClass(); } /** - * Sets the target element associated with this element - * @param DBElement $element The element that should be associated with this element. + * Sets the target element associated with this element. + * + * @param DBElement $element The element that should be associated with this element. + * * @return $this */ public function setTargetElement(?DBElement $element): self { - if ($element === null) { + if (null === $element) { $this->target_id = 0; $this->target_type = self::TARGET_TYPE_NONE; + return $this; } @@ -324,12 +337,14 @@ abstract class AbstractLogEntry extends DBElement /** * This function converts the internal numeric log level into an PSR3 compatible level string. - * @param int $level The numerical log level + * + * @param int $level The numerical log level + * * @return string The PSR3 compatible level string */ final public static function levelIntToString(int $level): string { - if (!isset(self::LEVEL_ID_TO_STRING[$level])) { + if (! isset(self::LEVEL_ID_TO_STRING[$level])) { throw new \InvalidArgumentException('No level with this int is existing!'); } @@ -338,13 +353,15 @@ abstract class AbstractLogEntry extends DBElement /** * This function converts a PSR3 compatible string to the internal numeric level string. + * * @param string $level the PSR3 compatible string that should be converted + * * @return int The internal int representation. */ final public static function levelStringToInt(string $level): int { $tmp = array_flip(self::LEVEL_ID_TO_STRING); - if (!isset($tmp[$level])) { + if (! isset($tmp[$level])) { throw new \InvalidArgumentException('No level with this string is existing!'); } @@ -353,12 +370,14 @@ abstract class AbstractLogEntry extends DBElement /** * Converts an target type id to an full qualified class name. - * @param int $type_id The target type ID + * + * @param int $type_id The target type ID + * * @return string */ final public static function targetTypeIdToClass(int $type_id): string { - if (!isset(self::TARGET_CLASS_MAPPING[$type_id])) { + if (! isset(self::TARGET_CLASS_MAPPING[$type_id])) { throw new \InvalidArgumentException('No target type with this ID is existing!'); } @@ -367,7 +386,9 @@ abstract class AbstractLogEntry extends DBElement /** * Convert a class name to a target type ID. - * @param string $class The name of the class (FQN) that should be converted to id + * + * @param string $class The name of the class (FQN) that should be converted to id + * * @return int The ID of the associated target type ID. */ final public static function targetTypeClassToID(string $class): int @@ -387,6 +408,4 @@ abstract class AbstractLogEntry extends DBElement throw new \InvalidArgumentException('No target ID for this class is existing!'); } - - -} \ No newline at end of file +} diff --git a/src/Entity/LogSystem/ConfigChangedLogEntry.php b/src/Entity/LogSystem/ConfigChangedLogEntry.php index 2c06cd51..c94d3b2a 100644 --- a/src/Entity/LogSystem/ConfigChangedLogEntry.php +++ b/src/Entity/LogSystem/ConfigChangedLogEntry.php @@ -1,4 +1,7 @@ extra['n']; } - -} \ No newline at end of file +} diff --git a/src/Entity/LogSystem/ElementCreatedLogEntry.php b/src/Entity/LogSystem/ElementCreatedLogEntry.php index 97d6f6c0..f27b73e1 100644 --- a/src/Entity/LogSystem/ElementCreatedLogEntry.php +++ b/src/Entity/LogSystem/ElementCreatedLogEntry.php @@ -1,4 +1,7 @@ getCreationInstockValue() !== null; + return null !== $this->getCreationInstockValue(); } -} \ No newline at end of file +} diff --git a/src/Entity/LogSystem/ElementDeletedLogEntry.php b/src/Entity/LogSystem/ElementDeletedLogEntry.php index 5756d2a0..2af0aade 100644 --- a/src/Entity/LogSystem/ElementDeletedLogEntry.php +++ b/src/Entity/LogSystem/ElementDeletedLogEntry.php @@ -1,4 +1,7 @@ extra['n']; } -} \ No newline at end of file +} diff --git a/src/Entity/LogSystem/ElementEditedLogEntry.php b/src/Entity/LogSystem/ElementEditedLogEntry.php index 87855cea..72908504 100644 --- a/src/Entity/LogSystem/ElementEditedLogEntry.php +++ b/src/Entity/LogSystem/ElementEditedLogEntry.php @@ -1,4 +1,7 @@ extra['m'] ?? ''; } -} \ No newline at end of file +} diff --git a/src/Entity/LogSystem/ExceptionLogEntry.php b/src/Entity/LogSystem/ExceptionLogEntry.php index abf1935f..bdd08a88 100644 --- a/src/Entity/LogSystem/ExceptionLogEntry.php +++ b/src/Entity/LogSystem/ExceptionLogEntry.php @@ -1,4 +1,7 @@ extra['t'] ?? "Unknown Class"; + return $this->extra['t'] ?? 'Unknown Class'; } /** * Returns the file where the exception happened. + * * @return string */ public function getFile(): string @@ -57,7 +60,8 @@ class ExceptionLogEntry extends AbstractLogEntry } /** - * Returns the line where the exception happened + * Returns the line where the exception happened. + * * @return int */ public function getLine(): int @@ -67,11 +71,11 @@ class ExceptionLogEntry extends AbstractLogEntry /** * Return the message of the exception. + * * @return string */ public function getMessage(): string { return $this->extra['m']; } - -} \ No newline at end of file +} diff --git a/src/Entity/LogSystem/InstockChangedLogEntry.php b/src/Entity/LogSystem/InstockChangedLogEntry.php index 079bb62b..5394213f 100644 --- a/src/Entity/LogSystem/InstockChangedLogEntry.php +++ b/src/Entity/LogSystem/InstockChangedLogEntry.php @@ -1,4 +1,7 @@ extra['p']); } + return $this->extra['p']; } /** * Returns the difference value of the change ($new_instock - $old_instock). - * @param $absolute bool Set this to true if you want only the absolute value of the difference. + * + * @param bool $absolute Set this to true if you want only the absolute value of the difference. + * * @return int Difference is positive if instock has increased, negative if decreased. */ public function getDifference(bool $absolute = false): int { // Check if one of the instock values is unknown - if ($this->getNewInstock() == -2 || $this->getOldInstock() == -2) { + if (-2 === $this->getNewInstock() || -2 === $this->getOldInstock()) { return 0; } @@ -95,11 +103,11 @@ class InstockChangedLogEntry extends AbstractLogEntry /** * Checks if the Change was an withdrawal of parts. + * * @return bool True if the change was an withdrawal, false if not. */ public function isWithdrawal(): bool { return $this->getNewInstock() < $this->getOldInstock(); } - -} \ No newline at end of file +} diff --git a/src/Entity/LogSystem/UserLoginLogEntry.php b/src/Entity/LogSystem/UserLoginLogEntry.php index 734010d5..090027f7 100644 --- a/src/Entity/LogSystem/UserLoginLogEntry.php +++ b/src/Entity/LogSystem/UserLoginLogEntry.php @@ -1,4 +1,7 @@ extra['i'] = $ip; + return $this; } -} \ No newline at end of file +} diff --git a/src/Entity/LogSystem/UserLogoutLogEntry.php b/src/Entity/LogSystem/UserLogoutLogEntry.php index b3fe0124..0c985567 100644 --- a/src/Entity/LogSystem/UserLogoutLogEntry.php +++ b/src/Entity/LogSystem/UserLogoutLogEntry.php @@ -1,4 +1,7 @@ extra['i'] = $ip; + return $this; } - - -} \ No newline at end of file +} diff --git a/src/Entity/LogSystem/UserNotAllowedLogEntry.php b/src/Entity/LogSystem/UserNotAllowedLogEntry.php index 71aaf626..617565dc 100644 --- a/src/Entity/LogSystem/UserNotAllowedLogEntry.php +++ b/src/Entity/LogSystem/UserNotAllowedLogEntry.php @@ -1,4 +1,7 @@ extra['p'] ?? ''; } -} \ No newline at end of file +} diff --git a/src/Entity/Parts/Part.php b/src/Entity/Parts/Part.php index ae8dfa65..a3680e6c 100644 --- a/src/Entity/Parts/Part.php +++ b/src/Entity/Parts/Part.php @@ -84,7 +84,7 @@ class Part extends AttachmentContainingDBElement use OrderTrait; /** - * TODO + * TODO. */ protected $devices; diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index c8ae0f8a..40dc02bf 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -90,7 +90,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe use MasterAttachmentTrait; /** - * The User id of the anonymous user + * The User id of the anonymous user. */ public const ID_ANONYMOUS = 1; diff --git a/src/EventSubscriber/LoginSuccessListener.php b/src/EventSubscriber/LoginSuccessListener.php index be9bed58..0c426789 100644 --- a/src/EventSubscriber/LoginSuccessListener.php +++ b/src/EventSubscriber/LoginSuccessListener.php @@ -38,10 +38,10 @@ use Symfony\Contracts\Translation\TranslatorInterface; */ final class LoginSuccessListener implements EventSubscriberInterface { - protected $translator; - protected $flashBag; - protected $eventLogger; - protected $gpdr_compliance; + private $translator; + private $flashBag; + private $eventLogger; + private $gpdr_compliance; public function __construct(TranslatorInterface $translator, FlashBagInterface $flashBag, EventLogger $eventLogger, bool $gpdr_compliance) { diff --git a/src/EventSubscriber/LogoutListener.php b/src/EventSubscriber/LogoutListener.php index 63f64846..660a4f68 100644 --- a/src/EventSubscriber/LogoutListener.php +++ b/src/EventSubscriber/LogoutListener.php @@ -1,4 +1,7 @@ gpdr_compliance = $gpdr_compliance; } - /** - * @inheritDoc - */ - public function logout(Request $request, Response $response, TokenInterface $token) + public function logout(Request $request, Response $response, TokenInterface $token): void { $log = new UserLogoutLogEntry($request->getClientIp(), $this->gpdr_compliance); $user = $token->getUser(); @@ -54,4 +53,4 @@ class LogoutListener implements LogoutHandlerInterface $this->logger->logAndFlush($log); } -} \ No newline at end of file +} diff --git a/src/EventSubscriber/LogoutOnDisabledUserListener.php b/src/EventSubscriber/LogoutOnDisabledUserListener.php index 81b152a4..fc30cb1c 100644 --- a/src/EventSubscriber/LogoutOnDisabledUserListener.php +++ b/src/EventSubscriber/LogoutOnDisabledUserListener.php @@ -34,10 +34,10 @@ use Symfony\Component\Security\Core\Security; final class LogoutOnDisabledUserListener implements EventSubscriberInterface { - protected $security; - protected $translator; - protected $flashBag; - protected $urlGenerator; + private $security; + private $translator; + private $flashBag; + private $urlGenerator; public function __construct(Security $security, UrlGeneratorInterface $urlGenerator) { diff --git a/src/EventSubscriber/MailFromListener.php b/src/EventSubscriber/MailFromListener.php index b8021219..1806f888 100644 --- a/src/EventSubscriber/MailFromListener.php +++ b/src/EventSubscriber/MailFromListener.php @@ -31,8 +31,8 @@ use Symfony\Component\Mime\Email; final class MailFromListener implements EventSubscriberInterface { - protected $email; - protected $name; + private $email; + private $name; public function __construct(string $email, string $name) { diff --git a/src/EventSubscriber/MigrationListener.php b/src/EventSubscriber/MigrationListener.php index dd7c2441..84db9d7f 100644 --- a/src/EventSubscriber/MigrationListener.php +++ b/src/EventSubscriber/MigrationListener.php @@ -1,4 +1,7 @@ old_version = empty($this->old_version) ? 'legacy/empty' : $this->old_version; $this->new_version = empty($this->new_version) ? 'unknown' : $this->new_version; - try { $log = new DatabaseUpdatedLogEntry($this->old_version, $this->new_version); $this->eventLogger->logAndFlush($log); - } catch (\Exception $exception) { + } catch (\Throwable $exception) { //Ignore any exception occuring here... } - } - public function onMigrationsMigrating(MigrationsEventArgs $args): void { // Save the version before any migration - if ($this->old_version == null) { + if (null === $this->old_version) { $this->old_version = $args->getConfiguration()->getCurrentVersion(); } } - /** - * @inheritDoc - */ public function getSubscribedEvents() { return [ Events::onMigrationsMigrated, Events::onMigrationsMigrating, - ]; + ]; } -} \ No newline at end of file +} diff --git a/src/EventSubscriber/PasswordChangeNeededSubscriber.php b/src/EventSubscriber/PasswordChangeNeededSubscriber.php index 52b8b735..b31eef7f 100644 --- a/src/EventSubscriber/PasswordChangeNeededSubscriber.php +++ b/src/EventSubscriber/PasswordChangeNeededSubscriber.php @@ -55,9 +55,9 @@ final class PasswordChangeNeededSubscriber implements EventSubscriberInterface * @var string The route the user will redirected to, if he needs to change this password */ public const REDIRECT_TARGET = 'user_settings'; - protected $security; - protected $flashBag; - protected $httpUtils; + private $security; + private $flashBag; + private $httpUtils; public function __construct(Security $security, FlashBagInterface $flashBag, HttpUtils $httpUtils) { diff --git a/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php b/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php index 12a5f979..c42ad500 100644 --- a/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php +++ b/src/EventSubscriber/SymfonyDebugToolbarSubscriber.php @@ -30,7 +30,7 @@ use Symfony\Component\HttpKernel\Event\FilterResponseEvent; final class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface { - protected $kernel; + private $kernel; public function __construct(ContainerInterface $kernel) { diff --git a/src/EventSubscriber/TimezoneListener.php b/src/EventSubscriber/TimezoneListener.php index d5abb465..513aa80e 100644 --- a/src/EventSubscriber/TimezoneListener.php +++ b/src/EventSubscriber/TimezoneListener.php @@ -35,8 +35,8 @@ use Symfony\Component\Security\Core\Security; */ final class TimezoneListener implements EventSubscriberInterface { - protected $default_timezone; - protected $security; + private $default_timezone; + private $security; public function __construct(string $timezone, Security $security) { diff --git a/src/EventSubscriber/U2FRegistrationSubscriber.php b/src/EventSubscriber/U2FRegistrationSubscriber.php index 2748fe47..54622d6c 100644 --- a/src/EventSubscriber/U2FRegistrationSubscriber.php +++ b/src/EventSubscriber/U2FRegistrationSubscriber.php @@ -34,10 +34,10 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; final class U2FRegistrationSubscriber implements EventSubscriberInterface { - protected $em; + private $em; - protected $demo_mode; - protected $flashBag; + private $demo_mode; + private $flashBag; /** * @var UrlGeneratorInterface */ @@ -51,9 +51,6 @@ final class U2FRegistrationSubscriber implements EventSubscriberInterface $this->flashBag = $flashBag; } - /** - * - */ public static function getSubscribedEvents(): array { return [ diff --git a/src/Exceptions/LogEntryObsoleteException.php b/src/Exceptions/LogEntryObsoleteException.php index b7e923ef..d8cbd66d 100644 --- a/src/Exceptions/LogEntryObsoleteException.php +++ b/src/Exceptions/LogEntryObsoleteException.php @@ -1,4 +1,7 @@ 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('ALTER TABLE log CHANGE datetime datetime DATETIME NOT NULL, CHANGE level level TINYINT, CHANGE extra extra LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\''); $this->addSql('DROP INDEX id_user ON log'); @@ -28,10 +28,10 @@ final class Version20200126191823 extends AbstractMigration $this->addSql('CREATE INDEX IDX_8F3F68C56B3CA4B ON log (id_user)'); } - 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('ALTER TABLE log DROP FOREIGN KEY FK_8F3F68C56B3CA4B'); $this->addSql('ALTER TABLE log DROP FOREIGN KEY FK_8F3F68C56B3CA4B'); diff --git a/src/Repository/LogEntryRepository.php b/src/Repository/LogEntryRepository.php index e4742131..7b67ec14 100644 --- a/src/Repository/LogEntryRepository.php +++ b/src/Repository/LogEntryRepository.php @@ -1,4 +1,7 @@ getTargetClass(); $id = $logEntry->getTargetID(); - if ($class === null || $id === null) { + if (null === $class || null === $id) { return null; } return $this->getEntityManager()->find($class, $id); } -} \ No newline at end of file +} diff --git a/src/Security/Voter/LogEntryVoter.php b/src/Security/Voter/LogEntryVoter.php index 1e2a8476..8348e1bc 100644 --- a/src/Security/Voter/LogEntryVoter.php +++ b/src/Security/Voter/LogEntryVoter.php @@ -1,4 +1,7 @@ resolver->inherit($user, 'system', 'delete_logs') ?? false; } - if ($attribute === 'read') { + if ('read' === $attribute) { //Allow read of the users own log entries if ( $subject->getUser() === $user @@ -49,22 +47,19 @@ class LogEntryVoter extends ExtendedVoter return true; } - return $this->resolver->inherit($user, 'system','show_logs') ?? false; + return $this->resolver->inherit($user, 'system', 'show_logs') ?? false; } } return false; } - /** - * @inheritDoc - */ protected function supports($attribute, $subject) { if ($subject instanceof AbstractLogEntry) { - return in_array($subject, static::ALLOWED_OPS); + return in_array($subject, static::ALLOWED_OPS, true); } return false; } -} \ No newline at end of file +} diff --git a/src/Services/LogSystem/EventLogger.php b/src/Services/LogSystem/EventLogger.php index acbf8f5d..d7651ac8 100644 --- a/src/Services/LogSystem/EventLogger.php +++ b/src/Services/LogSystem/EventLogger.php @@ -1,4 +1,7 @@ security->getUser(); //If the user is not specified explicitly, set it to the current user - if (($user === null || $user instanceof User) && $logEntry->getUser() === null) { - if ($user === null) { + if ((null === $user || $user instanceof User) && null === $logEntry->getUser()) { + if (null === $user) { $repo = $this->em->getRepository(User::class); $user = $repo->getAnonymousUser(); } @@ -64,6 +66,7 @@ class EventLogger if ($this->shouldBeAdded($logEntry)) { $this->em->persist($logEntry); + return true; } @@ -72,13 +75,14 @@ class EventLogger /** * Adds the given log entry to the Log, if the entry fullfills the global configured criterias and flush afterwards. - * @param AbstractLogEntry $logEntry + * * @return bool Returns true, if the event was added to log. */ public function logAndFlush(AbstractLogEntry $logEntry): bool { $tmp = $this->log($logEntry); $this->em->flush(); + return $tmp; } @@ -99,12 +103,12 @@ class EventLogger } //Check if the event type is black listed - if (!empty($blacklist) && $this->isObjectClassInArray($logEntry, $blacklist)) { + if (! empty($blacklist) && $this->isObjectClassInArray($logEntry, $blacklist)) { return false; } //Check for whitelisting - if (!empty($whitelist) && !$this->isObjectClassInArray($logEntry, $whitelist)) { + if (! empty($whitelist) && ! $this->isObjectClassInArray($logEntry, $whitelist)) { return false; } @@ -113,15 +117,17 @@ class EventLogger } /** - * Check if the object type is given in the classes array. This also works for inherited types - * @param object $object The object which should be checked - * @param string[] $classes The list of class names that should be used for checking. + * Check if the object type is given in the classes array. This also works for inherited types. + * + * @param object $object The object which should be checked + * @param string[] $classes The list of class names that should be used for checking. + * * @return bool */ protected function isObjectClassInArray(object $object, array $classes): bool { //Check if the class is directly in the classes array - if (in_array(get_class($object), $classes)) { + if (in_array(get_class($object), $classes, true)) { return true; } @@ -134,4 +140,4 @@ class EventLogger return false; } -} \ No newline at end of file +} diff --git a/src/Services/LogSystem/LogEntryExtraFormatter.php b/src/Services/LogSystem/LogEntryExtraFormatter.php index 5934d9e2..c2993422 100644 --- a/src/Services/LogSystem/LogEntryExtraFormatter.php +++ b/src/Services/LogSystem/LogEntryExtraFormatter.php @@ -1,4 +1,7 @@ %s: %s", + '%s: %s', $this->translator->trans('log.user_login.ip'), htmlspecialchars($context->getIPAddress()) ); @@ -113,7 +114,7 @@ class LogEntryExtraFormatter ); } - if ($context instanceof ElementEditedLogEntry && !empty($context->getMessage())) { + if ($context instanceof ElementEditedLogEntry && ! empty($context->getMessage())) { return htmlspecialchars($context->getMessage()); } @@ -123,7 +124,7 @@ class LogEntryExtraFormatter $this->translator->trans($context->isWithdrawal() ? 'log.instock_changed.withdrawal' : 'log.instock_changed.added'), $context->getOldInstock(), $context->getNewInstock(), - (!$context->isWithdrawal() ? '+' : '-') . $context->getDifference(true), + (! $context->isWithdrawal() ? '+' : '-').$context->getDifference(true), $this->translator->trans('log.instock_changed.comment'), htmlspecialchars($context->getComment()) ); @@ -133,6 +134,6 @@ class LogEntryExtraFormatter return htmlspecialchars($context->getMessage()); } - return ""; + return ''; } -} \ No newline at end of file +} diff --git a/src/Services/TranslationExtractor/PermissionExtractor.php b/src/Services/TranslationExtractor/PermissionExtractor.php index daba6c08..a76a1e44 100644 --- a/src/Services/TranslationExtractor/PermissionExtractor.php +++ b/src/Services/TranslationExtractor/PermissionExtractor.php @@ -34,8 +34,8 @@ use Symfony\Component\Translation\MessageCatalogue; */ final class PermissionExtractor implements ExtractorInterface { - protected $permission_structure; - protected $finished = false; + private $permission_structure; + private $finished = false; public function __construct(PermissionResolver $resolver) {