Fixed coding style.

This commit is contained in:
Jan Böhmer 2020-04-10 13:05:08 +02:00
parent a5e1f02d27
commit ae75e6844f
41 changed files with 147 additions and 163 deletions

View file

@ -51,7 +51,6 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;

View file

@ -222,7 +222,7 @@ abstract class BaseAdminController extends AbstractController
protected function _new(Request $request, EntityManagerInterface $em, EntityImporter $importer, ?AbstractNamedDBElement $entity = null)
{
$master_picture_backup = null;
if ($entity === null) {
if (null === $entity) {
/** @var AbstractStructuralDBElement|User $new_entity */
$new_entity = new $this->entity_class();
} else {

View file

@ -45,6 +45,7 @@ namespace App\Controller;
use App\DataTables\LogDataTable;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
@ -52,7 +53,6 @@ use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Orderdetail;
use App\Exceptions\AttachmentDownloadException;
use App\Form\Part\PartBaseType;
use App\Services\Attachments\AttachmentManager;
use App\Services\Attachments\AttachmentSubmitHandler;
use App\Services\Attachments\PartPreviewGenerator;
use App\Services\LogSystem\EventCommentHelper;
@ -62,7 +62,6 @@ use App\Services\Parameters\ParameterExtractor;
use App\Services\PricedetailHelper;
use Doctrine\ORM\EntityManagerInterface;
use Omines\DataTablesBundle\DataTableFactory;
use App\Entity\Parts\Manufacturer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
@ -272,7 +271,6 @@ class PartController extends AbstractController
$new_part->addOrderdetail($orderdetail);
}
$form = $this->createForm(PartBaseType::class, $new_part);
$form->handleRequest($request);

View file

@ -46,7 +46,6 @@ use App\Services\Attachments\BuiltinAttachmentsFinder;
use App\Services\TagFinder;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
@ -62,8 +61,6 @@ class TypeaheadController extends AbstractController
/**
* @Route("/builtInResources/search/{query}", name="typeahead_builtInRessources", requirements={"query"= ".+"})
*
* @param string $query
* @param BuiltinAttachmentsFinder $finder
* @return JsonResponse
*/
public function builtInResources(string $query, BuiltinAttachmentsFinder $finder)

View file

@ -56,7 +56,6 @@ use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Omines\DataTablesBundle\DataTableFactory;
use Symfony\Component\Asset\Packages;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -194,7 +193,6 @@ class UserController extends AdminPages\BaseAdminController
return $table->getResponse();
}
if ($this->getParameter('use_gravatar')) {
$avatar = $this->getGravatar($user->getEmail(), 200, 'identicon');
} else {

View file

@ -52,8 +52,8 @@ use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use InvalidArgumentException;
class DataStructureFixtures extends Fixture

View file

@ -44,8 +44,8 @@ namespace App\DataFixtures;
use App\Entity\UserSystem\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class UserFixtures extends Fixture

View file

@ -106,6 +106,7 @@ class LogDataTable implements DataTableTypeInterface
if (! is_array($value)) {
return [$value];
}
return $value;
});

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).
*
@ -20,7 +23,6 @@
namespace App\Entity\LogSystem;
use App\Entity\Base\AbstractDBElement;
use App\Entity\UserSystem\User;
use App\Events\SecurityEvents;
@ -60,21 +62,23 @@ class SecurityEventLogEntry extends AbstractLogEntry
if (! $element instanceof User) {
throw new \InvalidArgumentException('Target element must be a User object!');
}
return parent::setTargetElement($element);
}
/**
* Sets the type of this log entry.
* @param string $type
*
* @return $this
*/
public function setEventType(string $type): self
{
$key = array_search($type, static::SECURITY_TYPE_MAPPING);
if ($key === false) {
$key = array_search($type, static::SECURITY_TYPE_MAPPING, true);
if (false === $key) {
throw new \InvalidArgumentException('Given event type is not existing!');
}
$this->extra['e'] = $key;
return $this;
}
@ -84,7 +88,8 @@ class SecurityEventLogEntry extends AbstractLogEntry
}
/**
* Return what event this log entry represents (e.g. password_reset)
* Return what event this log entry represents (e.g. password_reset).
*
* @return string
*/
public function getEventType(): string
@ -121,6 +126,7 @@ class SecurityEventLogEntry extends AbstractLogEntry
$ip = IpUtils::anonymize($ip);
}
$this->extra['i'] = $ip;
return $this;
}
}

View file

@ -42,7 +42,6 @@ declare(strict_types=1);
namespace App\Entity\LogSystem;
use App\Exceptions\LogEntryObsoleteException;
use Doctrine\ORM\Mapping as ORM;
/**
@ -62,6 +61,7 @@ class UserNotAllowedLogEntry extends AbstractLogEntry
/**
* Returns the path the user tried to accessed and what was denied.
*
* @return string
*/
public function getPath(): string

View file

@ -306,13 +306,13 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
/**
* Sets the amount of parts in the part lot.
* If null is passed, amount will be set to unknown.
* @param float|null $new_amount
*
* @return $this
*/
public function setAmount(?float $new_amount): self
{
//Treat null like unknown amount
if ($new_amount === null) {
if (null === $new_amount) {
$this->instock_unknown = true;
$new_amount = 0.0;
}

View file

@ -44,9 +44,9 @@ namespace App\Entity\Parts\PartTraits;
use App\Entity\PriceInformations\Orderdetail;
use App\Security\Annotations\ColumnSecurity;
use Doctrine\ORM\Mapping as ORM;
use function count;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* This trait collects all aspects of a part related to orders and priceinformations.

View file

@ -164,11 +164,10 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
*
* You will get the price for $multiplier parts. If you want the price which is stored
* in the database, you have to pass the "price_related_quantity" count as $multiplier.
*
* @param float|string $multiplier The returned price (float or string) will be multiplied
* with this multiplier.
*
* @return null|string the price as a bcmath string
* @return string|null the price as a bcmath string
*/
public function getPricePerUnit($multiplier = 1.0): ?string
{

View file

@ -61,13 +61,16 @@ class U2FKey implements TwoFactorKeyInterface
/**
* We have to restrict the length here, as InnoDB only supports key index with max. 767 Bytes.
* Max length of keyhandles should be 128. (According to U2F_MAX_KH_SIZE in FIDO example C code).
*
* @ORM\Column(type="string", length=128)
*
* @var string
**/
public $keyHandle;
/**
* @ORM\Column(type="string")
*
* @var string
**/
public $publicKey;

View file

@ -87,7 +87,7 @@ class AttachmentDeleteListener
$real_path = $this->pathResolver->placeholderToRealPath($old_path);
//If the attachment does not point to a valid file, ignore it!
if ($real_path === null) {
if (null === $real_path) {
return;
}

View file

@ -67,7 +67,6 @@ use Symfony\Component\Serializer\SerializerInterface;
/**
* This event subscriber write to event log when entities are changed, removed, created.
* @package App\EventSubscriber\LogSystem
*/
class EventLoggerSubscriber implements EventSubscriber
{

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).
*
@ -20,7 +23,6 @@
namespace App\EventSubscriber\LogSystem;
use App\Entity\LogSystem\UserNotAllowedLogEntry;
use App\Services\LogSystem\EventLogger;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -30,7 +32,6 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
/**
* Write to event log when a user tries to access an forbidden page and recevies an 403 Access Denied message.
* @package App\EventSubscriber\LogSystem
*/
class LogAccessDeniedSubscriber implements EventSubscriberInterface
{
@ -41,7 +42,7 @@ class LogAccessDeniedSubscriber implements EventSubscriberInterface
$this->logger = $logger;
}
public function onKernelException(ExceptionEvent $event)
public function onKernelException(ExceptionEvent $event): void
{
$throwable = $event->getThrowable();
if ($throwable instanceof AccessDeniedHttpException) {
@ -57,9 +58,6 @@ class LogAccessDeniedSubscriber implements EventSubscriberInterface
$this->logger->logAndFlush($log_entry);
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return ['kernel.exception' => 'onKernelException'];

View file

@ -50,7 +50,6 @@ use Doctrine\Migrations\Events;
/**
* This subscriber logs databaseMigrations to Event log.
* @package App\EventSubscriber
*/
class LogDBMigrationSubscriber implements EventSubscriber
{

View file

@ -52,7 +52,6 @@ use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
/**
* This handler logs to event log, if a user logs out.
* @package App\EventSubscriber\LogSystem
*/
class LogoutLoggerHandler implements LogoutHandlerInterface
{

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).
*
@ -20,22 +23,18 @@
namespace App\EventSubscriber\LogSystem;
use App\Entity\LogSystem\SecurityEventLogEntry;
use App\Events\SecurityEvent;
use App\Events\SecurityEvents;
use App\Services\LogSystem\EventLogger;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* This subscriber writes entries to log if an security related event happens (e.g. the user changes its password).
* @package App\EventSubscriber\LogSystem
*/
final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
{
private $requestStack;
private $gpdr_compliant;
private $eventLogger;
@ -47,27 +46,6 @@ final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
$this->eventLogger = $eventLogger;
}
protected function addLog(string $type, SecurityEvent $event): void
{
$anonymize = $this->gpdr_compliant;
$request = $this->requestStack->getCurrentRequest();
if ($request !== null) {
$ip = $request->getClientIp() ?? 'unknown';
} else {
$ip = "Console";
//Dont try to apply IP filter rules to non numeric string
$anonymize = false;
}
$log = new SecurityEventLogEntry($type, $ip, $anonymize);
$log->setTargetElement($event->getTargetUser());
$this->eventLogger->logAndFlush($log);
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return [
@ -127,4 +105,22 @@ final class SecurityEventLoggerSubscriber implements EventSubscriberInterface
{
$this->addLog(SecurityEvents::TRUSTED_DEVICE_RESET, $event);
}
private function addLog(string $type, SecurityEvent $event): void
{
$anonymize = $this->gpdr_compliant;
$request = $this->requestStack->getCurrentRequest();
if (null !== $request) {
$ip = $request->getClientIp() ?? 'unknown';
} else {
$ip = 'Console';
//Dont try to apply IP filter rules to non numeric string
$anonymize = false;
}
$log = new SecurityEventLogEntry($type, $ip, $anonymize);
$log->setTargetElement($event->getTargetUser());
$this->eventLogger->logAndFlush($log);
}
}

View file

@ -49,7 +49,6 @@ use Symfony\Component\Mime\Email;
/**
* This subscriber set the "From" field for all sent email, based on the global configured sender name and email.
* @package App\EventSubscriber
*/
final class SetMailFromSubscriber implements EventSubscriberInterface
{

View file

@ -42,14 +42,11 @@ declare(strict_types=1);
namespace App\EventSubscriber;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
/**
* This subscriber sets an Header in Debug mode that signals the Symfony Profiler to also update on Ajax requests.
* @package App\EventSubscriber
*/
final class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
{

View file

@ -53,7 +53,6 @@ use Symfony\Component\Security\Core\Security;
/**
* This subscriber is used to log out a disabled user, as soon as he to do an request.
* It is not possible for him to login again, afterwards.
* @package App\EventSubscriber\UserSystem
*/
final class LogoutDisabledUserSubscriber implements EventSubscriberInterface
{

View file

@ -57,7 +57,6 @@ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
/**
* This subscriber is used to write U2F keys to DB, after user added them via GUI.
* @package App\EventSubscriber\UserSystem
*/
final class RegisterU2FSubscriber implements EventSubscriberInterface
{

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).
*
@ -20,14 +23,12 @@
namespace App\Events;
use App\Entity\UserSystem\User;
use Symfony\Contracts\EventDispatcher\Event;
/**
* This event is triggered when something security related to a user happens.
* For example when the password is reset or the an two factor authentication method was disabled.
* @package App\Events
*/
class SecurityEvent extends Event
{
@ -41,6 +42,7 @@ class SecurityEvent extends Event
/**
* Returns the affected user.
*
* @return User
*/
public function getTargetUser()

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).
*
@ -20,7 +23,6 @@
namespace App\Events;
class SecurityEvents
{
public const PASSWORD_CHANGED = 'security.password_changed';

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).
*
@ -20,7 +23,6 @@
namespace App\Form;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Form\AbstractTypeExtension;
@ -39,7 +41,6 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
* This prevents issues when the collection that is edited uses a OrderBy annotation and therefore the direction of the
* elements can change during requests.
* Must me enabled by setting reindex_enable to true in Type options.
* @package App\Form
*/
class CollectionTypeExtension extends AbstractTypeExtension
{
@ -55,7 +56,7 @@ class CollectionTypeExtension extends AbstractTypeExtension
return [CollectionType::class];
}
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
/*$resolver->setDefault('error_mapping', function (Options $options) {
$options->
@ -72,9 +73,9 @@ class CollectionTypeExtension extends AbstractTypeExtension
$resolver->setAllowedTypes('reindex_path', 'string');
}
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) {
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options): void {
$data = $event->getData();
$config = $event->getForm()->getConfig();
//If enabled do a reindexing of the collection
@ -86,7 +87,7 @@ class CollectionTypeExtension extends AbstractTypeExtension
foreach ($data->toArray() as $key => $item) {
$id = $this->propertyAccess->getValue($item, $options['reindex_path']);
//If element has an ID then use it. otherwise use default key
$index = $id === null ? $key : $options['reindex_prefix'] . $id;
$index = null === $id ? $key : $options['reindex_prefix'].$id;
$error_mapping['['.$key.']'] = $index;
$reindexed_data->set($index, $item);
}
@ -103,9 +104,7 @@ class CollectionTypeExtension extends AbstractTypeExtension
/**
* Set the option of the form.
* This a bit hacky cause we access private properties....
* @param FormBuilder $builder
* @param string $option
* @param mixed $value
*
* @throws \ReflectionException
*/
public function setOption(FormBuilder $builder, string $option, $value): void

View file

@ -45,9 +45,6 @@ namespace App\Form\Type;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Contracts\HasMasterAttachmentInterface;
use Doctrine\ORM\EntityRepository;
use ReflectionClass;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -88,9 +85,10 @@ class MasterPictureAttachmentType extends AbstractType
if (! $entity instanceof AttachmentContainingDBElement) {
throw new \RuntimeException('$entity must have Attachments! (be of type AttachmentContainingDBElement)');
}
return $entity->getAttachments()->toArray();
});
}
},
]);
$resolver->setAllowedValues('filter', ['', 'picture', '3d_model']);

View file

@ -20,7 +20,7 @@ final class Version20200409130946 extends AbstractMigration
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE u2f_keys CHANGE key_handle key_handle VARCHAR(128) NOT NULL');
}
@ -28,7 +28,7 @@ final class Version20200409130946 extends AbstractMigration
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 u2f_keys CHANGE key_handle key_handle VARCHAR(64) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`');
}

View file

@ -52,7 +52,6 @@ use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\User;
use function get_class;
use function is_object;

View file

@ -43,10 +43,10 @@ declare(strict_types=1);
namespace App\Services\Attachments;
use App\Entity\Attachments\Attachment;
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\Finder\Finder;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Cache\CacheInterface;
use Psr\Cache\InvalidArgumentException;
/**
* This service is used to find builtin attachment ressources.

View file

@ -44,7 +44,6 @@ namespace App\Services;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Devices\Device;
use App\Entity\Parameters\AbstractParameter;

View file

@ -94,7 +94,7 @@ class EntityURLGenerator
* @param mixed $entity The element for which the page should be generated
* @param string $type The page type. Currently supported: 'info', 'edit', 'create', 'clone', 'list'/'list_parts'
*
* @return null|string the link to the desired page
* @return string|null the link to the desired page
*
* @throws EntityNotSupportedException thrown if the entity is not supported for the given type
* @throws InvalidArgumentException thrown if the givent type is not existing

View file

@ -49,7 +49,6 @@ use App\Security\Interfaces\HasPermissionsInterface;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Yaml\Yaml;
class PermissionResolver

View file

@ -176,7 +176,7 @@ class PricedetailHelper
$converted = $this->convertMoneyToCurrency($pricedetail->getPricePerUnit(), $pricedetail->getCurrency(), $currency);
//Ignore price informations that can not be converted to base currency.
if ($converted !== null) {
if (null !== $converted) {
$avg = bcadd($avg, $converted, Pricedetail::PRICE_PRECISION);
++$count;
}