Applied code style rules to src/

This commit is contained in:
Jan Böhmer 2020-01-05 15:46:58 +01:00
parent 700c049d26
commit f861de791f
186 changed files with 1462 additions and 1059 deletions

View file

@ -6,5 +6,5 @@ parameters:
- "clean-code" - "clean-code"
- "common" - "common"
# very nice to have ↓ # very nice to have ↓
- "symplify" #- "symplify"
- "symfony" - "symfony"

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -51,7 +54,7 @@ class CleanAttachmentsCommand extends Command
parent::__construct(); parent::__construct();
} }
protected function configure() protected function configure(): void
{ {
$this $this
->setDescription('Lists (and deletes if wanted) attachments files that are not used anymore (abandoned files).') ->setDescription('Lists (and deletes if wanted) attachments files that are not used anymore (abandoned files).')
@ -59,7 +62,7 @@ class CleanAttachmentsCommand extends Command
' These files are not needed and can eventually deleted.'); ' These files are not needed and can eventually deleted.');
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output): void
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
@ -84,7 +87,7 @@ class CleanAttachmentsCommand extends Command
foreach ($finder as $file) { foreach ($finder as $file) {
//If not attachment object uses this file, print it //If not attachment object uses this file, print it
if (0 == \count($this->reverseSearch->findAttachmentsByFile($file))) { if (0 === \count($this->reverseSearch->findAttachmentsByFile($file))) {
$file_list[] = $file; $file_list[] = $file;
$table->addRow([ $table->addRow([
$fs->makePathRelative($file->getPathname(), $mediaPath), $fs->makePathRelative($file->getPathname(), $mediaPath),
@ -99,7 +102,7 @@ class CleanAttachmentsCommand extends Command
$continue = $io->confirm(sprintf('Found %d abandoned files. Do you want to delete them? This can not be undone!', \count($file_list)), false); $continue = $io->confirm(sprintf('Found %d abandoned files. Do you want to delete them? This can not be undone!', \count($file_list)), false);
if (!$continue) { if (! $continue) {
//We are finished here, when no files should be deleted //We are finished here, when no files should be deleted
return; return;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -67,7 +70,7 @@ class ConvertBBCodeCommand extends Command
parent::__construct(); parent::__construct();
} }
protected function configure() protected function configure(): void
{ {
$this $this
->setDescription('Converts BBCode used in old Part-DB versions to newly used Markdown') ->setDescription('Converts BBCode used in old Part-DB versions to newly used Markdown')
@ -97,7 +100,7 @@ class ConvertBBCodeCommand extends Command
]; ];
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output): void
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
$targets = $this->getTargetsLists(); $targets = $this->getTargetsLists();
@ -126,7 +129,7 @@ class ConvertBBCodeCommand extends Command
//In verbose mode print the names of the entities //In verbose mode print the names of the entities
foreach ($results as $result) { foreach ($results as $result) {
/* @var NamedDBElement $result */ /** @var NamedDBElement $result */
$io->writeln( $io->writeln(
'Convert entity: '.$result->getName().' ('.$result->getIDString().')', 'Convert entity: '.$result->getName().' ('.$result->getIDString().')',
OutputInterface::VERBOSITY_VERBOSE OutputInterface::VERBOSITY_VERBOSE
@ -135,7 +138,7 @@ class ConvertBBCodeCommand extends Command
//Retrieve bbcode from entity //Retrieve bbcode from entity
$bbcode = $this->propertyAccessor->getValue($result, $property); $bbcode = $this->propertyAccessor->getValue($result, $property);
//Check if the current property really contains BBCode //Check if the current property really contains BBCode
if (!preg_match(static::BBCODE_REGEX, $bbcode)) { if (! preg_match(static::BBCODE_REGEX, $bbcode)) {
continue; continue;
} }
$io->writeln( $io->writeln(
@ -156,7 +159,7 @@ class ConvertBBCodeCommand extends Command
} }
//If we are not in dry run, save changes to DB //If we are not in dry run, save changes to DB
if (!$input->getOption('dry-run')) { if (! $input->getOption('dry-run')) {
$this->em->flush(); $this->em->flush();
$io->success('Changes saved to DB successfully!'); $io->success('Changes saved to DB successfully!');
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -45,7 +48,7 @@ class SetPasswordCommand extends Command
parent::__construct(); parent::__construct();
} }
protected function configure() protected function configure(): void
{ {
$this $this
->setDescription('Sets the password of a user') ->setDescription('Sets the password of a user')
@ -54,18 +57,16 @@ class SetPasswordCommand extends Command
; ;
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output): void
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
$user_name = $input->getArgument('user'); $user_name = $input->getArgument('user');
/** /** @var User */
* @var User
*/
$users = $this->entityManager->getRepository(User::class)->findBy(['name' => $user_name]); $users = $this->entityManager->getRepository(User::class)->findBy(['name' => $user_name]);
$user = $users[0]; $user = $users[0];
if (null == $user) { if (null === $user) {
$io->error(sprintf('No user with the given username %s found in the database!', $user_name)); $io->error(sprintf('No user with the given username %s found in the database!', $user_name));
return; return;
@ -77,14 +78,14 @@ class SetPasswordCommand extends Command
sprintf('You are going to change the password of %s with ID %d. Proceed?', sprintf('You are going to change the password of %s with ID %d. Proceed?',
$user->getFullName(true), $user->getID())); $user->getFullName(true), $user->getID()));
if (!$proceed) { if (! $proceed) {
return; return;
} }
$success = false; $success = false;
$new_password = ''; $new_password = '';
while (!$success) { while (! $success) {
$pw1 = $io->askHidden('Please enter new password:'); $pw1 = $io->askHidden('Please enter new password:');
$pw2 = $io->askHidden('Please confirm:'); $pw2 = $io->askHidden('Please confirm:');
if ($pw1 !== $pw2) { if ($pw1 !== $pw2) {

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -49,7 +52,7 @@ class UpdateExchangeRatesCommand extends Command
parent::__construct(); parent::__construct();
} }
protected function configure() protected function configure(): void
{ {
$this $this
->setDescription('Updates the currency exchange rates.') ->setDescription('Updates the currency exchange rates.')
@ -62,7 +65,7 @@ class UpdateExchangeRatesCommand extends Command
null); null);
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output): void
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
@ -88,7 +91,7 @@ class UpdateExchangeRatesCommand extends Command
$repo = $this->em->getRepository(Currency::class); $repo = $this->em->getRepository(Currency::class);
$candidates = []; $candidates = [];
if (!empty($iso_code)) { if (! empty($iso_code)) {
$candidates = $repo->findBy(['iso_code' => $iso_code]); $candidates = $repo->findBy(['iso_code' => $iso_code]);
} else { } else {
$candidates = $repo->findAll(); $candidates = $repo->findAll();

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -80,7 +83,7 @@ abstract class BaseAdminController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
//Check if we editing a user and if we need to change the password of it //Check if we editing a user and if we need to change the password of it
if ($entity instanceof User && !empty($form['new_password']->getData())) { if ($entity instanceof User && ! empty($form['new_password']->getData())) {
$password = $this->passwordEncoder->encodePassword($entity, $form['new_password']->getData()); $password = $this->passwordEncoder->encodePassword($entity, $form['new_password']->getData());
$entity->setPassword($password); $entity->setPassword($password);
//By default the user must change the password afterwards //By default the user must change the password afterwards
@ -90,11 +93,12 @@ abstract class BaseAdminController extends AbstractController
//Upload passed files //Upload passed files
$attachments = $form['attachments']; $attachments = $form['attachments'];
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
/** @var $attachment FormInterface */ /** @var FormInterface $attachment */
$options = [ $options = [
'secure_attachment' => $attachment['secureFile']->getData(), 'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->getData(), 'download_url' => $attachment['downloadURL']->getData(),
]; ];
try { try {
$this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); $this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
} catch (AttachmentDownloadException $ex) { } catch (AttachmentDownloadException $ex) {
@ -112,7 +116,7 @@ abstract class BaseAdminController extends AbstractController
//Rebuild form, so it is based on the updated data. Important for the parent field! //Rebuild form, so it is based on the updated data. Important for the parent field!
//We can not use dynamic form events here, because the parent entity list is build from database! //We can not use dynamic form events here, because the parent entity list is build from database!
$form = $this->createForm($this->form_class, $entity, ['attachment_class' => $this->attachment_class]); $form = $this->createForm($this->form_class, $entity, ['attachment_class' => $this->attachment_class]);
} elseif ($form->isSubmitted() && !$form->isValid()) { } elseif ($form->isSubmitted() && ! $form->isValid()) {
$this->addFlash('error', 'entity.edit_flash.invalid'); $this->addFlash('error', 'entity.edit_flash.invalid');
} }
@ -136,7 +140,7 @@ abstract class BaseAdminController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
if ($new_entity instanceof User && !empty($form['new_password']->getData())) { if ($new_entity instanceof User && ! empty($form['new_password']->getData())) {
$password = $this->passwordEncoder->encodePassword($new_entity, $form['new_password']->getData()); $password = $this->passwordEncoder->encodePassword($new_entity, $form['new_password']->getData());
$new_entity->setPassword($password); $new_entity->setPassword($password);
//By default the user must change the password afterwards //By default the user must change the password afterwards
@ -146,11 +150,12 @@ abstract class BaseAdminController extends AbstractController
//Upload passed files //Upload passed files
$attachments = $form['attachments']; $attachments = $form['attachments'];
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
/** @var $attachment FormInterface */ /** @var FormInterface $attachment */
$options = [ $options = [
'secure_attachment' => $attachment['secureFile']->getData(), 'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->getData(), 'download_url' => $attachment['downloadURL']->getData(),
]; ];
try { try {
$this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); $this->attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
} catch (AttachmentDownloadException $ex) { } catch (AttachmentDownloadException $ex) {
@ -168,7 +173,7 @@ abstract class BaseAdminController extends AbstractController
return $this->redirectToRoute($this->route_base.'_edit', ['id' => $new_entity->getID()]); return $this->redirectToRoute($this->route_base.'_edit', ['id' => $new_entity->getID()]);
} }
if ($form->isSubmitted() && !$form->isValid()) { if ($form->isSubmitted() && ! $form->isValid()) {
$this->addFlash('error', 'entity.created_flash.invalid'); $this->addFlash('error', 'entity.created_flash.invalid');
} }
@ -187,7 +192,7 @@ abstract class BaseAdminController extends AbstractController
$errors = $importer->fileToDBEntities($file, $this->entity_class, $options); $errors = $importer->fileToDBEntities($file, $this->entity_class, $options);
foreach ($errors as $name => $error) { foreach ($errors as $name => $error) {
/* @var $error ConstraintViolationList */ /** @var ConstraintViolationList $error */
$this->addFlash('error', $name.':'.$error); $this->addFlash('error', $name.':'.$error);
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -32,7 +35,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
/** /**
* @Route("/footprint") * @Route("/footprint")
@ -76,8 +78,6 @@ class FootprintController extends BaseAdminController
/** /**
* @Route("/export", name="footprint_export_all") * @Route("/export", name="footprint_export_all")
* *
* @param SerializerInterface $serializer
*
* @return Response * @return Response
*/ */
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request) public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -32,7 +35,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
/** /**
* @Route("/manufacturer") * @Route("/manufacturer")
@ -76,8 +78,6 @@ class ManufacturerController extends BaseAdminController
/** /**
* @Route("/export", name="manufacturer_export_all") * @Route("/export", name="manufacturer_export_all")
* *
* @param SerializerInterface $serializer
*
* @return Response * @return Response
*/ */
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request) public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -32,7 +35,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
/** /**
* @Route("/measurement_unit") * @Route("/measurement_unit")
@ -76,8 +78,6 @@ class MeasurementUnitController extends BaseAdminController
/** /**
* @Route("/export", name="measurement_unit_export_all") * @Route("/export", name="measurement_unit_export_all")
* *
* @param SerializerInterface $serializer
*
* @return Response * @return Response
*/ */
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request) public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,7 +34,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
/** /**
* @Route("/store_location") * @Route("/store_location")
@ -75,8 +77,6 @@ class StorelocationController extends BaseAdminController
/** /**
* @Route("/export", name="store_location_export_all") * @Route("/export", name="store_location_export_all")
* *
* @param SerializerInterface $serializer
*
* @return Response * @return Response
*/ */
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request) public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,7 +34,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
/** /**
* @Route("/supplier") * @Route("/supplier")
@ -75,8 +77,6 @@ class SupplierController extends BaseAdminController
/** /**
* @Route("/export", name="supplier_export_all") * @Route("/export", name="supplier_export_all")
* *
* @param SerializerInterface $serializer
*
* @return Response * @return Response
*/ */
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request) public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -49,7 +52,7 @@ class AttachmentFileController extends AbstractController
throw new \RuntimeException('You can not download external attachments!'); throw new \RuntimeException('You can not download external attachments!');
} }
if (!$helper->isFileExisting($attachment)) { if (! $helper->isFileExisting($attachment)) {
throw new \RuntimeException('The file associated with the attachment is not existing!'); throw new \RuntimeException('The file associated with the attachment is not existing!');
} }
@ -79,7 +82,7 @@ class AttachmentFileController extends AbstractController
throw new \RuntimeException('You can not download external attachments!'); throw new \RuntimeException('You can not download external attachments!');
} }
if (!$helper->isFileExisting($attachment)) { if (! $helper->isFileExisting($attachment)) {
throw new \RuntimeException('The file associated with the attachment is not existing!'); throw new \RuntimeException('The file associated with the attachment is not existing!');
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -80,11 +82,12 @@ class PartController extends AbstractController
//Upload passed files //Upload passed files
$attachments = $form['attachments']; $attachments = $form['attachments'];
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
/** @var $attachment FormInterface */ /** @var FormInterface $attachment */
$options = [ $options = [
'secure_attachment' => $attachment['secureFile']->getData(), 'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->getData(), 'download_url' => $attachment['downloadURL']->getData(),
]; ];
try { try {
$attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); $attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
} catch (AttachmentDownloadException $ex) { } catch (AttachmentDownloadException $ex) {
@ -100,7 +103,7 @@ class PartController extends AbstractController
$this->addFlash('info', 'part.edited_flash'); $this->addFlash('info', 'part.edited_flash');
//Reload form, so the SIUnitType entries use the new part unit //Reload form, so the SIUnitType entries use the new part unit
$form = $this->createForm(PartBaseType::class, $part); $form = $this->createForm(PartBaseType::class, $part);
} elseif ($form->isSubmitted() && !$form->isValid()) { } elseif ($form->isSubmitted() && ! $form->isValid()) {
$this->addFlash('error', 'part.edited_flash.invalid'); $this->addFlash('error', 'part.edited_flash.invalid');
} }
@ -163,11 +166,12 @@ class PartController extends AbstractController
//Upload passed files //Upload passed files
$attachments = $form['attachments']; $attachments = $form['attachments'];
foreach ($attachments as $attachment) { foreach ($attachments as $attachment) {
/** @var $attachment FormInterface */ /** @var FormInterface $attachment */
$options = [ $options = [
'secure_attachment' => $attachment['secureFile']->getData(), 'secure_attachment' => $attachment['secureFile']->getData(),
'download_url' => $attachment['downloadURL']->getData(), 'download_url' => $attachment['downloadURL']->getData(),
]; ];
try { try {
$attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options); $attachmentSubmitHandler->handleFormSubmit($attachment->getData(), $attachment['file']->getData(), $options);
} catch (AttachmentDownloadException $ex) { } catch (AttachmentDownloadException $ex) {
@ -185,7 +189,7 @@ class PartController extends AbstractController
return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]); return $this->redirectToRoute('part_edit', ['id' => $new_part->getID()]);
} }
if ($form->isSubmitted() && !$form->isValid()) { if ($form->isSubmitted() && ! $form->isValid()) {
$this->addFlash('error', 'part.created_flash.invalid'); $this->addFlash('error', 'part.created_flash.invalid');
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -37,8 +40,6 @@ class PartListsController extends AbstractController
/** /**
* @Route("/category/{id}/parts", name="part_list_category") * @Route("/category/{id}/parts", name="part_list_category")
* *
* @param $id int The id of the category
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/ */
public function showCategory(Category $category, Request $request, DataTableFactory $dataTable) public function showCategory(Category $category, Request $request, DataTableFactory $dataTable)
@ -59,8 +60,6 @@ class PartListsController extends AbstractController
/** /**
* @Route("/footprint/{id}/parts", name="part_list_footprint") * @Route("/footprint/{id}/parts", name="part_list_footprint")
* *
* @param $id int The id of the category
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/ */
public function showFootprint(Footprint $footprint, Request $request, DataTableFactory $dataTable) public function showFootprint(Footprint $footprint, Request $request, DataTableFactory $dataTable)
@ -81,8 +80,6 @@ class PartListsController extends AbstractController
/** /**
* @Route("/manufacturer/{id}/parts", name="part_list_manufacturer") * @Route("/manufacturer/{id}/parts", name="part_list_manufacturer")
* *
* @param $id int The id of the category
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/ */
public function showManufacturer(Manufacturer $manufacturer, Request $request, DataTableFactory $dataTable) public function showManufacturer(Manufacturer $manufacturer, Request $request, DataTableFactory $dataTable)
@ -103,8 +100,6 @@ class PartListsController extends AbstractController
/** /**
* @Route("/store_location/{id}/parts", name="part_list_store_location") * @Route("/store_location/{id}/parts", name="part_list_store_location")
* *
* @param $id int The id of the category
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/ */
public function showStorelocation(Storelocation $storelocation, Request $request, DataTableFactory $dataTable) public function showStorelocation(Storelocation $storelocation, Request $request, DataTableFactory $dataTable)
@ -125,8 +120,6 @@ class PartListsController extends AbstractController
/** /**
* @Route("/supplier/{id}/parts", name="part_list_supplier") * @Route("/supplier/{id}/parts", name="part_list_supplier")
* *
* @param $id int The id of the category
*
* @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\Response
*/ */
public function showSupplier(Supplier $supplier, Request $request, DataTableFactory $dataTable) public function showSupplier(Supplier $supplier, Request $request, DataTableFactory $dataTable)

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -55,7 +58,7 @@ class RedirectController extends AbstractController
//Check if a user has set a preferred language setting: //Check if a user has set a preferred language setting:
$user = $this->getUser(); $user = $this->getUser();
if (($user instanceof User) && !empty($user->getLanguage())) { if (($user instanceof User) && ! empty($user->getLanguage())) {
$locale = $user->getLanguage(); $locale = $user->getLanguage();
} }
@ -63,7 +66,7 @@ class RedirectController extends AbstractController
$new_url = $request->getUriForPath('/'.$locale.$request->getPathInfo()); $new_url = $request->getUriForPath('/'.$locale.$request->getPathInfo());
//If either mod_rewrite is not enabled or the index.php version is enforced, add index.php to the string //If either mod_rewrite is not enabled or the index.php version is enforced, add index.php to the string
if (($this->enforce_index_php || !$this->checkIfModRewriteAvailable()) if (($this->enforce_index_php || ! $this->checkIfModRewriteAvailable())
&& false === strpos($new_url, 'index.php')) { && false === strpos($new_url, 'index.php')) {
//Like Request::getUriForPath only with index.php //Like Request::getUriForPath only with index.php
$new_url = $request->getSchemeAndHttpHost().$request->getBaseUrl().'/index.php/'.$locale.$request->getPathInfo(); $new_url = $request->getSchemeAndHttpHost().$request->getBaseUrl().'/index.php/'.$locale.$request->getPathInfo();
@ -81,7 +84,7 @@ class RedirectController extends AbstractController
*/ */
public function checkIfModRewriteAvailable() public function checkIfModRewriteAvailable()
{ {
if (!\function_exists('apache_get_modules')) { if (! \function_exists('apache_get_modules')) {
//If we can not check for apache modules, we just hope for the best and assume url rewriting is available //If we can not check for apache modules, we just hope for the best and assume url rewriting is available
//If you want to enforce index.php versions of the url, you can override this via ENV vars. //If you want to enforce index.php versions of the url, you can override this via ENV vars.
return true; return true;

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -69,7 +72,7 @@ class SecurityController extends AbstractController
*/ */
public function requestPwReset(PasswordResetManager $passwordReset, Request $request) public function requestPwReset(PasswordResetManager $passwordReset, Request $request)
{ {
if (!$this->allow_email_pw_reset) { if (! $this->allow_email_pw_reset) {
throw new AccessDeniedHttpException('The password reset via email is disabled!'); throw new AccessDeniedHttpException('The password reset via email is disabled!');
} }
@ -109,9 +112,9 @@ class SecurityController extends AbstractController
/** /**
* @Route("/pw_reset/new_pw/{user}/{token}", name="pw_reset_new_pw") * @Route("/pw_reset/new_pw/{user}/{token}", name="pw_reset_new_pw")
*/ */
public function pwResetNewPw(PasswordResetManager $passwordReset, Request $request, string $user = null, string $token = null) public function pwResetNewPw(PasswordResetManager $passwordReset, Request $request, ?string $user = null, ?string $token = null)
{ {
if (!$this->allow_email_pw_reset) { if (! $this->allow_email_pw_reset) {
throw new AccessDeniedHttpException('The password reset via email is disabled!'); throw new AccessDeniedHttpException('The password reset via email is disabled!');
} }
@ -149,7 +152,7 @@ class SecurityController extends AbstractController
$data = $form->getData(); $data = $form->getData();
//Try to set the new password //Try to set the new password
$success = $passwordReset->setNewPassword($data['username'], $data['token'], $data['new_password']); $success = $passwordReset->setNewPassword($data['username'], $data['token'], $data['new_password']);
if (!$success) { if (! $success) {
$this->addFlash('error', 'pw_reset.new_pw.error'); $this->addFlash('error', 'pw_reset.new_pw.error');
} else { } else {
$this->addFlash('success', 'pw_reset.new_pw.success'); $this->addFlash('success', 'pw_reset.new_pw.success');
@ -166,7 +169,7 @@ class SecurityController extends AbstractController
/** /**
* @Route("/logout", name="logout") * @Route("/logout", name="logout")
*/ */
public function logout() public function logout(): void
{ {
throw new \RuntimeException('Will be intercepted before getting here'); throw new \RuntimeException('Will be intercepted before getting here');
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -61,7 +64,7 @@ class TreeController extends AbstractController
* @Route("/category/{id}", name="tree_category") * @Route("/category/{id}", name="tree_category")
* @Route("/categories") * @Route("/categories")
*/ */
public function categoryTree(Category $category = null) public function categoryTree(?Category $category = null)
{ {
$tree = $this->treeGenerator->getTreeView(Category::class, $category); $tree = $this->treeGenerator->getTreeView(Category::class, $category);
@ -72,7 +75,7 @@ class TreeController extends AbstractController
* @Route("/footprint/{id}", name="tree_footprint") * @Route("/footprint/{id}", name="tree_footprint")
* @Route("/footprints") * @Route("/footprints")
*/ */
public function footprintTree(Footprint $footprint = null) public function footprintTree(?Footprint $footprint = null)
{ {
$tree = $this->treeGenerator->getTreeView(Footprint::class, $footprint); $tree = $this->treeGenerator->getTreeView(Footprint::class, $footprint);
@ -83,7 +86,7 @@ class TreeController extends AbstractController
* @Route("/location/{id}", name="tree_location") * @Route("/location/{id}", name="tree_location")
* @Route("/locations") * @Route("/locations")
*/ */
public function locationTree(Storelocation $location = null) public function locationTree(?Storelocation $location = null)
{ {
$tree = $this->treeGenerator->getTreeView(Storelocation::class, $location); $tree = $this->treeGenerator->getTreeView(Storelocation::class, $location);
@ -94,7 +97,7 @@ class TreeController extends AbstractController
* @Route("/manufacturer/{id}", name="tree_manufacturer") * @Route("/manufacturer/{id}", name="tree_manufacturer")
* @Route("/manufacturers") * @Route("/manufacturers")
*/ */
public function manufacturerTree(Manufacturer $manufacturer = null) public function manufacturerTree(?Manufacturer $manufacturer = null)
{ {
$tree = $this->treeGenerator->getTreeView(Manufacturer::class, $manufacturer); $tree = $this->treeGenerator->getTreeView(Manufacturer::class, $manufacturer);
@ -105,7 +108,7 @@ class TreeController extends AbstractController
* @Route("/supplier/{id}", name="tree_supplier") * @Route("/supplier/{id}", name="tree_supplier")
* @Route("/suppliers") * @Route("/suppliers")
*/ */
public function supplierTree(Supplier $supplier = null) public function supplierTree(?Supplier $supplier = null)
{ {
$tree = $this->treeGenerator->getTreeView(Supplier::class, $supplier); $tree = $this->treeGenerator->getTreeView(Supplier::class, $supplier);
@ -116,7 +119,7 @@ class TreeController extends AbstractController
* @Route("/device/{id}", name="tree_device") * @Route("/device/{id}", name="tree_device")
* @Route("/devices") * @Route("/devices")
*/ */
public function deviceTree(Device $device = null) public function deviceTree(?Device $device = null)
{ {
$tree = $this->treeGenerator->getTreeView(Device::class, $device, ''); $tree = $this->treeGenerator->getTreeView(Device::class, $device, '');

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -34,7 +37,6 @@ use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
/** /**
* @Route("/user") * @Route("/user")
@ -106,8 +108,6 @@ class UserController extends AdminPages\BaseAdminController
/** /**
* @Route("/export", name="user_export_all") * @Route("/export", name="user_export_all")
* *
* @param SerializerInterface $serializer
*
* @return Response * @return Response
*/ */
public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request) public function exportAll(EntityManagerInterface $em, EntityExporter $exporter, Request $request)
@ -183,7 +183,7 @@ class UserController extends AdminPages\BaseAdminController
$url = 'https://www.gravatar.com/avatar/'; $url = 'https://www.gravatar.com/avatar/';
$url .= md5(strtolower(trim($email))); $url .= md5(strtolower(trim($email)));
$url .= "?s=$s&d=$d&r=$r"; $url .= "?s=${s}&d=${d}&r=${r}";
if ($img) { if ($img) {
$url = '<img src="'.$url.'"'; $url = '<img src="'.$url.'"';
foreach ($atts as $key => $val) { foreach ($atts as $key => $val) {

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -61,12 +64,13 @@ class UserSettingsController extends AbstractController
//When user change its settings, he should be logged in fully. //When user change its settings, he should be logged in fully.
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
if (!$user instanceof User) { if (! $user instanceof User) {
return new \RuntimeException('This controller only works only for Part-DB User objects!'); return new \RuntimeException('This controller only works only for Part-DB User objects!');
} }
if (empty($user->getBackupCodes())) { if (empty($user->getBackupCodes())) {
$this->addFlash('error', 'tfa_backup.no_codes_enabled'); $this->addFlash('error', 'tfa_backup.no_codes_enabled');
throw new \RuntimeException('You do not have any backup codes enabled, therefore you can not view them!'); throw new \RuntimeException('You do not have any backup codes enabled, therefore you can not view them!');
} }
@ -91,7 +95,7 @@ class UserSettingsController extends AbstractController
//When user change its settings, he should be logged in fully. //When user change its settings, he should be logged in fully.
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
if (!$user instanceof User) { if (! $user instanceof User) {
throw new \RuntimeException('This controller only works only for Part-DB User objects!'); throw new \RuntimeException('This controller only works only for Part-DB User objects!');
} }
@ -103,12 +107,14 @@ class UserSettingsController extends AbstractController
$u2f = $key_repo->find($key_id); $u2f = $key_repo->find($key_id);
if (null === $u2f) { if (null === $u2f) {
$this->addFlash('danger', 'tfa_u2f.u2f_delete.not_existing'); $this->addFlash('danger', 'tfa_u2f.u2f_delete.not_existing');
throw new \RuntimeException('Key not existing!'); throw new \RuntimeException('Key not existing!');
} }
//User can only delete its own U2F keys //User can only delete its own U2F keys
if ($u2f->getUser() !== $user) { if ($u2f->getUser() !== $user) {
$this->addFlash('danger', 'tfa_u2f.u2f_delete.access_denied'); $this->addFlash('danger', 'tfa_u2f.u2f_delete.access_denied');
throw new \RuntimeException('You can only delete your own U2F keys!'); throw new \RuntimeException('You can only delete your own U2F keys!');
} }
@ -138,7 +144,7 @@ class UserSettingsController extends AbstractController
//When user change its settings, he should be logged in fully. //When user change its settings, he should be logged in fully.
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
if (!$user instanceof User) { if (! $user instanceof User) {
return new \RuntimeException('This controller only works only for Part-DB User objects!'); return new \RuntimeException('This controller only works only for Part-DB User objects!');
} }
@ -158,9 +164,7 @@ class UserSettingsController extends AbstractController
*/ */
public function userSettings(Request $request, EntityManagerInterface $em, UserPasswordEncoderInterface $passwordEncoder, GoogleAuthenticator $googleAuthenticator, BackupCodeManager $backupCodeManager) public function userSettings(Request $request, EntityManagerInterface $em, UserPasswordEncoderInterface $passwordEncoder, GoogleAuthenticator $googleAuthenticator, BackupCodeManager $backupCodeManager)
{ {
/** /** @var User */
* @var User
*/
$user = $this->getUser(); $user = $this->getUser();
$page_need_reload = false; $page_need_reload = false;
@ -168,7 +172,7 @@ class UserSettingsController extends AbstractController
//When user change its settings, he should be logged in fully. //When user change its settings, he should be logged in fully.
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
if (!$user instanceof User) { if (! $user instanceof User) {
throw new \RuntimeException('This controller only works only for Part-DB User objects!'); throw new \RuntimeException('This controller only works only for Part-DB User objects!');
} }
@ -180,7 +184,7 @@ class UserSettingsController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid() && !$this->demo_mode) { if ($form->isSubmitted() && $form->isValid() && ! $this->demo_mode) {
//Check if user theme setting has changed //Check if user theme setting has changed
if ($user->getTheme() !== $em->getUnitOfWork()->getOriginalEntityData($user)['theme']) { if ($user->getTheme() !== $em->getUnitOfWork()->getOriginalEntityData($user)['theme']) {
$page_need_reload = true; $page_need_reload = true;
@ -227,7 +231,7 @@ class UserSettingsController extends AbstractController
$pw_form->handleRequest($request); $pw_form->handleRequest($request);
//Check if password if everything was correct, then save it to User and DB //Check if password if everything was correct, then save it to User and DB
if ($pw_form->isSubmitted() && $pw_form->isValid() && !$this->demo_mode) { if ($pw_form->isSubmitted() && $pw_form->isValid() && ! $this->demo_mode) {
$password = $passwordEncoder->encodePassword($user, $pw_form['new_password']->getData()); $password = $passwordEncoder->encodePassword($user, $pw_form['new_password']->getData());
$user->setPassword($password); $user->setPassword($password);
@ -242,14 +246,14 @@ class UserSettingsController extends AbstractController
//Handle 2FA things //Handle 2FA things
$google_form = $this->createForm(TFAGoogleSettingsType::class, $user); $google_form = $this->createForm(TFAGoogleSettingsType::class, $user);
$google_enabled = $user->isGoogleAuthenticatorEnabled(); $google_enabled = $user->isGoogleAuthenticatorEnabled();
if (!$form->isSubmitted() && !$google_enabled) { if (! $form->isSubmitted() && ! $google_enabled) {
$user->setGoogleAuthenticatorSecret($googleAuthenticator->generateSecret()); $user->setGoogleAuthenticatorSecret($googleAuthenticator->generateSecret());
$google_form->get('googleAuthenticatorSecret')->setData($user->getGoogleAuthenticatorSecret()); $google_form->get('googleAuthenticatorSecret')->setData($user->getGoogleAuthenticatorSecret());
} }
$google_form->handleRequest($request); $google_form->handleRequest($request);
if ($google_form->isSubmitted() && $google_form->isValid() && !$this->demo_mode) { if ($google_form->isSubmitted() && $google_form->isValid() && ! $this->demo_mode) {
if (!$google_enabled) { if (! $google_enabled) {
//Save 2FA settings (save secrets) //Save 2FA settings (save secrets)
$user->setGoogleAuthenticatorSecret($google_form->get('googleAuthenticatorSecret')->getData()); $user->setGoogleAuthenticatorSecret($google_form->get('googleAuthenticatorSecret')->getData());
$backupCodeManager->enableBackupCodes($user); $backupCodeManager->enableBackupCodes($user);
@ -277,7 +281,7 @@ class UserSettingsController extends AbstractController
])->getForm(); ])->getForm();
$backup_form->handleRequest($request); $backup_form->handleRequest($request);
if ($backup_form->isSubmitted() && $backup_form->isValid() && !$this->demo_mode) { if ($backup_form->isSubmitted() && $backup_form->isValid() && ! $this->demo_mode) {
$backupCodeManager->regenerateBackupCodes($user); $backupCodeManager->regenerateBackupCodes($user);
$em->flush(); $em->flush();
$this->addFlash('success', 'user.settings.2fa.backup_codes.regenerated'); $this->addFlash('success', 'user.settings.2fa.backup_codes.regenerated');

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -26,7 +29,7 @@ use Doctrine\Common\Persistence\ObjectManager;
class AppFixtures extends Fixture class AppFixtures extends Fixture
{ {
public function load(ObjectManager $manager) public function load(ObjectManager $manager): void
{ {
// $product = new Product(); // $product = new Product();
// $manager->persist($product); // $manager->persist($product);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -46,7 +49,7 @@ class DataStructureFixtures extends Fixture
/** /**
* Load data fixtures with the passed EntityManager. * Load data fixtures with the passed EntityManager.
*/ */
public function load(ObjectManager $manager) public function load(ObjectManager $manager): void
{ {
//Reset autoincrement //Reset autoincrement
$types = [AttachmentType::class, Device::class, Category::class, Footprint::class, Manufacturer::class, $types = [AttachmentType::class, Device::class, Category::class, Footprint::class, Manufacturer::class,
@ -65,14 +68,14 @@ class DataStructureFixtures extends Fixture
* @param string $class The class for which the nodes should be generated (must be a StructuralDBElement child) * @param string $class The class for which the nodes should be generated (must be a StructuralDBElement child)
* @param ObjectManager $manager The ObjectManager that should be used to persist the nodes * @param ObjectManager $manager The ObjectManager that should be used to persist the nodes
*/ */
public function createNodesForClass(string $class, ObjectManager $manager) public function createNodesForClass(string $class, ObjectManager $manager): void
{ {
if (!new $class() instanceof StructuralDBElement) { if (! new $class() instanceof StructuralDBElement) {
throw new \InvalidArgumentException('$class must be a StructuralDBElement!'); throw new \InvalidArgumentException('$class must be a StructuralDBElement!');
} }
$table_name = $this->em->getClassMetadata($class)->getTableName(); $table_name = $this->em->getClassMetadata($class)->getTableName();
$this->em->getConnection()->exec("ALTER TABLE `$table_name` AUTO_INCREMENT = 1;"); $this->em->getConnection()->exec("ALTER TABLE `${table_name}` AUTO_INCREMENT = 1;");
/** @var StructuralDBElement $node1 */ /** @var StructuralDBElement $node1 */
$node1 = new $class(); $node1 = new $class();

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,21 +34,21 @@ class GroupFixtures extends Fixture
public const USERS = 'group-users'; public const USERS = 'group-users';
public const READONLY = 'group-readonly'; public const READONLY = 'group-readonly';
public function load(ObjectManager $manager) public function load(ObjectManager $manager): void
{ {
$admins = new Group(); $admins = new Group();
$admins->setName('admins'); $admins->setName('admins');
//Perm values taken from Version 1 //Perm values taken from Version 1
$admins->getPermissions()->setRawPermissionValues([ $admins->getPermissions()->setRawPermissionValues([
'system' => '21', 'groups' => '1365', 'users' => '87381', 'self' => '85', 'config' => '85', 'system' => 21, 'groups' => 1365, 'users' => 87381, 'self' => 85, 'config' => 85,
'database' => '21', 'parts' => '1431655765', 'parts_name' => '5', 'parts_description' => '5', 'database' => 21, 'parts' => 1431655765, 'parts_name' => 5, 'parts_description' => 5,
'parts_footprint' => '5', 'parts_manufacturer' => '5', 'parts_comment' => '5', 'parts_order' => '5', 'parts_footprint' => 5, 'parts_manufacturer' => 5, 'parts_comment' => 5, 'parts_order' => 5,
'parts_orderdetails' => '341', 'parts_prices' => '341', 'parts_attachments' => '341', 'devices' => '5461', 'parts_orderdetails' => 341, 'parts_prices' => 341, 'parts_attachments' => 341, 'devices' => 5461,
'devices_parts' => '325', 'storelocations' => '5461', 'footprints' => '5461', 'categories' => '5461', 'devices_parts' => 325, 'storelocations' => 5461, 'footprints' => 5461, 'categories' => 5461,
'suppliers' => '5461', 'manufacturers' => '5461', 'attachment_types' => '1365', 'tools' => '1365', 'suppliers' => 5461, 'manufacturers' => 5461, 'attachment_types' => 1365, 'tools' => 1365,
'labels' => '21', 'parts_category' => '5', 'parts_minamount' => '5', 'parts_lots' => '85', 'parts_tags' => '5', 'labels' => 21, 'parts_category' => 5, 'parts_minamount' => 5, 'parts_lots' => 85, 'parts_tags' => 5,
'parts_unit' => '5', 'parts_mass' => '5', 'parts_status' => '5', 'parts_mpn' => '5', 'currencies' => '5461', 'parts_unit' => 5, 'parts_mass' => 5, 'parts_status' => 5, 'parts_mpn' => 5, 'currencies' => 5461,
'measurement_units' => '5461', 'measurement_units' => 5461,
]); ]);
$this->setReference(self::ADMINS, $admins); $this->setReference(self::ADMINS, $admins);
$manager->persist($admins); $manager->persist($admins);
@ -53,15 +56,15 @@ class GroupFixtures extends Fixture
$readonly = new Group(); $readonly = new Group();
$readonly->setName('readonly'); $readonly->setName('readonly');
$readonly->getPermissions()->setRawPermissionValues([ $readonly->getPermissions()->setRawPermissionValues([
'system' => '2', 'groups' => '2730', 'users' => '43690', 'self' => '25', 'config' => '170', 'system' => 2, 'groups' => 2730, 'users' => 43690, 'self' => 25, 'config' => 170,
'database' => '42', 'parts' => '2778027689', 'parts_name' => '9', 'parts_description' => '9', 'database' => 42, 'parts' => 2778027689, 'parts_name' => 9, 'parts_description' => 9,
'parts_footprint' => '9', 'parts_manufacturer' => '9', 'parts_comment' => '9', 'parts_order' => '9', 'parts_footprint' => 9, 'parts_manufacturer' => 9, 'parts_comment' => 9, 'parts_order' => 9,
'parts_orderdetails' => '681', 'parts_prices' => '681', 'parts_attachments' => '681', 'devices' => '1705', 'parts_orderdetails' => 681, 'parts_prices' => 681, 'parts_attachments' => 681, 'devices' => 1705,
'devices_parts' => '649', 'storelocations' => '1705', 'footprints' => '1705', 'categories' => '1705', 'devices_parts' => 649, 'storelocations' => 1705, 'footprints' => 1705, 'categories' => 1705,
'suppliers' => '1705', 'manufacturers' => '1705', 'attachment_types' => '681', 'tools' => '1366', 'suppliers' => 1705, 'manufacturers' => 1705, 'attachment_types' => 681, 'tools' => 1366,
'labels' => '165', 'parts_category' => '9', 'parts_minamount' => '9', 'parts_lots' => '169', 'parts_tags' => '9', 'labels' => 165, 'parts_category' => 9, 'parts_minamount' => 9, 'parts_lots' => 169, 'parts_tags' => 9,
'parts_unit' => '9', 'parts_mass' => '9', 'parts_status' => '9', 'parts_mpn' => '9', 'currencies' => '9897', 'parts_unit' => 9, 'parts_mass' => 9, 'parts_status' => 9, 'parts_mpn' => 9, 'currencies' => 9897,
'measurement_units' => '9897', 'measurement_units' => 9897,
]); ]);
$this->setReference(self::READONLY, $readonly); $this->setReference(self::READONLY, $readonly);
$manager->persist($readonly); $manager->persist($readonly);
@ -69,15 +72,15 @@ class GroupFixtures extends Fixture
$users = new Group(); $users = new Group();
$users->setName('users'); $users->setName('users');
$users->getPermissions()->setRawPermissionValues([ $users->getPermissions()->setRawPermissionValues([
'system' => '42', 'groups' => '2730', 'users' => '43690', 'self' => '89', 'config' => '105', 'system' => 42, 'groups' => 2730, 'users' => 43690, 'self' => 89, 'config' => 105,
'database' => '41', 'parts' => '1431655765', 'parts_name' => '5', 'parts_description' => '5', 'database' => 41, 'parts' => 1431655765, 'parts_name' => 5, 'parts_description' => 5,
'parts_footprint' => '5', 'parts_manufacturer' => '5', 'parts_comment' => '5', 'parts_order' => '5', 'parts_footprint' => 5, 'parts_manufacturer' => 5, 'parts_comment' => 5, 'parts_order' => 5,
'parts_orderdetails' => '341', 'parts_prices' => '341', 'parts_attachments' => '341', 'devices' => '5461', 'parts_orderdetails' => 341, 'parts_prices' => 341, 'parts_attachments' => 341, 'devices' => 5461,
'devices_parts' => '325', 'storelocations' => '5461', 'footprints' => '5461', 'categories' => '5461', 'devices_parts' => 325, 'storelocations' => 5461, 'footprints' => 5461, 'categories' => 5461,
'suppliers' => '5461', 'manufacturers' => '5461', 'attachment_types' => '1365', 'tools' => '1365', 'suppliers' => 5461, 'manufacturers' => 5461, 'attachment_types' => 1365, 'tools' => 1365,
'labels' => '85', 'parts_category' => '5', 'parts_minamount' => '5', 'parts_lots' => '85', 'parts_tags' => '5', 'labels' => 85, 'parts_category' => 5, 'parts_minamount' => 5, 'parts_lots' => 85, 'parts_tags' => 5,
'parts_unit' => '5', 'parts_mass' => '5', 'parts_status' => '5', 'parts_mpn' => '5', 'currencies' => '5461', 'parts_unit' => 5, 'parts_mass' => 5, 'parts_status' => 5, 'parts_mpn' => 5, 'currencies' => 5461,
'measurement_units' => '5461', 'measurement_units' => 5461,
]); ]);
$this->setReference(self::USERS, $users); $this->setReference(self::USERS, $users);
$manager->persist($users); $manager->persist($users);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -38,7 +41,7 @@ class UserFixtures extends Fixture
$this->encoder = $encoder; $this->encoder = $encoder;
} }
public function load(ObjectManager $manager) public function load(ObjectManager $manager): void
{ {
//Reset autoincrement //Reset autoincrement
$this->em->getConnection()->exec('ALTER TABLE `users` AUTO_INCREMENT = 1;'); $this->em->getConnection()->exec('ALTER TABLE `users` AUTO_INCREMENT = 1;');

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -36,13 +39,13 @@ class CustomORMAdapter extends ORMAdapter
{ {
protected $hydrationMode; protected $hydrationMode;
public function configure(array $options) public function configure(array $options): void
{ {
parent::configure($options); parent::configure($options);
$this->hydrationMode = isset($options['hydrate']) ? $options['hydrate'] : Query::HYDRATE_OBJECT; $this->hydrationMode = $options['hydrate'] ?? Query::HYDRATE_OBJECT;
} }
protected function prepareQuery(AdapterQuery $query) protected function prepareQuery(AdapterQuery $query): void
{ {
parent::prepareQuery($query); parent::prepareQuery($query);
$query->setIdentifierPropertyPath(null); $query->setIdentifierPropertyPath(null);
@ -57,7 +60,7 @@ class CustomORMAdapter extends ORMAdapter
$builder = $query->get('qb'); $builder = $query->get('qb');
$state = $query->getState(); $state = $query->getState();
// Apply definitive view state for current 'page' of the table // 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 */ /** @var AbstractColumn $column */
if ($column->isOrderable()) { if ($column->isOrderable()) {
$builder->addOrderBy($column->getOrderField(), $direction); $builder->addOrderBy($column->getOrderField(), $direction);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -54,23 +57,13 @@ class AttachmentDataTable implements DataTableTypeInterface
$this->attachmentURLGenerator = $attachmentURLGenerator; $this->attachmentURLGenerator = $attachmentURLGenerator;
} }
protected function getQuery(QueryBuilder $builder) public function configure(DataTable $dataTable, array $options): void
{
$builder->distinct()->select('attachment')
->addSelect('attachment_type')
//->addSelect('element')
->from(Attachment::class, 'attachment')
->leftJoin('attachment.attachment_type', 'attachment_type');
//->leftJoin('attachment.element', 'element');
}
public function configure(DataTable $dataTable, array $options)
{ {
$dataTable->add('picture', TextColumn::class, [ $dataTable->add('picture', TextColumn::class, [
'label' => '', 'label' => '',
'render' => function ($value, Attachment $context) { 'render' => function ($value, Attachment $context) {
if ($context->isPicture() if ($context->isPicture()
&& !$context->isExternal() && ! $context->isExternal()
&& $this->attachmentHelper->isFileExisting($context)) { && $this->attachmentHelper->isFileExisting($context)) {
return sprintf( return sprintf(
'<img alt="%s" src="%s" data-thumbnail="%s" class="%s">', '<img alt="%s" src="%s" data-thumbnail="%s" class="%s">',
@ -204,9 +197,19 @@ class AttachmentDataTable implements DataTableTypeInterface
$dataTable->createAdapter(ORMAdapter::class, [ $dataTable->createAdapter(ORMAdapter::class, [
'entity' => Attachment::class, 'entity' => Attachment::class,
'query' => function (QueryBuilder $builder) { 'query' => function (QueryBuilder $builder): void {
$this->getQuery($builder); $this->getQuery($builder);
}, },
]); ]);
} }
protected function getQuery(QueryBuilder $builder): void
{
$builder->distinct()->select('attachment')
->addSelect('attachment_type')
//->addSelect('element')
->from(Attachment::class, 'attachment')
->leftJoin('attachment.attachment_type', 'attachment_type');
//->leftJoin('attachment.element', 'element');
}
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -50,11 +53,11 @@ class EntityColumn extends AbstractColumn
*/ */
public function normalize($value) public function normalize($value)
{ {
/* @var NamedDBElement $value */ /** @var NamedDBElement $value */
return $value; return $value;
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
parent::configureOptions($resolver); parent::configureOptions($resolver);
@ -76,9 +79,9 @@ class EntityColumn extends AbstractColumn
$this->urlGenerator->listPartsURL($entity), $this->urlGenerator->listPartsURL($entity),
$value $value
); );
} else {
return sprintf('<i>%s</i>', $value);
} }
return sprintf('<i>%s</i>', $value);
} }
}; };
}); });

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,14 +34,11 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
*/ */
class LocaleDateTimeColumn extends AbstractColumn class LocaleDateTimeColumn extends AbstractColumn
{ {
/**
* {@inheritdoc}
*/
public function normalize($value) public function normalize($value)
{ {
if (null === $value) { if (null === $value) {
return $this->options['nullValue']; return $this->options['nullValue'];
} elseif (!$value instanceof \DateTimeInterface) { } elseif (! $value instanceof \DateTimeInterface) {
$value = new \DateTime((string) $value); $value = new \DateTime((string) $value);
} }
@ -60,9 +60,6 @@ class LocaleDateTimeColumn extends AbstractColumn
return $formatter->format($value->getTimestamp()); return $formatter->format($value->getTimestamp());
} }
/**
* {@inheritdoc}
*/
protected function configureOptions(OptionsResolver $resolver) protected function configureOptions(OptionsResolver $resolver)
{ {
parent::configureOptions($resolver); parent::configureOptions($resolver);

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -56,7 +59,7 @@ class PartAttachmentsColumn extends AbstractColumn
public function render($value, $context) public function render($value, $context)
{ {
if (!$context instanceof Part) { if (! $context instanceof Part) {
throw new \RuntimeException('$context must be a Part object!'); throw new \RuntimeException('$context must be a Part object!');
} }
$tmp = ''; $tmp = '';
@ -70,7 +73,7 @@ class PartAttachmentsColumn extends AbstractColumn
if (--$count < 0) { if (--$count < 0) {
break; break;
} }
/* @var Attachment $attachment */ /** @var Attachment $attachment */
$tmp .= sprintf( $tmp .= sprintf(
'<a href="%s" title="%s" class="attach-table-icon" target="_blank" rel="noopener" data-no-ajax>%s</a>', '<a href="%s" title="%s" class="attach-table-icon" target="_blank" rel="noopener" data-no-ajax>%s</a>',
$this->urlGenerator->viewURL($attachment), $this->urlGenerator->viewURL($attachment),
@ -87,7 +90,7 @@ class PartAttachmentsColumn extends AbstractColumn
return $tmp; return $tmp;
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
parent::configureOptions($resolver); parent::configureOptions($resolver);
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -71,87 +74,7 @@ class PartsDataTable implements DataTableTypeInterface
$this->attachmentURLGenerator = $attachmentURLGenerator; $this->attachmentURLGenerator = $attachmentURLGenerator;
} }
protected function getQuery(QueryBuilder $builder) public function configure(DataTable $dataTable, array $options): void
{
$builder->distinct()->select('part')
->addSelect('category')
->addSelect('footprint')
->addSelect('manufacturer')
->addSelect('partUnit')
->addSelect('master_picture_attachment')
->addSelect('footprint_attachment')
->addSelect('partLots')
->addSelect('orderdetails')
->addSelect('attachments')
->addSelect('storelocations')
->from(Part::class, 'part')
->leftJoin('part.category', 'category')
->leftJoin('part.master_picture_attachment', 'master_picture_attachment')
->leftJoin('part.partLots', 'partLots')
->leftJoin('partLots.storage_location', 'storelocations')
->leftJoin('part.footprint', 'footprint')
->leftJoin('footprint.master_picture_attachment', 'footprint_attachment')
->leftJoin('part.manufacturer', 'manufacturer')
->leftJoin('part.orderdetails', 'orderdetails')
->leftJoin('part.attachments', 'attachments')
->leftJoin('part.partUnit', 'partUnit');
}
protected function buildCriteria(QueryBuilder $builder, array $options)
{
$em = $builder->getEntityManager();
if (isset($options['category'])) {
$category = $options['category'];
$list = $this->treeBuilder->typeToNodesList(Category::class, $category);
$list[] = $category;
$builder->andWhere('part.category IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['footprint'])) {
$category = $options['footprint'];
$list = $this->treeBuilder->typeToNodesList(Footprint::class, $category);
$list[] = $category;
$builder->andWhere('part.footprint IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['manufacturer'])) {
$category = $options['manufacturer'];
$list = $this->treeBuilder->typeToNodesList(Manufacturer::class, $category);
$list[] = $category;
$builder->andWhere('part.manufacturer IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['storelocation'])) {
$location = $options['storelocation'];
$list = $this->treeBuilder->typeToNodesList(Storelocation::class, $location);
$list[] = $location;
$builder->andWhere('partLots.storage_location IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['supplier'])) {
$supplier = $options['supplier'];
$list = $this->treeBuilder->typeToNodesList(Supplier::class, $supplier);
$list[] = $supplier;
$builder->andWhere('orderdetails.supplier IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['tag'])) {
$builder->andWhere('part.tags LIKE :tag')->setParameter('tag', '%'.$options['tag'].'%');
}
if (isset($options['search'])) {
$builder->AndWhere('part.name LIKE :search')->orWhere('part.description LIKE :search')->orWhere('part.comment LIKE :search')
->setParameter('search', '%'.$options['search'].'%');
}
}
public function configure(DataTable $dataTable, array $options)
{ {
$dataTable $dataTable
->add('picture', TextColumn::class, [ ->add('picture', TextColumn::class, [
@ -293,16 +216,96 @@ class PartsDataTable implements DataTableTypeInterface
->addOrderBy('name') ->addOrderBy('name')
->createAdapter(CustomORMAdapter::class, [ ->createAdapter(CustomORMAdapter::class, [
'query' => function (QueryBuilder $builder) { 'query' => function (QueryBuilder $builder): void {
$this->getQuery($builder); $this->getQuery($builder);
}, },
'entity' => Part::class, 'entity' => Part::class,
'criteria' => [ 'criteria' => [
function (QueryBuilder $builder) use ($options) { function (QueryBuilder $builder) use ($options): void {
$this->buildCriteria($builder, $options); $this->buildCriteria($builder, $options);
}, },
new SearchCriteriaProvider(), new SearchCriteriaProvider(),
], ],
]); ]);
} }
protected function getQuery(QueryBuilder $builder): void
{
$builder->distinct()->select('part')
->addSelect('category')
->addSelect('footprint')
->addSelect('manufacturer')
->addSelect('partUnit')
->addSelect('master_picture_attachment')
->addSelect('footprint_attachment')
->addSelect('partLots')
->addSelect('orderdetails')
->addSelect('attachments')
->addSelect('storelocations')
->from(Part::class, 'part')
->leftJoin('part.category', 'category')
->leftJoin('part.master_picture_attachment', 'master_picture_attachment')
->leftJoin('part.partLots', 'partLots')
->leftJoin('partLots.storage_location', 'storelocations')
->leftJoin('part.footprint', 'footprint')
->leftJoin('footprint.master_picture_attachment', 'footprint_attachment')
->leftJoin('part.manufacturer', 'manufacturer')
->leftJoin('part.orderdetails', 'orderdetails')
->leftJoin('part.attachments', 'attachments')
->leftJoin('part.partUnit', 'partUnit');
}
protected function buildCriteria(QueryBuilder $builder, array $options): void
{
$em = $builder->getEntityManager();
if (isset($options['category'])) {
$category = $options['category'];
$list = $this->treeBuilder->typeToNodesList(Category::class, $category);
$list[] = $category;
$builder->andWhere('part.category IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['footprint'])) {
$category = $options['footprint'];
$list = $this->treeBuilder->typeToNodesList(Footprint::class, $category);
$list[] = $category;
$builder->andWhere('part.footprint IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['manufacturer'])) {
$category = $options['manufacturer'];
$list = $this->treeBuilder->typeToNodesList(Manufacturer::class, $category);
$list[] = $category;
$builder->andWhere('part.manufacturer IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['storelocation'])) {
$location = $options['storelocation'];
$list = $this->treeBuilder->typeToNodesList(Storelocation::class, $location);
$list[] = $location;
$builder->andWhere('partLots.storage_location IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['supplier'])) {
$supplier = $options['supplier'];
$list = $this->treeBuilder->typeToNodesList(Supplier::class, $supplier);
$list[] = $supplier;
$builder->andWhere('orderdetails.supplier IN (:cid)')->setParameter('cid', $list);
}
if (isset($options['tag'])) {
$builder->andWhere('part.tags LIKE :tag')->setParameter('tag', '%'.$options['tag'].'%');
}
if (isset($options['search'])) {
$builder->AndWhere('part.name LIKE :search')->orWhere('part.description LIKE :search')->orWhere('part.comment LIKE :search')
->setParameter('search', '%'.$options['search'].'%');
}
}
} }

View file

@ -68,6 +68,11 @@ abstract class Attachment extends NamedDBElement
/** @var array Placeholders for attachments which using built in files. */ /** @var array Placeholders for attachments which using built in files. */
public const BUILTIN_PLACEHOLDER = ['%FOOTPRINTS%', '%FOOTPRINTS3D%']; public const BUILTIN_PLACEHOLDER = ['%FOOTPRINTS%', '%FOOTPRINTS3D%'];
/**
* @var string The class of the element that can be passed to this attachment. Must be overridden in subclasses.
*/
public const ALLOWED_ELEMENT_CLASS = '';
/** /**
* @var bool * @var bool
* @ORM\Column(type="boolean") * @ORM\Column(type="boolean")
@ -99,11 +104,6 @@ abstract class Attachment extends NamedDBElement
*/ */
protected $attachment_type; protected $attachment_type;
/**
* @var string The class of the element that can be passed to this attachment. Must be overridden in subclasses.
*/
public const ALLOWED_ELEMENT_CLASS = '';
public function __construct() public function __construct()
{ {
//parent::__construct(); //parent::__construct();
@ -170,7 +170,7 @@ abstract class Attachment extends NamedDBElement
return true; return true;
} }
return !\in_array($tmp[0], array_merge(static::INTERNAL_PLACEHOLDER, static::BUILTIN_PLACEHOLDER), false); return ! \in_array($tmp[0], array_merge(static::INTERNAL_PLACEHOLDER, static::BUILTIN_PLACEHOLDER), false);
} }
/** /**
@ -221,7 +221,7 @@ abstract class Attachment extends NamedDBElement
return null; return null;
} }
if (!empty($this->original_filename)) { if (! empty($this->original_filename)) {
return strtolower(pathinfo($this->original_filename, PATHINFO_EXTENSION)); return strtolower(pathinfo($this->original_filename, PATHINFO_EXTENSION));
} }
@ -244,7 +244,7 @@ abstract class Attachment extends NamedDBElement
*/ */
public function getURL(): ?string public function getURL(): ?string
{ {
if (!$this->isExternal() && !$this->isBuiltIn()) { if (! $this->isExternal() && ! $this->isBuiltIn()) {
return null; return null;
} }
@ -257,7 +257,7 @@ abstract class Attachment extends NamedDBElement
*/ */
public function getHost(): ?string public function getHost(): ?string
{ {
if (!$this->isExternal()) { if (! $this->isExternal()) {
return null; return null;
} }
@ -287,7 +287,7 @@ abstract class Attachment extends NamedDBElement
} }
//If we have a stored original filename, then use it //If we have a stored original filename, then use it
if (!empty($this->original_filename)) { if (! empty($this->original_filename)) {
return $this->original_filename; return $this->original_filename;
} }
@ -362,8 +362,8 @@ abstract class Attachment extends NamedDBElement
*/ */
public function setElement(AttachmentContainingDBElement $element): self public function setElement(AttachmentContainingDBElement $element): self
{ {
if (!is_a($element, static::ALLOWED_ELEMENT_CLASS)) { if (! is_a($element, static::ALLOWED_ELEMENT_CLASS)) {
throw new \InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', \get_class($this), static::ALLOWED_ELEMENT_CLASS)); throw new \InvalidArgumentException(sprintf('The element associated with a %s must be a %s!', static::class, static::ALLOWED_ELEMENT_CLASS));
} }
$this->element = $element; $this->element = $element;
@ -404,7 +404,7 @@ abstract class Attachment extends NamedDBElement
public function setURL(?string $url): self public function setURL(?string $url): self
{ {
//Only set if the URL is not empty //Only set if the URL is not empty
if (!empty($url)) { if (! empty($url)) {
if (false !== strpos($url, '%BASE%') || false !== strpos($url, '%MEDIA%')) { if (false !== strpos($url, '%BASE%') || false !== strpos($url, '%MEDIA%')) {
throw new \InvalidArgumentException('You can not reference internal files via the url field! But nice try!'); throw new \InvalidArgumentException('You can not reference internal files via the url field! But nice try!');
} }
@ -443,9 +443,9 @@ abstract class Attachment extends NamedDBElement
/** /**
* Check if a string is a URL and is valid. * Check if a string is a URL and is valid.
* *
* @param $string string The string which should be checked * @param string $string The string which should be checked
* @param bool $path_required If true, the string must contain a path to be valid. (e.g. foo.bar would be invalid, foo.bar/test.php would be valid). * @param bool $path_required If true, the string must contain a path to be valid. (e.g. foo.bar would be invalid, foo.bar/test.php would be valid).
* @param $only_http bool Set this to true, if only HTTPS or HTTP schemata should be allowed. * @param bool $only_http Set this to true, if only HTTPS or HTTP schemata should be allowed.
* *Caution: When this is set to false, a attacker could use the file:// schema, to get internal server files, like /etc/passwd.* * *Caution: When this is set to false, a attacker could use the file:// schema, to get internal server files, like /etc/passwd.*
* *
* @return bool True if the string is a valid URL. False, if the string is not an URL or invalid. * @return bool True if the string is a valid URL. False, if the string is not an URL or invalid.

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -30,12 +33,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class AttachmentTypeAttachment extends Attachment class AttachmentTypeAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = AttachmentType::class;
/** /**
* @var AttachmentType the element this attachment is associated with * @var AttachmentType the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Attachments\AttachmentType", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Attachments\AttachmentType", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = AttachmentType::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class CategoryAttachment extends Attachment class CategoryAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = Category::class;
/** /**
* @var Category the element this attachment is associated with * @var Category the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Category", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Category", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = Category::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class CurrencyAttachment extends Attachment class CurrencyAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = Currency::class;
/** /**
* @var Currency the element this attachment is associated with * @var Currency the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = Currency::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class DeviceAttachment extends Attachment class DeviceAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = Device::class;
/** /**
* @var Device the element this attachment is associated with * @var Device the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Devices\Device", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Devices\Device", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = Device::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class FootprintAttachment extends Attachment class FootprintAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = Footprint::class;
/** /**
* @var Footprint the element this attachment is associated with * @var Footprint the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Footprint", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Footprint", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = Footprint::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class GroupAttachment extends Attachment class GroupAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = Group::class;
/** /**
* @var Group the element this attachment is associated with * @var Group the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\Group", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\Group", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = Group::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class ManufacturerAttachment extends Attachment class ManufacturerAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = Manufacturer::class;
/** /**
* @var Manufacturer the element this attachment is associated with * @var Manufacturer the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Manufacturer", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Manufacturer", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = Manufacturer::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -32,12 +35,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class MeasurementUnitAttachment extends Attachment class MeasurementUnitAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = MeasurementUnit::class;
/** /**
* @var Manufacturer the element this attachment is associated with * @var Manufacturer the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\MeasurementUnit", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\MeasurementUnit", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = MeasurementUnit::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class PartAttachment extends Attachment class PartAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = Part::class;
/** /**
* @var Part the element this attachment is associated with * @var Part the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Part", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = Part::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class StorelocationAttachment extends Attachment class StorelocationAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = Storelocation::class;
/** /**
* @var Storelocation the element this attachment is associated with * @var Storelocation the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Storelocation", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Storelocation", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = Storelocation::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class SupplierAttachment extends Attachment class SupplierAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = Supplier::class;
/** /**
* @var Supplier the element this attachment is associated with * @var Supplier the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\Parts\Supplier", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = Supplier::class;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,12 +34,11 @@ use Doctrine\ORM\Mapping as ORM;
*/ */
class UserAttachment extends Attachment class UserAttachment extends Attachment
{ {
public const ALLOWED_ELEMENT_CLASS = User::class;
/** /**
* @var User the element this attachment is associated with * @var User the element this attachment is associated with
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="attachments") * @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="attachments")
* @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE"). * @ORM\JoinColumn(name="element_id", referencedColumnName="id", nullable=false, onDelete="CASCADE").
*/ */
protected $element; protected $element;
public const ALLOWED_ELEMENT_CLASS = User::class;
} }

View file

@ -20,6 +20,7 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
/** /**
* Part-DB Version 0.4+ "nextgen" * Part-DB Version 0.4+ "nextgen"
* Copyright (C) 2016 - 2019 Jan Böhmer * Copyright (C) 2016 - 2019 Jan Böhmer

View file

@ -66,6 +66,12 @@ abstract class DBElement
*/ */
protected $id; protected $id;
public function __clone()
{
//Set ID to null, so that an new entry is created
$this->id = null;
}
/** /**
* Get the ID. The ID can be zero, or even negative (for virtual elements). If an element is virtual, can be * Get the ID. The ID can be zero, or even negative (for virtual elements). If an element is virtual, can be
* checked with isVirtualElement(). * checked with isVirtualElement().
@ -86,10 +92,4 @@ abstract class DBElement
* @return string The ID as a string; * @return string The ID as a string;
*/ */
abstract public function getIDString(): string; abstract public function getIDString(): string;
public function __clone()
{
//Set ID to null, so that an new entry is created
$this->id = null;
}
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -45,6 +45,17 @@ abstract class NamedDBElement extends DBElement
*/ */
protected $name = ''; protected $name = '';
/******************************************************************************
*
* Helpers
*
******************************************************************************/
public function __toString()
{
return $this->getName();
}
/******************************************************************************** /********************************************************************************
* *
* Getters * Getters
@ -80,15 +91,4 @@ abstract class NamedDBElement extends DBElement
return $this; return $this;
} }
/******************************************************************************
*
* Helpers
*
******************************************************************************/
public function __toString()
{
return $this->getName();
}
} }

View file

@ -113,11 +113,11 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
*/ */
public function isChildOf(self $another_element): bool public function isChildOf(self $another_element): bool
{ {
$class_name = \get_class($this); $class_name = static::class;
//Check if both elements compared, are from the same type //Check if both elements compared, are from the same type
// (we have to check inheritance, or we get exceptions when using doctrine entities (they have a proxy type): // (we have to check inheritance, or we get exceptions when using doctrine entities (they have a proxy type):
if (!is_a($another_element, $class_name) && !is_a($this, \get_class($another_element))) { if (! is_a($another_element, $class_name) && ! is_a($this, \get_class($another_element))) {
throw new \InvalidArgumentException('isChildOf() only works for objects of the same type!'); throw new \InvalidArgumentException('isChildOf() only works for objects of the same type!');
} }
@ -201,7 +201,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
*/ */
public function getFullPath(string $delimiter = self::PATH_DELIMITER_ARROW): string public function getFullPath(string $delimiter = self::PATH_DELIMITER_ARROW): string
{ {
if (!\is_array($this->full_path_strings)) { if (! \is_array($this->full_path_strings)) {
$this->full_path_strings = []; $this->full_path_strings = [];
$this->full_path_strings[] = $this->getName(); $this->full_path_strings[] = $this->getName();
$element = $this; $element = $this;
@ -233,7 +233,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
$tmp[] = $this; $tmp[] = $this;
//We only allow 20 levels depth //We only allow 20 levels depth
while (!end($tmp)->isRoot() && \count($tmp) < 20) { while (! end($tmp)->isRoot() && \count($tmp) < 20) {
$tmp[] = end($tmp)->parent; $tmp[] = end($tmp)->parent;
} }
@ -243,8 +243,6 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement
/** /**
* Get all sub elements of this element. * Get all sub elements of this element.
* *
* @param bool $recursive if true, the search is recursive
*
* @return Collection<static> all subelements as an array of objects (sorted by their full path) * @return Collection<static> all subelements as an array of objects (sorted by their full path)
*/ */
public function getSubelements(): iterable public function getSubelements(): iterable

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -266,7 +269,7 @@ class PartLot extends DBElement
*/ */
public function getAmount(): float public function getAmount(): float
{ {
if ($this->part instanceof Part && !$this->part->useFloatAmount()) { if ($this->part instanceof Part && ! $this->part->useFloatAmount()) {
return round($this->amount); return round($this->amount);
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -192,7 +195,7 @@ trait BasicPropertyTrait
/** /**
* Set the favorite status for this part. * Set the favorite status for this part.
* *
* @param $new_favorite_status bool The new favorite status, that should be applied on this part. * @param bool $new_favorite_status The new favorite status, that should be applied on this part.
* Set this to true, when the part should be a favorite. * Set this to true, when the part should be a favorite.
*/ */
public function setFavorite(bool $new_favorite_status): self public function setFavorite(bool $new_favorite_status): self

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -134,7 +137,7 @@ trait InstockTrait
public function useFloatAmount(): bool public function useFloatAmount(): bool
{ {
if ($this->partUnit instanceof MeasurementUnit) { if ($this->partUnit instanceof MeasurementUnit) {
return !$this->partUnit->isInteger(); return ! $this->partUnit->isInteger();
} }
//When no part unit is set, treat it as part count, and so use the integer value. //When no part unit is set, treat it as part count, and so use the integer value.

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -185,7 +188,7 @@ trait OrderTrait
} }
foreach ($all_orderdetails as $orderdetails) { foreach ($all_orderdetails as $orderdetails) {
if (!$orderdetails->getObsolete()) { if (! $orderdetails->getObsolete()) {
return false; return false;
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -104,7 +107,7 @@ class Currency extends StructuralDBElement
return null; return null;
} }
return bcdiv(1, $tmp, static::PRICE_SCALE); return bcdiv('1', $tmp, static::PRICE_SCALE);
} }
/** /**

View file

@ -181,7 +181,7 @@ class Orderdetail extends DBElement
/** /**
* Get the link to the website of the article on the suppliers website. * Get the link to the website of the article on the suppliers website.
* *
* @param $no_automatic_url bool Set this to true, if you only want to get the local set product URL for this Orderdetail * @param bool $no_automatic_url Set this to true, if you only want to get the local set product URL for this Orderdetail
* and not a automatic generated one, based from the Supplier * and not a automatic generated one, based from the Supplier
* *
* @return string the link to the article * @return string the link to the article
@ -330,7 +330,7 @@ class Orderdetail extends DBElement
* Sets the custom product supplier URL for this order detail. * Sets the custom product supplier URL for this order detail.
* Set this to "", if the function getSupplierProductURL should return the automatic generated URL. * Set this to "", if the function getSupplierProductURL should return the automatic generated URL.
* *
* @param $new_url string The new URL for the supplier URL * @param string $new_url The new URL for the supplier URL
* *
* @return Orderdetail * @return Orderdetail
*/ */

View file

@ -68,10 +68,10 @@ use Symfony\Component\Validator\Constraints as Assert;
*/ */
class Pricedetail extends DBElement class Pricedetail extends DBElement
{ {
public const PRICE_PRECISION = 5;
use TimestampTrait; use TimestampTrait;
public const PRICE_PRECISION = 5;
/** /**
* @var Orderdetail * @var Orderdetail
* @ORM\ManyToOne(targetEntity="Orderdetail", inversedBy="pricedetails") * @ORM\ManyToOne(targetEntity="Orderdetail", inversedBy="pricedetails")
@ -180,7 +180,7 @@ class Pricedetail extends DBElement
*/ */
public function getPriceRelatedQuantity(): float public function getPriceRelatedQuantity(): float
{ {
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) { if ($this->orderdetail && $this->orderdetail->getPart() && ! $this->orderdetail->getPart()->useFloatAmount()) {
$tmp = round($this->price_related_quantity); $tmp = round($this->price_related_quantity);
return $tmp < 1 ? 1 : $tmp; return $tmp < 1 ? 1 : $tmp;
@ -203,7 +203,7 @@ class Pricedetail extends DBElement
*/ */
public function getMinDiscountQuantity(): float public function getMinDiscountQuantity(): float
{ {
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) { if ($this->orderdetail && $this->orderdetail->getPart() && ! $this->orderdetail->getPart()->useFloatAmount()) {
$tmp = round($this->min_discount_quantity); $tmp = round($this->min_discount_quantity);
return $tmp < 1 ? 1 : $tmp; return $tmp < 1 ? 1 : $tmp;

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -299,7 +302,7 @@ class PermissionsEmbed
*/ */
public function isValidPermissionName(string $permission_name): bool public function isValidPermissionName(string $permission_name): bool
{ {
return isset($this->$permission_name); return isset($this->{$permission_name});
} }
/** /**
@ -312,11 +315,11 @@ class PermissionsEmbed
*/ */
public function getBitValue(string $permission_name, int $bit_n): int public function getBitValue(string $permission_name, int $bit_n): int
{ {
if (!$this->isValidPermissionName($permission_name)) { if (! $this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException(sprintf('No permission with the name "%s" is existing!', $permission_name)); throw new \InvalidArgumentException(sprintf('No permission with the name "%s" is existing!', $permission_name));
} }
$perm_int = $this->$permission_name; $perm_int = (int) $this->{$permission_name};
return static::readBitPair($perm_int, $bit_n); return static::readBitPair($perm_int, $bit_n);
} }
@ -382,11 +385,11 @@ class PermissionsEmbed
*/ */
public function setBitValue(string $permission_name, int $bit_n, int $new_value): self public function setBitValue(string $permission_name, int $bit_n, int $new_value): self
{ {
if (!$this->isValidPermissionName($permission_name)) { if (! $this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException('No permission with the given name is existing!'); throw new \InvalidArgumentException('No permission with the given name is existing!');
} }
$this->$permission_name = static::writeBitPair($this->$permission_name, $bit_n, $new_value); $this->{$permission_name} = static::writeBitPair($this->{$permission_name}, $bit_n, $new_value);
return $this; return $this;
} }
@ -401,11 +404,11 @@ class PermissionsEmbed
*/ */
public function getRawPermissionValue(string $permission_name): int public function getRawPermissionValue(string $permission_name): int
{ {
if (!$this->isValidPermissionName($permission_name)) { if (! $this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException('No permission with the given name is existing!'); throw new \InvalidArgumentException('No permission with the given name is existing!');
} }
return $this->$permission_name; return $this->{$permission_name};
} }
/** /**
@ -418,11 +421,11 @@ class PermissionsEmbed
*/ */
public function setRawPermissionValue(string $permission_name, int $value): self public function setRawPermissionValue(string $permission_name, int $value): self
{ {
if (!$this->isValidPermissionName($permission_name)) { if (! $this->isValidPermissionName($permission_name)) {
throw new \InvalidArgumentException(sprintf('No permission with the given name %s is existing!', $permission_name)); throw new \InvalidArgumentException(sprintf('No permission with the given name %s is existing!', $permission_name));
} }
$this->$permission_name = $value; $this->{$permission_name} = $value;
return $this; return $this;
} }
@ -436,9 +439,9 @@ class PermissionsEmbed
* *
* @return $this * @return $this
*/ */
public function setRawPermissionValues(array $values, array $values2 = null): self public function setRawPermissionValues(array $values, ?array $values2 = null): self
{ {
if (!empty($values2)) { if (! empty($values2)) {
$values = array_combine($values, $values2); $values = array_combine($values, $values2);
} }
@ -452,12 +455,12 @@ class PermissionsEmbed
/** /**
* Reads a bit pair from $data. * Reads a bit pair from $data.
* *
* @param $data int The data from where the bits should be extracted from * @param int|string $data The data from where the bits should be extracted from
* @param $n int The number of the lower bit (of the pair) that should be read. Starting from zero. * @param int $n The number of the lower bit (of the pair) that should be read. Starting from zero.
* *
* @return int the value of the bit pair * @return int the value of the bit pair
*/ */
final protected static function readBitPair(int $data, int $n): int final protected static function readBitPair($data, int $n): int
{ {
Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.'); Assert::lessThanEq($n, 31, '$n must be smaller than 32, because only a 32bit int is used! Got %s.');
if (0 !== $n % 2) { if (0 !== $n % 2) {
@ -471,9 +474,9 @@ class PermissionsEmbed
/** /**
* Writes a bit pair in the given $data and returns it. * Writes a bit pair in the given $data and returns it.
* *
* @param $data int The data which should be modified * @param int $data The data which should be modified
* @param $n int The number of the lower bit of the pair which should be written * @param int $n The number of the lower bit of the pair which should be written
* @param $new int The new value of the pair * @param int $new The new value of the pair
* *
* @return int the new data with the modified pair * @return int the new data with the modified pair
*/ */

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -38,13 +41,6 @@ class U2FKey implements TwoFactorKeyInterface
{ {
use TimestampTrait; use TimestampTrait;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/** /**
* @ORM\Column(type="string", length=64) * @ORM\Column(type="string", length=64)
* *
@ -73,6 +69,13 @@ class U2FKey implements TwoFactorKeyInterface
**/ **/
public $counter; public $counter;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/** /**
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="u2fKeys") * @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User", inversedBy="u2fKeys")
* *
@ -95,62 +98,52 @@ class U2FKey implements TwoFactorKeyInterface
$this->counter = $data->counter; $this->counter = $data->counter;
} }
/** {@inheritdoc} */
public function getKeyHandle() public function getKeyHandle()
{ {
return $this->keyHandle; return $this->keyHandle;
} }
/** {@inheritdoc} */ public function setKeyHandle($keyHandle): void
public function setKeyHandle($keyHandle)
{ {
$this->keyHandle = $keyHandle; $this->keyHandle = $keyHandle;
} }
/** {@inheritdoc} */
public function getPublicKey() public function getPublicKey()
{ {
return $this->publicKey; return $this->publicKey;
} }
/** {@inheritdoc} */ public function setPublicKey($publicKey): void
public function setPublicKey($publicKey)
{ {
$this->publicKey = $publicKey; $this->publicKey = $publicKey;
} }
/** {@inheritdoc} */
public function getCertificate() public function getCertificate()
{ {
return $this->certificate; return $this->certificate;
} }
/** {@inheritdoc} */ public function setCertificate($certificate): void
public function setCertificate($certificate)
{ {
$this->certificate = $certificate; $this->certificate = $certificate;
} }
/** {@inheritdoc} */
public function getCounter() public function getCounter()
{ {
return $this->counter; return $this->counter;
} }
/** {@inheritdoc} */ public function setCounter($counter): void
public function setCounter($counter)
{ {
$this->counter = $counter; $this->counter = $counter;
} }
/** {@inheritdoc} */
public function getName() public function getName()
{ {
return $this->name; return $this->name;
} }
/** {@inheritdoc} */ public function setName($name): void
public function setName($name)
{ {
$this->name = $name; $this->name = $name;
} }

View file

@ -266,6 +266,19 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
$this->u2fKeys = new ArrayCollection(); $this->u2fKeys = new ArrayCollection();
} }
/**
* Returns a string representation of this user (the full name).
* E.g. 'Jane Doe (j.doe) [DISABLED].
*
* @return string
*/
public function __toString()
{
$tmp = $this->isDisabled() ? ' [DISABLED]' : '';
return $this->getFullName(true).$tmp;
}
/** /**
* Checks if the current user, is the user which represents the not logged in (anonymous) users. * Checks if the current user, is the user which represents the not logged in (anonymous) users.
* *
@ -330,7 +343,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/** /**
* @see UserInterface * @see UserInterface
*/ */
public function getSalt() public function getSalt(): void
{ {
// not needed when using the "bcrypt" algorithm in security.yaml // not needed when using the "bcrypt" algorithm in security.yaml
} }
@ -338,7 +351,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/** /**
* @see UserInterface * @see UserInterface
*/ */
public function eraseCredentials() public function eraseCredentials(): void
{ {
// If you store any temporary, sensitive data on the user, clear it here // If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null; // $this->plainPassword = null;
@ -503,7 +516,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
public function setName(string $new_name): NamedDBElement public function setName(string $new_name): NamedDBElement
{ {
// Anonymous user is not allowed to change its username // Anonymous user is not allowed to change its username
if (!$this->isAnonymousUser()) { if (! $this->isAnonymousUser()) {
$this->name = $new_name; $this->name = $new_name;
} }
@ -646,8 +659,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
/** /**
* Change the timezone of this user. * Change the timezone of this user.
* *
* @param string $timezone|null The new timezone (e.g. 'Europe/Berlin') or null to use the system wide one.
*
* @return $this * @return $this
*/ */
public function setTimezone(?string $timezone): self public function setTimezone(?string $timezone): self
@ -706,19 +717,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
return $this; return $this;
} }
/**
* Returns a string representation of this user (the full name).
* E.g. 'Jane Doe (j.doe) [DISABLED].
*
* @return string
*/
public function __toString()
{
$tmp = $this->isDisabled() ? ' [DISABLED]' : '';
return $this->getFullName(true).$tmp;
}
/** /**
* Return true if the user should do two-factor authentication. * Return true if the user should do two-factor authentication.
* *
@ -771,7 +769,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/ */
public function isBackupCode(string $code): bool public function isBackupCode(string $code): bool
{ {
return \in_array($code, $this->backupCodes); return \in_array($code, $this->backupCodes, true);
} }
/** /**
@ -781,7 +779,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/ */
public function invalidateBackupCode(string $code): void public function invalidateBackupCode(string $code): void
{ {
$key = array_search($code, $this->backupCodes); $key = array_search($code, $this->backupCodes, true);
if (false !== $key) { if (false !== $key) {
unset($this->backupCodes[$key]); unset($this->backupCodes[$key]);
} }
@ -883,9 +881,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
$this->u2fKeys->removeElement($key); $this->u2fKeys->removeElement($key);
} }
/**
* {@inheritdoc}
*/
public function getPreferredTwoFactorProvider(): ?string public function getPreferredTwoFactorProvider(): ?string
{ {
//If U2F is available then prefer it //If U2F is available then prefer it

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -52,7 +55,7 @@ class AttachmentDeleteListener
* *
* @PreUpdate * @PreUpdate
*/ */
public function preUpdateHandler(Attachment $attachment, PreUpdateEventArgs $event) public function preUpdateHandler(Attachment $attachment, PreUpdateEventArgs $event): void
{ {
if ($event->hasChangedField('path')) { if ($event->hasChangedField('path')) {
//Dont delete file if the attachment uses a builtin ressource: //Dont delete file if the attachment uses a builtin ressource:
@ -70,7 +73,7 @@ class AttachmentDeleteListener
* *
* @PostRemove * @PostRemove
*/ */
public function postRemoveHandler(Attachment $attachment, LifecycleEventArgs $event) public function postRemoveHandler(Attachment $attachment, LifecycleEventArgs $event): void
{ {
//Dont delete file if the attachment uses a builtin ressource: //Dont delete file if the attachment uses a builtin ressource:
if ($attachment->isBuiltIn()) { if ($attachment->isBuiltIn()) {

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -46,7 +49,7 @@ class TreeCacheInvalidationListener
* @ORM\PostPersist() * @ORM\PostPersist()
* @ORM\PostRemove() * @ORM\PostRemove()
*/ */
public function invalidate(DBElement $element, LifecycleEventArgs $event) public function invalidate(DBElement $element, LifecycleEventArgs $event): void
{ {
//If an element was changed, then invalidate all cached trees with this element class //If an element was changed, then invalidate all cached trees with this element class
if ($element instanceof StructuralDBElement) { if ($element instanceof StructuralDBElement) {

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -41,7 +44,7 @@ class LoginSuccessListener implements EventSubscriberInterface
$this->flashBag = $flashBag; $this->flashBag = $flashBag;
} }
public function onLogin(InteractiveLoginEvent $event) public function onLogin(InteractiveLoginEvent $event): void
{ {
$this->flashBag->add('notice', $this->translator->trans('flash.login_successful')); $this->flashBag->add('notice', $this->translator->trans('flash.login_successful'));
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -43,7 +46,7 @@ class LogoutOnDisabledUserListener implements EventSubscriberInterface
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
} }
public function onRequest(RequestEvent $event) public function onRequest(RequestEvent $event): void
{ {
$user = $this->security->getUser(); $user = $this->security->getUser();
if ($user instanceof User && $user->isDisabled()) { if ($user instanceof User && $user->isDisabled()) {

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -36,10 +39,6 @@ use Symfony\Component\Security\Http\HttpUtils;
*/ */
class PasswordChangeNeededSubscriber implements EventSubscriberInterface class PasswordChangeNeededSubscriber implements EventSubscriberInterface
{ {
protected $security;
protected $flashBag;
protected $httpUtils;
/** /**
* @var string[] The routes the user is allowed to access without being redirected. * @var string[] The routes the user is allowed to access without being redirected.
* This should be only routes related to login/logout and user settings * This should be only routes related to login/logout and user settings
@ -54,6 +53,9 @@ class PasswordChangeNeededSubscriber implements EventSubscriberInterface
/** @var string The route the user will redirected to, if he needs to change this password */ /** @var string The route the user will redirected to, if he needs to change this password */
public const REDIRECT_TARGET = 'user_settings'; public const REDIRECT_TARGET = 'user_settings';
protected $security;
protected $flashBag;
protected $httpUtils;
public function __construct(Security $security, FlashBagInterface $flashBag, HttpUtils $httpUtils) public function __construct(Security $security, FlashBagInterface $flashBag, HttpUtils $httpUtils)
{ {
@ -72,15 +74,15 @@ class PasswordChangeNeededSubscriber implements EventSubscriberInterface
$user = $this->security->getUser(); $user = $this->security->getUser();
$request = $event->getRequest(); $request = $event->getRequest();
if (!$event->isMasterRequest()) { if (! $event->isMasterRequest()) {
return; return;
} }
if (!$user instanceof User) { if (! $user instanceof User) {
return; return;
} }
//Abort if we dont need to redirect the user. //Abort if we dont need to redirect the user.
if (!$user->isNeedPwChange() && !static::TFARedirectNeeded($user)) { if (! $user->isNeedPwChange() && ! static::TFARedirectNeeded($user)) {
return; return;
} }
@ -123,16 +125,13 @@ class PasswordChangeNeededSubscriber implements EventSubscriberInterface
{ {
$tfa_enabled = $user->isU2FAuthEnabled() || $user->isGoogleAuthenticatorEnabled(); $tfa_enabled = $user->isU2FAuthEnabled() || $user->isGoogleAuthenticatorEnabled();
if (null !== $user->getGroup() && $user->getGroup()->isEnforce2FA() && !$tfa_enabled) { if (null !== $user->getGroup() && $user->getGroup()->isEnforce2FA() && ! $tfa_enabled) {
return true; return true;
} }
return false; return false;
} }
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() public static function getSubscribedEvents()
{ {
return [ return [

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -57,9 +60,9 @@ class SymfonyDebugToolbarSubscriber implements EventSubscriberInterface
return ['kernel.response' => 'onKernelResponse']; return ['kernel.response' => 'onKernelResponse'];
} }
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event): void
{ {
if (!$this->kernel->getParameter('kernel.debug')) { if (! $this->kernel->getParameter('kernel.debug')) {
return; return;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -41,18 +44,18 @@ class TimezoneListener implements EventSubscriberInterface
$this->security = $security; $this->security = $security;
} }
public function setTimeZone(ControllerEvent $event) public function setTimeZone(ControllerEvent $event): void
{ {
$timezone = null; $timezone = null;
//Check if the user has set a timezone //Check if the user has set a timezone
$user = $this->security->getUser(); $user = $this->security->getUser();
if ($user instanceof User && !empty($user->getTimezone())) { if ($user instanceof User && ! empty($user->getTimezone())) {
$timezone = $user->getTimezone(); $timezone = $user->getTimezone();
} }
//Fill with default value if needed //Fill with default value if needed
if (null === $timezone && !empty($this->default_timezone)) { if (null === $timezone && ! empty($this->default_timezone)) {
$timezone = $this->default_timezone; $timezone = $this->default_timezone;
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -31,13 +34,12 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class U2FRegistrationSubscriber implements EventSubscriberInterface class U2FRegistrationSubscriber implements EventSubscriberInterface
{ {
/** @var UrlGeneratorInterface */
private $router;
protected $em; protected $em;
protected $demo_mode; protected $demo_mode;
protected $flashBag; protected $flashBag;
/** @var UrlGeneratorInterface */
private $router;
public function __construct(UrlGeneratorInterface $router, EntityManagerInterface $entityManager, FlashBagInterface $flashBag, bool $demo_mode) public function __construct(UrlGeneratorInterface $router, EntityManagerInterface $entityManager, FlashBagInterface $flashBag, bool $demo_mode)
{ {
@ -58,7 +60,7 @@ class U2FRegistrationSubscriber implements EventSubscriberInterface
public function onRegister(RegisterEvent $event): void public function onRegister(RegisterEvent $event): void
{ {
//Skip adding of U2F key on demo mode //Skip adding of U2F key on demo mode
if (!$this->demo_mode) { if (! $this->demo_mode) {
$user = $event->getUser(); $user = $event->getUser();
$registration = $event->getRegistration(); $registration = $event->getRegistration();
$newKey = new U2FKey(); $newKey = new U2FKey();

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -39,7 +42,7 @@ class AttachmentTypeAdminForm extends BaseEntityAdminForm
parent::__construct($security, $params); parent::__construct($security, $params);
} }
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity): void
{ {
$is_new = null === $entity->getID(); $is_new = null === $entity->getID();
@ -48,7 +51,7 @@ class AttachmentTypeAdminForm extends BaseEntityAdminForm
'help' => 'attachment_type.edit.filetype_filter.help', 'help' => 'attachment_type.edit.filetype_filter.help',
'attr' => ['placeholder' => 'attachment_type.edit.filetype_filter.placeholder'], 'attr' => ['placeholder' => 'attachment_type.edit.filetype_filter.placeholder'],
'empty_data' => '', 'empty_data' => '',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
//Normalize data before writing it to database //Normalize data before writing it to database
$builder->get('filetype_filter')->addViewTransformer(new CallbackTransformer( $builder->get('filetype_filter')->addViewTransformer(new CallbackTransformer(

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -50,13 +53,13 @@ class BaseEntityAdminForm extends AbstractType
$this->params = $params; $this->params = $params;
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
parent::configureOptions($resolver); // TODO: Change the autogenerated stub parent::configureOptions($resolver); // TODO: Change the autogenerated stub
$resolver->setRequired('attachment_class'); $resolver->setRequired('attachment_class');
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
/** @var StructuralDBElement $entity */ /** @var StructuralDBElement $entity */
$entity = $options['data']; $entity = $options['data'];
@ -65,22 +68,22 @@ class BaseEntityAdminForm extends AbstractType
$builder $builder
->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label', ->add('name', TextType::class, ['empty_data' => '', 'label' => 'name.label',
'attr' => ['placeholder' => 'part.name.placeholder'], 'attr' => ['placeholder' => 'part.name.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]) 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('parent', StructuralEntityType::class, ['class' => \get_class($entity), ->add('parent', StructuralEntityType::class, ['class' => \get_class($entity),
'required' => false, 'label' => 'parent.label', 'required' => false, 'label' => 'parent.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]) 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity), ])
->add('not_selectable', CheckboxType::class, ['required' => false, ->add('not_selectable', CheckboxType::class, ['required' => false,
'label' => 'entity.edit.not_selectable', 'label' => 'entity.edit.not_selectable',
'help' => 'entity.edit.not_selectable.help', 'help' => 'entity.edit.not_selectable.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]) 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('comment', CKEditorType::class, ['required' => false, 'empty_data' => '', ->add('comment', CKEditorType::class, ['required' => false, 'empty_data' => '',
'label' => 'comment.label', 'label' => 'comment.label',
'attr' => ['rows' => 4], 'help' => 'bbcode.hint', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$this->additionalFormElements($builder, $options, $entity); $this->additionalFormElements($builder, $options, $entity);
@ -90,7 +93,7 @@ class BaseEntityAdminForm extends AbstractType
'allow_add' => true, 'allow_add' => true,
'allow_delete' => true, 'allow_delete' => true,
'label' => false, 'label' => false,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'entry_options' => [ 'entry_options' => [
'data_class' => $options['attachment_class'], 'data_class' => $options['attachment_class'],
], ],
@ -99,7 +102,7 @@ class BaseEntityAdminForm extends AbstractType
$builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [ $builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [
'required' => false, 'required' => false,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'label' => 'part.edit.master_attachment', 'label' => 'part.edit.master_attachment',
'entity' => $entity, 'entity' => $entity,
]); ]);
@ -108,12 +111,12 @@ class BaseEntityAdminForm extends AbstractType
$builder->add('save', SubmitType::class, [ $builder->add('save', SubmitType::class, [
'label' => $is_new ? 'entity.create' : 'entity.edit.save', 'label' => $is_new ? 'entity.create' : 'entity.edit.save',
'attr' => ['class' => $is_new ? 'btn-success' : ''], 'attr' => ['class' => $is_new ? 'btn-success' : ''],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]) 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ])
->add('reset', ResetType::class, ['label' => 'entity.edit.reset', ->add('reset', ResetType::class, ['label' => 'entity.edit.reset',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
} }
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity): void
{ {
//Empty for Base //Empty for Base
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -28,7 +31,7 @@ use Symfony\Component\Form\FormBuilderInterface;
class CategoryAdminForm extends BaseEntityAdminForm class CategoryAdminForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity): void
{ {
$is_new = null === $entity->getID(); $is_new = null === $entity->getID();
@ -36,44 +39,44 @@ class CategoryAdminForm extends BaseEntityAdminForm
'label' => 'category.edit.disable_footprints', 'label' => 'category.edit.disable_footprints',
'help' => 'category.edit.disable_footprints.help', 'help' => 'category.edit.disable_footprints.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('disable_manufacturers', CheckboxType::class, ['required' => false, $builder->add('disable_manufacturers', CheckboxType::class, ['required' => false,
'label' => 'category.edit.disable_manufacturers', 'label' => 'category.edit.disable_manufacturers',
'help' => 'category.edit.disable_manufacturers.help', 'help' => 'category.edit.disable_manufacturers.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('disable_autodatasheets', CheckboxType::class, ['required' => false, $builder->add('disable_autodatasheets', CheckboxType::class, ['required' => false,
'label' => 'category.edit.disable_autodatasheets', 'label' => 'category.edit.disable_autodatasheets',
'help' => 'category.edit.disable_autodatasheets.help', 'help' => 'category.edit.disable_autodatasheets.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('disable_properties', CheckboxType::class, ['required' => false, $builder->add('disable_properties', CheckboxType::class, ['required' => false,
'label' => 'category.edit.disable_properties', 'label' => 'category.edit.disable_properties',
'help' => 'category.edit.disable_properties.help', 'help' => 'category.edit.disable_properties.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('partname_hint', TextType::class, ['required' => false, 'empty_data' => '', $builder->add('partname_hint', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'category.edit.partname_hint', 'label' => 'category.edit.partname_hint',
'attr' => ['placeholder' => 'category.edit.partname_hint.placeholder'], 'attr' => ['placeholder' => 'category.edit.partname_hint.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('partname_regex', TextType::class, ['required' => false, 'empty_data' => '', $builder->add('partname_regex', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'category.edit.partname_regex', 'label' => 'category.edit.partname_regex',
'attr' => ['placeholder' => 'category.edit.partname_regex.placeholder'], 'attr' => ['placeholder' => 'category.edit.partname_regex.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('default_description', TextType::class, ['required' => false, 'empty_data' => '', $builder->add('default_description', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'category.edit.default_description', 'label' => 'category.edit.default_description',
'attr' => ['placeholder' => 'category.edit.default_description.placeholder'], 'attr' => ['placeholder' => 'category.edit.default_description.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('default_comment', TextType::class, ['required' => false, 'empty_data' => '', $builder->add('default_comment', TextType::class, ['required' => false, 'empty_data' => '',
'label' => 'category.edit.default_comment', 'label' => 'category.edit.default_comment',
'attr' => ['placeholder' => 'category.edit.default_comment.placeholder'], 'attr' => ['placeholder' => 'category.edit.default_comment.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -30,20 +33,20 @@ use Symfony\Component\Form\FormBuilderInterface;
class CompanyForm extends BaseEntityAdminForm class CompanyForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity): void
{ {
$is_new = null === $entity->getID(); $is_new = null === $entity->getID();
$builder->add('address', TextareaType::class, [ $builder->add('address', TextareaType::class, [
'label' => 'company.edit.address', 'label' => 'company.edit.address',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.edit.address.placeholder'], 'required' => false, 'attr' => ['placeholder' => 'company.edit.address.placeholder'], 'required' => false,
'empty_data' => '', 'empty_data' => '',
]); ]);
$builder->add('phone_number', TelType::class, [ $builder->add('phone_number', TelType::class, [
'label' => 'company.edit.phone_number', 'label' => 'company.edit.phone_number',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.edit.phone_number.placeholder'], 'attr' => ['placeholder' => 'company.edit.phone_number.placeholder'],
'required' => false, 'required' => false,
'empty_data' => '', 'empty_data' => '',
@ -51,21 +54,21 @@ class CompanyForm extends BaseEntityAdminForm
$builder->add('fax_number', TelType::class, [ $builder->add('fax_number', TelType::class, [
'label' => 'company.edit.fax_number', 'label' => 'company.edit.fax_number',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false, 'attr' => ['placeholder' => 'company.fax_number.placeholder'], 'required' => false,
'empty_data' => '', 'empty_data' => '',
]); ]);
$builder->add('email_address', EmailType::class, [ $builder->add('email_address', EmailType::class, [
'label' => 'company.edit.email', 'label' => 'company.edit.email',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.edit.email.placeholder'], 'required' => false, 'attr' => ['placeholder' => 'company.edit.email.placeholder'], 'required' => false,
'empty_data' => '', 'empty_data' => '',
]); ]);
$builder->add('website', UrlType::class, [ $builder->add('website', UrlType::class, [
'label' => 'company.edit.website', 'label' => 'company.edit.website',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.edit.website.placeholder'], 'required' => false, 'attr' => ['placeholder' => 'company.edit.website.placeholder'], 'required' => false,
'empty_data' => '', 'empty_data' => '',
]); ]);
@ -73,7 +76,7 @@ class CompanyForm extends BaseEntityAdminForm
$builder->add('auto_product_url', UrlType::class, [ $builder->add('auto_product_url', UrlType::class, [
'label' => 'company.edit.auto_product_url', 'label' => 'company.edit.auto_product_url',
'help' => 'company.edit.auto_product_url.help', 'help' => 'company.edit.auto_product_url.help',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
'attr' => ['placeholder' => 'company.edit.auto_product_url.placeholder'], 'attr' => ['placeholder' => 'company.edit.auto_product_url.placeholder'],
'required' => false, 'required' => false,
'empty_data' => '', 'empty_data' => '',

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -28,7 +31,7 @@ use Symfony\Component\Form\FormBuilderInterface;
class CurrencyAdminForm extends BaseEntityAdminForm class CurrencyAdminForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity): void
{ {
$is_new = null === $entity->getID(); $is_new = null === $entity->getID();
@ -37,13 +40,13 @@ class CurrencyAdminForm extends BaseEntityAdminForm
'label' => 'currency.edit.iso_code', 'label' => 'currency.edit.iso_code',
'preferred_choices' => ['EUR', 'USD', 'GBP', 'JPY', 'CNY'], 'preferred_choices' => ['EUR', 'USD', 'GBP', 'JPY', 'CNY'],
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], 'attr' => ['class' => 'selectpicker', 'data-live-search' => true],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('exchange_rate', MoneyType::class, [ $builder->add('exchange_rate', MoneyType::class, [
'required' => false, 'required' => false,
'label' => 'currency.edit.exchange_rate', 'label' => 'currency.edit.exchange_rate',
'currency' => $this->params->get('default_currency'), 'currency' => $this->params->get('default_currency'),
'scale' => 6, 'scale' => 6,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -27,11 +30,11 @@ use Symfony\Component\Form\FormBuilderInterface;
class FootprintAdminForm extends BaseEntityAdminForm class FootprintAdminForm extends BaseEntityAdminForm
{ {
public function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) public function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity): void
{ {
$builder->add('footprint_3d', MasterPictureAttachmentType::class, [ $builder->add('footprint_3d', MasterPictureAttachmentType::class, [
'required' => false, 'required' => false,
'disabled' => !$this->security->isGranted(null === $entity->getID() ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted(null === $entity->getID() ? 'create' : 'edit', $entity),
'label' => 'footprint.edit.3d_model', 'label' => 'footprint.edit.3d_model',
'filter' => '3d_model', 'filter' => '3d_model',
'entity' => $entity, 'entity' => $entity,

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -28,7 +31,7 @@ use Symfony\Component\Form\FormBuilderInterface;
class GroupAdminForm extends BaseEntityAdminForm class GroupAdminForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity): void
{ {
$is_new = null === $entity->getID(); $is_new = null === $entity->getID();
@ -36,13 +39,13 @@ class GroupAdminForm extends BaseEntityAdminForm
'label' => 'group.edit.enforce_2fa', 'label' => 'group.edit.enforce_2fa',
'help' => 'entity.edit.enforce_2fa.help', 'help' => 'entity.edit.enforce_2fa.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity),
]); ]);
$builder->add('permissions', PermissionsType::class, [ $builder->add('permissions', PermissionsType::class, [
'mapped' => false, 'mapped' => false,
'data' => $builder->getData(), 'data' => $builder->getData(),
'disabled' => !$this->security->isGranted('edit_permissions', $entity), 'disabled' => ! $this->security->isGranted('edit_permissions', $entity),
]); ]);
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -41,14 +44,14 @@ class ImportType extends AbstractType
$this->security = $security; $this->security = $security;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$data = $options['data']; $data = $options['data'];
//Disable import if user is not allowed to create elements. //Disable import if user is not allowed to create elements.
$entity = new $data['entity_class'](); $entity = new $data['entity_class']();
$perm_name = 'create'; $perm_name = 'create';
$disabled = !$this->security->isGranted($perm_name, $entity); $disabled = ! $this->security->isGranted($perm_name, $entity);
$builder $builder

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -38,14 +41,14 @@ class MassCreationForm extends AbstractType
$this->security = $security; $this->security = $security;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$data = $options['data']; $data = $options['data'];
//Disable import if user is not allowed to create elements. //Disable import if user is not allowed to create elements.
$entity = new $data['entity_class'](); $entity = new $data['entity_class']();
$perm_name = 'create'; $perm_name = 'create';
$disabled = !$this->security->isGranted($perm_name, $entity); $disabled = ! $this->security->isGranted($perm_name, $entity);
$builder $builder
->add('lines', TextareaType::class, ['data' => '', ->add('lines', TextareaType::class, ['data' => '',

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -28,7 +31,7 @@ use Symfony\Component\Form\FormBuilderInterface;
class MeasurementUnitAdminForm extends BaseEntityAdminForm class MeasurementUnitAdminForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity): void
{ {
$is_new = null === $entity->getID(); $is_new = null === $entity->getID();
@ -36,17 +39,17 @@ class MeasurementUnitAdminForm extends BaseEntityAdminForm
'label' => 'measurement_unit.edit.is_integer', 'label' => 'measurement_unit.edit.is_integer',
'help' => 'measurement_unit.edit.is_integer.help', 'help' => 'measurement_unit.edit.is_integer.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('use_si_prefix', CheckboxType::class, ['required' => false, $builder->add('use_si_prefix', CheckboxType::class, ['required' => false,
'label' => 'measurement_unit.edit.use_si_prefix', 'label' => 'measurement_unit.edit.use_si_prefix',
'help' => 'measurement_unit.edit.use_si_prefix.help', 'help' => 'measurement_unit.edit.use_si_prefix.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
$builder->add('unit', TextType::class, ['required' => false, $builder->add('unit', TextType::class, ['required' => false,
'label' => 'measurement_unit.edit.unit_symbol', 'label' => 'measurement_unit.edit.unit_symbol',
'attr' => ['placeholder' => 'measurement_unit.edit.unit_symbol.placeholder'], 'attr' => ['placeholder' => 'measurement_unit.edit.unit_symbol.placeholder'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), ]);
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -29,7 +32,7 @@ use Symfony\Component\Form\FormBuilderInterface;
class StorelocationAdminForm extends BaseEntityAdminForm class StorelocationAdminForm extends BaseEntityAdminForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity): void
{ {
$is_new = null === $entity->getID(); $is_new = null === $entity->getID();
@ -38,27 +41,27 @@ class StorelocationAdminForm extends BaseEntityAdminForm
'label' => 'storelocation.edit.is_full.label', 'label' => 'storelocation.edit.is_full.label',
'help' => 'storelocation.edit.is_full.help', 'help' => 'storelocation.edit.is_full.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('limit_to_existing_parts', CheckboxType::class, [ $builder->add('limit_to_existing_parts', CheckboxType::class, [
'required' => false, 'required' => false,
'label' => 'storelocation.limit_to_existing.label', 'label' => 'storelocation.limit_to_existing.label',
'help' => 'storelocation.limit_to_existing.help', 'help' => 'storelocation.limit_to_existing.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('only_single_part', CheckboxType::class, [ $builder->add('only_single_part', CheckboxType::class, [
'required' => false, 'required' => false,
'label' => 'storelocation.only_single_part.label', 'label' => 'storelocation.only_single_part.label',
'help' => 'storelocation.only_single_part.help', 'help' => 'storelocation.only_single_part.help',
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('storage_type', StructuralEntityType::class, [ $builder->add('storage_type', StructuralEntityType::class, [
'required' => false, 'required' => false,
'label' => 'storelocation.storage_type.label', 'label' => 'storelocation.storage_type.label',
'help' => 'storelocation.storage_type.help', 'help' => 'storelocation.storage_type.help',
'class' => MeasurementUnit::class, 'disable_not_selectable' => true, 'class' => MeasurementUnit::class, 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -29,7 +32,7 @@ use Symfony\Component\Form\FormBuilderInterface;
class SupplierForm extends CompanyForm class SupplierForm extends CompanyForm
{ {
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity): void
{ {
$is_new = null === $entity->getID(); $is_new = null === $entity->getID();
@ -40,14 +43,14 @@ class SupplierForm extends CompanyForm
'required' => false, 'required' => false,
'label' => 'supplier.edit.default_currency', 'label' => 'supplier.edit.default_currency',
'disable_not_selectable' => true, 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), ]); 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity), ]);
$builder->add('shipping_costs', MoneyType::class, [ $builder->add('shipping_costs', MoneyType::class, [
'required' => false, 'required' => false,
'currency' => $this->params->get('default_currency'), 'currency' => $this->params->get('default_currency'),
'scale' => 3, 'scale' => 3,
'label' => 'supplier.shipping_costs.label', 'label' => 'supplier.shipping_costs.label',
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity),
]); ]);
} }
} }

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -53,7 +56,7 @@ class AttachmentFormType extends AbstractType
$this->allow_attachments_download = $allow_attachments_downloads; $this->allow_attachments_download = $allow_attachments_downloads;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('name', TextType::class, [ $builder->add('name', TextType::class, [
'label' => 'attachment.edit.name', 'label' => 'attachment.edit.name',
@ -94,7 +97,7 @@ class AttachmentFormType extends AbstractType
$builder->add('downloadURL', CheckboxType::class, ['required' => false, $builder->add('downloadURL', CheckboxType::class, ['required' => false,
'label' => 'attachment.edit.download_url', 'label' => 'attachment.edit.download_url',
'mapped' => false, 'mapped' => false,
'disabled' => !$this->allow_attachments_download, 'disabled' => ! $this->allow_attachments_download,
'attr' => ['class' => 'form-control-sm'], 'attr' => ['class' => 'form-control-sm'],
'label_attr' => ['class' => 'checkbox-custom'], ]); 'label_attr' => ['class' => 'checkbox-custom'], ]);
@ -114,7 +117,7 @@ class AttachmentFormType extends AbstractType
//Check the secure file checkbox, if file is in securefile location //Check the secure file checkbox, if file is in securefile location
$builder->get('secureFile')->addEventListener( $builder->get('secureFile')->addEventListener(
FormEvents::PRE_SET_DATA, FormEvents::PRE_SET_DATA,
function (FormEvent $event) { function (FormEvent $event): void {
$attachment = $event->getForm()->getParent()->getData(); $attachment = $event->getForm()->getParent()->getData();
if ($attachment instanceof Attachment) { if ($attachment instanceof Attachment) {
$event->setData($attachment->isSecure()); $event->setData($attachment->isSecure());
@ -123,7 +126,7 @@ class AttachmentFormType extends AbstractType
); );
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => Attachment::class, 'data_class' => Attachment::class,

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -46,7 +49,7 @@ class OrderdetailType extends AbstractType
$this->security = $security; $this->security = $security;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
/** @var Orderdetail $orderdetail */ /** @var Orderdetail $orderdetail */
$orderdetail = $builder->getData(); $orderdetail = $builder->getData();
@ -76,7 +79,7 @@ class OrderdetailType extends AbstractType
]); ]);
//Add pricedetails after we know the data, so we can set the default currency //Add pricedetails after we know the data, so we can set the default currency
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options) { $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options): void {
/** @var Orderdetail $orderdetail */ /** @var Orderdetail $orderdetail */
$orderdetail = $event->getData(); $orderdetail = $event->getData();
@ -94,14 +97,14 @@ class OrderdetailType extends AbstractType
'prototype_data' => $dummy_pricedetail, 'prototype_data' => $dummy_pricedetail,
'by_reference' => false, 'by_reference' => false,
'entry_options' => [ 'entry_options' => [
'disabled' => !$this->security->isGranted('@parts_prices.edit'), 'disabled' => ! $this->security->isGranted('@parts_prices.edit'),
'measurement_unit' => $options['measurement_unit'], 'measurement_unit' => $options['measurement_unit'],
], ],
]); ]);
}); });
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => Orderdetail::class, 'data_class' => Orderdetail::class,

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -59,7 +62,7 @@ class PartBaseType extends AbstractType
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
/** @var Part $part */ /** @var Part $part */
$part = $builder->getData(); $part = $builder->getData();
@ -79,7 +82,7 @@ class PartBaseType extends AbstractType
'empty_data' => '', 'empty_data' => '',
'label' => 'part.edit.name', 'label' => 'part.edit.name',
'attr' => ['placeholder' => 'part.edit.name.placeholder'], 'attr' => ['placeholder' => 'part.edit.name.placeholder'],
'disabled' => !$this->security->isGranted('name.edit', $part), 'disabled' => ! $this->security->isGranted('name.edit', $part),
]) ])
->add('description', CKEditorType::class, [ ->add('description', CKEditorType::class, [
'required' => false, 'required' => false,
@ -87,26 +90,26 @@ class PartBaseType extends AbstractType
'label' => 'part.edit.description', 'label' => 'part.edit.description',
'config_name' => 'description_config', 'config_name' => 'description_config',
'attr' => ['placeholder' => 'part.edit.description.placeholder', 'rows' => 2], 'attr' => ['placeholder' => 'part.edit.description.placeholder', 'rows' => 2],
'disabled' => !$this->security->isGranted('description.edit', $part), 'disabled' => ! $this->security->isGranted('description.edit', $part),
]) ])
->add('minAmount', SIUnitType::class, [ ->add('minAmount', SIUnitType::class, [
'attr' => ['min' => 0, 'placeholder' => 'part.editmininstock.placeholder'], 'attr' => ['min' => 0, 'placeholder' => 'part.editmininstock.placeholder'],
'label' => 'part.edit.mininstock', 'label' => 'part.edit.mininstock',
'measurement_unit' => $part->getPartUnit(), 'measurement_unit' => $part->getPartUnit(),
'disabled' => !$this->security->isGranted('minamount.edit', $part), 'disabled' => ! $this->security->isGranted('minamount.edit', $part),
]) ])
->add('category', StructuralEntityType::class, [ ->add('category', StructuralEntityType::class, [
'class' => Category::class, 'class' => Category::class,
'label' => 'part.edit.category', 'label' => 'part.edit.category',
'disable_not_selectable' => true, 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('category.edit', $part), 'disabled' => ! $this->security->isGranted('category.edit', $part),
]) ])
->add('footprint', StructuralEntityType::class, [ ->add('footprint', StructuralEntityType::class, [
'class' => Footprint::class, 'class' => Footprint::class,
'required' => false, 'required' => false,
'label' => 'part.edit.footprint', 'label' => 'part.edit.footprint',
'disable_not_selectable' => true, 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('footprint.edit', $part), 'disabled' => ! $this->security->isGranted('footprint.edit', $part),
]) ])
->add('tags', TextType::class, [ ->add('tags', TextType::class, [
'required' => false, 'required' => false,
@ -115,7 +118,7 @@ class PartBaseType extends AbstractType
'attr' => [ 'attr' => [
'class' => 'tagsinput', 'class' => 'tagsinput',
'data-autocomplete' => $this->urlGenerator->generate('typeahead_tags', ['query' => 'QUERY']), ], 'data-autocomplete' => $this->urlGenerator->generate('typeahead_tags', ['query' => 'QUERY']), ],
'disabled' => !$this->security->isGranted('tags.edit', $part), 'disabled' => ! $this->security->isGranted('tags.edit', $part),
]); ]);
//Manufacturer section //Manufacturer section
@ -124,24 +127,24 @@ class PartBaseType extends AbstractType
'required' => false, 'required' => false,
'label' => 'part.edit.manufacturer.label', 'label' => 'part.edit.manufacturer.label',
'disable_not_selectable' => true, 'disable_not_selectable' => true,
'disabled' => !$this->security->isGranted('manufacturer.edit', $part), 'disabled' => ! $this->security->isGranted('manufacturer.edit', $part),
]) ])
->add('manufacturer_product_url', UrlType::class, [ ->add('manufacturer_product_url', UrlType::class, [
'required' => false, 'required' => false,
'empty_data' => '', 'empty_data' => '',
'label' => 'part.edit.manufacturer_url.label', 'label' => 'part.edit.manufacturer_url.label',
'disabled' => !$this->security->isGranted('mpn.edit', $part), 'disabled' => ! $this->security->isGranted('mpn.edit', $part),
]) ])
->add('manufacturer_product_number', TextType::class, [ ->add('manufacturer_product_number', TextType::class, [
'required' => false, 'required' => false,
'empty_data' => '', 'empty_data' => '',
'label' => 'part.edit.mpn', 'label' => 'part.edit.mpn',
'disabled' => !$this->security->isGranted('mpn.edit', $part), ]) 'disabled' => ! $this->security->isGranted('mpn.edit', $part), ])
->add('manufacturing_status', ChoiceType::class, [ ->add('manufacturing_status', ChoiceType::class, [
'label' => 'part.edit.manufacturing_status', 'label' => 'part.edit.manufacturing_status',
'choices' => $status_choices, 'choices' => $status_choices,
'required' => false, 'required' => false,
'disabled' => !$this->security->isGranted('status.edit', $part), 'disabled' => ! $this->security->isGranted('status.edit', $part),
]); ]);
//Advanced section //Advanced section
@ -149,26 +152,26 @@ class PartBaseType extends AbstractType
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'required' => false, 'required' => false,
'label' => 'part.edit.needs_review', 'label' => 'part.edit.needs_review',
'disabled' => !$this->security->isGranted('edit', $part), 'disabled' => ! $this->security->isGranted('edit', $part),
]) ])
->add('favorite', CheckboxType::class, [ ->add('favorite', CheckboxType::class, [
'label_attr' => ['class' => 'checkbox-custom'], 'label_attr' => ['class' => 'checkbox-custom'],
'required' => false, 'required' => false,
'label' => 'part.edit.is_favorite', 'label' => 'part.edit.is_favorite',
'disabled' => !$this->security->isGranted('change_favorite', $part), 'disabled' => ! $this->security->isGranted('change_favorite', $part),
]) ])
->add('mass', SIUnitType::class, [ ->add('mass', SIUnitType::class, [
'unit' => 'g', 'unit' => 'g',
'label' => 'part.edit.mass', 'label' => 'part.edit.mass',
'required' => false, 'required' => false,
'disabled' => !$this->security->isGranted('mass.edit', $part), 'disabled' => ! $this->security->isGranted('mass.edit', $part),
]) ])
->add('partUnit', StructuralEntityType::class, [ ->add('partUnit', StructuralEntityType::class, [
'class' => MeasurementUnit::class, 'class' => MeasurementUnit::class,
'required' => false, 'required' => false,
'disable_not_selectable' => true, 'disable_not_selectable' => true,
'label' => 'part.edit.partUnit', 'label' => 'part.edit.partUnit',
'disabled' => !$this->security->isGranted('unit.edit', $part), 'disabled' => ! $this->security->isGranted('unit.edit', $part),
]); ]);
//Comment section //Comment section
@ -176,7 +179,7 @@ class PartBaseType extends AbstractType
'required' => false, 'required' => false,
'label' => 'part.edit.comment', 'label' => 'part.edit.comment',
'attr' => ['rows' => 4], 'attr' => ['rows' => 4],
'disabled' => !$this->security->isGranted('comment.edit', $part), 'empty_data' => '', 'disabled' => ! $this->security->isGranted('comment.edit', $part), 'empty_data' => '',
]); ]);
//Part Lots section //Part Lots section
@ -187,7 +190,7 @@ class PartBaseType extends AbstractType
'label' => false, 'label' => false,
'entry_options' => [ 'entry_options' => [
'measurement_unit' => $part->getPartUnit(), 'measurement_unit' => $part->getPartUnit(),
'disabled' => !$this->security->isGranted('lots.edit', $part), 'disabled' => ! $this->security->isGranted('lots.edit', $part),
], ],
'by_reference' => false, 'by_reference' => false,
]); ]);
@ -200,14 +203,14 @@ class PartBaseType extends AbstractType
'label' => false, 'label' => false,
'entry_options' => [ 'entry_options' => [
'data_class' => PartAttachment::class, 'data_class' => PartAttachment::class,
'disabled' => !$this->security->isGranted('attachments.edit', $part), 'disabled' => ! $this->security->isGranted('attachments.edit', $part),
], ],
'by_reference' => false, 'by_reference' => false,
]); ]);
$builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [ $builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [
'required' => false, 'required' => false,
'disabled' => !$this->security->isGranted('attachments.edit', $part), 'disabled' => ! $this->security->isGranted('attachments.edit', $part),
'label' => 'part.edit.master_attachment', 'label' => 'part.edit.master_attachment',
'entity' => $part, 'entity' => $part,
]); ]);
@ -222,7 +225,7 @@ class PartBaseType extends AbstractType
'prototype_data' => new Orderdetail(), 'prototype_data' => new Orderdetail(),
'entry_options' => [ 'entry_options' => [
'measurement_unit' => $part->getPartUnit(), 'measurement_unit' => $part->getPartUnit(),
'disabled' => !$this->security->isGranted('orderdetails.edit', $part), 'disabled' => ! $this->security->isGranted('orderdetails.edit', $part),
], ],
]); ]);
@ -232,7 +235,7 @@ class PartBaseType extends AbstractType
->add('reset', ResetType::class, ['label' => 'part.edit.reset']); ->add('reset', ResetType::class, ['label' => 'part.edit.reset']);
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => Part::class, 'data_class' => Part::class,

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -43,7 +46,7 @@ class PartLotType extends AbstractType
$this->security = $security; $this->security = $security;
} }
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder->add('description', TextType::class, [ $builder->add('description', TextType::class, [
'label' => 'part_lot.edit.description', 'label' => 'part_lot.edit.description',
@ -89,7 +92,7 @@ class PartLotType extends AbstractType
]); ]);
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => PartLot::class, 'data_class' => PartLot::class,

View file

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
* *
@ -32,7 +35,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class PricedetailType extends AbstractType class PricedetailType extends AbstractType
{ {
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
//No labels needed, we define translation in templates //No labels needed, we define translation in templates
$builder->add('min_discount_quantity', SIUnitType::class, [ $builder->add('min_discount_quantity', SIUnitType::class, [
@ -57,7 +60,7 @@ class PricedetailType extends AbstractType
]); ]);
} }
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => Pricedetail::class, 'data_class' => Pricedetail::class,

Some files were not shown because too many files have changed in this diff Show more