Fixed coding style.

This commit is contained in:
Jan Böhmer 2020-02-01 16:17:20 +01:00
parent 0a94689d98
commit f2ff77a8b3
44 changed files with 435 additions and 387 deletions

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -21,7 +24,6 @@
namespace App\Services\LogSystem;
use App\Entity\LogSystem\AbstractLogEntry;
use App\Entity\UserSystem\User;
use Doctrine\ORM\EntityManagerInterface;
@ -47,15 +49,15 @@ class EventLogger
/**
* Adds the given log entry to the Log, if the entry fullfills the global configured criterias.
* The change will not be flushed yet.
* @param AbstractLogEntry $logEntry
*
* @return bool Returns true, if the event was added to log.
*/
public function log(AbstractLogEntry $logEntry): bool
{
$user = $this->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;
}
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -21,7 +24,6 @@
namespace App\Services\LogSystem;
use App\Entity\LogSystem\AbstractLogEntry;
use App\Entity\LogSystem\DatabaseUpdatedLogEntry;
use App\Entity\LogSystem\ElementCreatedLogEntry;
@ -36,7 +38,6 @@ use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Format the Extra field of a log entry in a user readible form.
* @package App\Services\LogSystem
*/
class LogEntryExtraFormatter
{
@ -49,7 +50,7 @@ class LogEntryExtraFormatter
/**
* Return an user viewable representation of the extra data in a log entry, styled for console output.
* @param AbstractLogEntry $logEntry
*
* @return string
*/
public function formatConsole(AbstractLogEntry $logEntry): string
@ -64,15 +65,15 @@ class LogEntryExtraFormatter
}
/**
* Return a HTML formatted string containing a user viewable form of the Extra data
* @param AbstractLogEntry $context
* Return a HTML formatted string containing a user viewable form of the Extra data.
*
* @return string
*/
public function format(AbstractLogEntry $context): string
{
if ($context instanceof UserLoginLogEntry || $context instanceof UserLogoutLogEntry) {
return sprintf(
"<i>%s</i>: %s",
'<i>%s</i>: %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 '';
}
}
}