Fixed some inspection issues.

This commit is contained in:
Jan Böhmer 2022-08-14 19:32:53 +02:00
parent eef26f7ae6
commit 639829f5c5
97 changed files with 305 additions and 185 deletions

View file

@ -46,6 +46,7 @@ use App\Services\Attachments\AttachmentManager;
use App\Services\Attachments\AttachmentPathResolver;
use App\Services\Attachments\AttachmentReverseSearch;
use IntlDateFormatter;
use Locale;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
@ -106,7 +107,7 @@ class CleanAttachmentsCommand extends Command
$table = new Table($output);
$table->setHeaders(['Filename', 'MIME Type', 'Last modified date']);
$dateformatter = IntlDateFormatter::create(\Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
$dateformatter = IntlDateFormatter::create(Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
foreach ($finder as $file) {
//If not attachment object uses this file, print it

View file

@ -65,6 +65,7 @@ use App\Services\LogSystem\EventCommentHelper;
use App\Services\LogSystem\HistoryHelper;
use App\Services\LogSystem\TimeTravel;
use App\Services\StructuralElementRecursionHelper;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Omines\DataTablesBundle\DataTableFactory;
@ -77,7 +78,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -138,17 +138,17 @@ abstract class BaseAdminController extends AbstractController
$this->entityManager = $entityManager;
}
protected function revertElementIfNeeded(AbstractDBElement $entity, ?string $timestamp): ?\DateTime
protected function revertElementIfNeeded(AbstractDBElement $entity, ?string $timestamp): ?DateTime
{
if (null !== $timestamp) {
$this->denyAccessUnlessGranted('@tools.timetravel');
$this->denyAccessUnlessGranted('show_history', $entity);
//If the timestamp only contains numbers interpret it as unix timestamp
if (ctype_digit($timestamp)) {
$timeTravel_timestamp = new \DateTime();
$timeTravel_timestamp = new DateTime();
$timeTravel_timestamp->setTimestamp((int) $timestamp);
} else { //Try to parse it via DateTime
$timeTravel_timestamp = new \DateTime($timestamp);
$timeTravel_timestamp = new DateTime($timestamp);
}
$this->timeTravel->revertEntityToTimestamp($entity, $timeTravel_timestamp);
@ -433,7 +433,8 @@ abstract class BaseAdminController extends AbstractController
$this->denyAccessUnlessGranted('delete', $entity);
if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager = $this->entityManager;
if (!$this->deleteCheck($entity)) {
return $this->redirectToRoute($this->route_base.'_edit', ['id' => $entity->getID()]);

View file

@ -68,7 +68,6 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**

View file

@ -51,6 +51,7 @@ use App\Services\EntityExporter;
use App\Services\EntityImporter;
use App\Services\StructuralElementRecursionHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -70,7 +71,7 @@ class FootprintController extends BaseAdminController
/**
* @Route("/{id}", name="footprint_delete", methods={"DELETE"})
*/
public function delete(Request $request, Footprint $entity, StructuralElementRecursionHelper $recursionHelper): \Symfony\Component\HttpFoundation\RedirectResponse
public function delete(Request $request, Footprint $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse
{
return $this->_delete($request, $entity, $recursionHelper);
}

View file

@ -55,8 +55,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authenticator\AbstractPreAuthenticatedAuthenticator;
/**
* @Route("/label_profile")
*/

View file

@ -50,6 +50,7 @@ use App\Services\EntityExporter;
use App\Services\EntityImporter;
use App\Services\StructuralElementRecursionHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -69,9 +70,9 @@ class ManufacturerController extends BaseAdminController
/**
* @Route("/{id}", name="manufacturer_delete", methods={"DELETE"})
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* @return RedirectResponse
*/
public function delete(Request $request, Manufacturer $entity, StructuralElementRecursionHelper $recursionHelper): \Symfony\Component\HttpFoundation\RedirectResponse
public function delete(Request $request, Manufacturer $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse
{
return $this->_delete($request, $entity, $recursionHelper);
}

View file

@ -51,6 +51,7 @@ use App\Services\EntityExporter;
use App\Services\EntityImporter;
use App\Services\StructuralElementRecursionHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -70,7 +71,7 @@ class MeasurementUnitController extends BaseAdminController
/**
* @Route("/{id}", name="measurement_unit_delete", methods={"DELETE"})
*/
public function delete(Request $request, MeasurementUnit $entity, StructuralElementRecursionHelper $recursionHelper): \Symfony\Component\HttpFoundation\RedirectResponse
public function delete(Request $request, MeasurementUnit $entity, StructuralElementRecursionHelper $recursionHelper): RedirectResponse
{
return $this->_delete($request, $entity, $recursionHelper);
}

View file

@ -33,6 +33,7 @@ use App\Services\ElementTypeNameGenerator;
use App\Services\LabelSystem\LabelGenerator;
use App\Services\Misc\RangeParser;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormError;
use Symfony\Component\HttpFoundation\Request;
@ -146,7 +147,7 @@ class LabelController extends AbstractController
protected function findObjects(string $type, string $ids): array
{
if (!isset(LabelGenerator::CLASS_SUPPORT_MAPPING[$type])) {
throw new \InvalidArgumentException('The given type is not known and can not be mapped to a class!');
throw new InvalidArgumentException('The given type is not known and can not be mapped to a class!');
}
$id_array = $this->rangeParser->parse($ids);

View file

@ -52,9 +52,11 @@ use App\Entity\LogSystem\ElementEditedLogEntry;
use App\Services\LogSystem\EventUndoHelper;
use App\Services\LogSystem\TimeTravel;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Omines\DataTablesBundle\DataTableFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
@ -99,7 +101,7 @@ class LogController extends AbstractController
/**
* @Route("/undo", name="log_undo", methods={"POST"})
*/
public function undoRevertLog(Request $request, EventUndoHelper $eventUndoHelper): \Symfony\Component\HttpFoundation\RedirectResponse
public function undoRevertLog(Request $request, EventUndoHelper $eventUndoHelper): RedirectResponse
{
$mode = EventUndoHelper::MODE_UNDO;
$id = $request->request->get('undo');
@ -112,7 +114,7 @@ class LogController extends AbstractController
$log_element = $this->entityManager->find(AbstractLogEntry::class, $id);
if (null === $log_element) {
throw new \InvalidArgumentException('No log entry with the given ID is existing!');
throw new InvalidArgumentException('No log entry with the given ID is existing!');
}
$this->denyAccessUnlessGranted('revert_element', $log_element->getTargetClass());

View file

@ -60,7 +60,9 @@ use App\Services\LogSystem\HistoryHelper;
use App\Services\LogSystem\TimeTravel;
use App\Services\Parameters\ParameterExtractor;
use App\Services\PricedetailHelper;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Omines\DataTablesBundle\DataTableFactory;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
@ -91,7 +93,7 @@ class PartController extends AbstractController
* @Route("/{id}/info/{timestamp}", name="part_info")
* @Route("/{id}", requirements={"id"="\d+"})
*
* @throws \Exception
* @throws Exception
*/
public function show(Part $part, Request $request, TimeTravel $timeTravel, HistoryHelper $historyHelper,
DataTableFactory $dataTable, ParameterExtractor $parameterExtractor, ?string $timestamp = null): Response
@ -104,10 +106,10 @@ class PartController extends AbstractController
$this->denyAccessUnlessGranted('show_history', $part);
//If the timestamp only contains numbers interpret it as unix timestamp
if (ctype_digit($timestamp)) {
$timeTravel_timestamp = new \DateTime();
$timeTravel_timestamp = new DateTime();
$timeTravel_timestamp->setTimestamp((int) $timestamp);
} else { //Try to parse it via DateTime
$timeTravel_timestamp = new \DateTime($timestamp);
$timeTravel_timestamp = new DateTime($timestamp);
}
$timeTravel->revertEntityToTimestamp($part, $timeTravel_timestamp);
}
@ -199,12 +201,11 @@ class PartController extends AbstractController
/**
* @Route("/{id}/delete", name="part_delete", methods={"DELETE"})
*/
public function delete(Request $request, Part $part): RedirectResponse
public function delete(Request $request, Part $part, EntityManagerInterface $entityManager): RedirectResponse
{
$this->denyAccessUnlessGranted('delete', $part);
if ($this->isCsrfTokenValid('delete'.$part->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$this->commentHelper->setMessage($request->request->get('log_comment', null));

View file

@ -27,6 +27,7 @@ use App\Form\LabelSystem\ScanDialogType;
use App\Services\LabelSystem\Barcodes\BarcodeNormalizer;
use App\Services\LabelSystem\Barcodes\BarcodeRedirector;
use Doctrine\ORM\EntityNotFoundException;
use InvalidArgumentException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -67,7 +68,7 @@ class ScanController extends AbstractController
} catch (EntityNotFoundException $exception) {
$this->addFlash('success', 'scan.qr_not_found');
}
} catch (\InvalidArgumentException $exception) {
} catch (InvalidArgumentException $exception) {
$this->addFlash('error', 'scan.format_unknown');
}
}

View file

@ -55,7 +55,9 @@ use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
@ -78,7 +80,7 @@ class SecurityController extends AbstractController
/**
* @Route("/login", name="login", methods={"GET", "POST"})
*/
public function login(AuthenticationUtils $authenticationUtils): \Symfony\Component\HttpFoundation\Response
public function login(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
@ -95,7 +97,7 @@ class SecurityController extends AbstractController
/**
* @Route("/pw_reset/request", name="pw_reset_request")
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
* @return RedirectResponse|Response
*/
public function requestPwReset(PasswordResetManager $passwordReset, Request $request)
{
@ -139,7 +141,7 @@ class SecurityController extends AbstractController
/**
* @Route("/pw_reset/new_pw/{user}/{token}", name="pw_reset_new_pw")
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
* @return RedirectResponse|Response
*/
public function pwResetNewPw(PasswordResetManager $passwordReset, Request $request, EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher, ?string $user = null, ?string $token = null)
{

View file

@ -55,6 +55,7 @@ use App\Services\EntityExporter;
use App\Services\EntityImporter;
use App\Services\StructuralElementRecursionHelper;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use InvalidArgumentException;
use Omines\DataTablesBundle\DataTableFactory;
use Symfony\Component\Asset\Packages;
@ -98,7 +99,7 @@ class UserController extends AdminPages\BaseAdminController
* @Route("/{id}/edit/{timestamp}", requirements={"id"="\d+"}, name="user_edit")
* @Route("/{id}/", requirements={"id"="\d+"})
*
* @throws \Exception
* @throws Exception
*/
public function edit(User $entity, Request $request, EntityManagerInterface $em, ?string $timestamp = null): Response
{

View file

@ -62,9 +62,9 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
use Symfony\Component\Validator\Constraints\Length;
@ -199,7 +199,7 @@ class UserSettingsController extends AbstractController
/**
* @Route("/settings", name="user_settings")
*
* @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
* @return RedirectResponse|Response
*/
public function userSettings(Request $request, EntityManagerInterface $em, UserPasswordHasherInterface $passwordEncoder, GoogleAuthenticator $googleAuthenticator, BackupCodeManager $backupCodeManager, FormFactoryInterface $formFactory)
{

View file

@ -35,6 +35,7 @@ use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
use Brick\Math\BigDecimal;
use DateTime;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
@ -80,7 +81,7 @@ class PartFixtures extends Fixture
$part->addPartLot($partLot1);
$partLot2 = new PartLot();
$partLot2->setExpirationDate(new \DateTime());
$partLot2->setExpirationDate(new DateTime());
$partLot2->setComment('Test');
$partLot2->setNeedsRefill(true);
$partLot2->setStorageLocation($manager->find(Storelocation::class, 3));

View file

@ -47,7 +47,6 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class UserFixtures extends Fixture
{

View file

@ -44,6 +44,7 @@ namespace App\DataTables\Column;
use DateTime;
use DateTimeInterface;
use Exception;
use IntlDateFormatter;
use Locale;
use Omines\DataTablesBundle\Column\AbstractColumn;
@ -58,7 +59,7 @@ class LocaleDateTimeColumn extends AbstractColumn
/**
* @param $value
* @return bool|mixed|string
* @throws \Exception
* @throws Exception
*/
public function normalize($value): string
{

View file

@ -288,7 +288,7 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface
}
/**
* @param mixed[] $assoc
* @param array $assoc
*/
private function getJoinTableName(
array $assoc,

View file

@ -180,7 +180,7 @@ abstract class Attachment extends AbstractNamedDBElement
//After the %PLACEHOLDER% comes a slash, so we can check if we have a placeholder via explode
$tmp = explode('/', $this->path);
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));
}
/**

View file

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace App\Entity\Base;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
@ -55,7 +56,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
* "user" = "App\Entity\User"
* })
*/
abstract class AbstractDBElement implements \JsonSerializable
abstract class AbstractDBElement implements JsonSerializable
{
/** @var int|null The Identification number for this part. This value is unique for the element in this table.
* Null if the element is not saved to DB yet.

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Entity\Base;
use App\Entity\Attachments\Attachment;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Entity\Base;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**

View file

@ -24,6 +24,8 @@ declare(strict_types=1);
namespace App\Entity\Contracts;
use DateTime;
interface TimeTravelInterface
{
/**
@ -41,5 +43,5 @@ interface TimeTravelInterface
/**
* Returns the the timestamp associated with this change.
*/
public function getTimestamp(): \DateTime;
public function getTimestamp(): DateTime;
}

View file

@ -64,6 +64,7 @@ use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use Psr\Log\LogLevel;
/**
@ -263,7 +264,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
public function setLevel(int $level): self
{
if ($level < 0 || $this->level > 7) {
throw new \InvalidArgumentException(sprintf('$level must be between 0 and 7! %d given!', $level));
throw new InvalidArgumentException(sprintf('$level must be between 0 and 7! %d given!', $level));
}
$this->level = $level;
@ -387,7 +388,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
final public static function levelIntToString(int $level): string
{
if (!isset(self::LEVEL_ID_TO_STRING[$level])) {
throw new \InvalidArgumentException('No level with this int is existing!');
throw new InvalidArgumentException('No level with this int is existing!');
}
return self::LEVEL_ID_TO_STRING[$level];
@ -404,7 +405,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
{
$tmp = array_flip(self::LEVEL_ID_TO_STRING);
if (!isset($tmp[$level])) {
throw new \InvalidArgumentException('No level with this string is existing!');
throw new InvalidArgumentException('No level with this string is existing!');
}
return $tmp[$level];
@ -418,7 +419,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
final public static function targetTypeIdToClass(int $type_id): string
{
if (!isset(self::TARGET_CLASS_MAPPING[$type_id])) {
throw new \InvalidArgumentException('No target type with this ID is existing!');
throw new InvalidArgumentException('No target type with this ID is existing!');
}
return self::TARGET_CLASS_MAPPING[$type_id];
@ -446,6 +447,6 @@ abstract class AbstractLogEntry extends AbstractDBElement
}
}
throw new \InvalidArgumentException('No target ID for this class is existing!');
throw new InvalidArgumentException('No target ID for this class is existing!');
}
}

View file

@ -27,6 +27,7 @@ use App\Entity\Base\AbstractDBElement;
use App\Entity\Contracts\LogWithEventUndoInterface;
use App\Entity\Contracts\NamedElementInterface;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
/**
* @ORM\Entity()
@ -104,7 +105,7 @@ class CollectionElementDeleted extends AbstractLogEntry implements LogWithEventU
} elseif ('revert' === $mode) {
$this->extra['um'] = 2;
} else {
throw new \InvalidArgumentException('Passed invalid $mode!');
throw new InvalidArgumentException('Passed invalid $mode!');
}
return $this;

View file

@ -48,6 +48,7 @@ use App\Entity\Contracts\LogWithEventUndoInterface;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
/**
* @ORM\Entity()
@ -120,7 +121,7 @@ class ElementCreatedLogEntry extends AbstractLogEntry implements LogWithCommentI
} elseif ('revert' === $mode) {
$this->extra['um'] = 2;
} else {
throw new \InvalidArgumentException('Passed invalid $mode!');
throw new InvalidArgumentException('Passed invalid $mode!');
}
return $this;

View file

@ -50,6 +50,7 @@ use App\Entity\Contracts\TimeTravelInterface;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
/**
* @ORM\Entity()
@ -153,7 +154,7 @@ class ElementDeletedLogEntry extends AbstractLogEntry implements TimeTravelInter
} elseif ('revert' === $mode) {
$this->extra['um'] = 2;
} else {
throw new \InvalidArgumentException('Passed invalid $mode!');
throw new InvalidArgumentException('Passed invalid $mode!');
}
return $this;

View file

@ -47,6 +47,7 @@ use App\Entity\Contracts\LogWithCommentInterface;
use App\Entity\Contracts\LogWithEventUndoInterface;
use App\Entity\Contracts\TimeTravelInterface;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
/**
* @ORM\Entity()
@ -157,7 +158,7 @@ class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterf
} elseif ('revert' === $mode) {
$this->extra['um'] = 2;
} else {
throw new \InvalidArgumentException('Passed invalid $mode!');
throw new InvalidArgumentException('Passed invalid $mode!');
}
return $this;

View file

@ -27,6 +27,7 @@ use App\Entity\Base\AbstractDBElement;
use App\Entity\UserSystem\User;
use App\Events\SecurityEvents;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use Symfony\Component\HttpFoundation\IpUtils;
/**
@ -60,7 +61,7 @@ class SecurityEventLogEntry extends AbstractLogEntry
public function setTargetElement(?AbstractDBElement $element): AbstractLogEntry
{
if (!$element instanceof User) {
throw new \InvalidArgumentException('Target element must be a User object!');
throw new InvalidArgumentException('Target element must be a User object!');
}
return parent::setTargetElement($element);
@ -75,7 +76,7 @@ class SecurityEventLogEntry extends AbstractLogEntry
{
$key = array_search($type, static::SECURITY_TYPE_MAPPING, true);
if (false === $key) {
throw new \InvalidArgumentException('Given event type is not existing!');
throw new InvalidArgumentException('Given event type is not existing!');
}
$this->extra['e'] = $key;

View file

@ -30,6 +30,8 @@ use InvalidArgumentException;
use LogicException;
use Symfony\Component\Validator\Constraints as Assert;
use function sprintf;
/**
* @ORM\Entity()
* @ORM\Table("parameters")
@ -376,7 +378,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement
*/
protected function formatWithUnit(float $value, string $format = '%g'): string
{
$str = \sprintf($format, $value);
$str = sprintf($format, $value);
if (!empty($this->unit)) {
return $str.' '.$this->unit;
}

View file

@ -44,6 +44,8 @@ namespace App\Entity\Parts\PartTraits;
use App\Entity\Parts\Part;
use App\Security\Annotations\ColumnSecurity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Advanced properties of a part, not related to a more specific group.

View file

@ -46,6 +46,7 @@ use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Security\Annotations\ColumnSecurity;
use App\Validator\Constraints\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
trait BasicPropertyTrait

View file

@ -46,6 +46,8 @@ use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\PartLot;
use App\Security\Annotations\ColumnSecurity;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* This trait collects all aspects of a part related to instock, part lots.

View file

@ -46,6 +46,8 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Security\Annotations\ColumnSecurity;
use App\Validator\Constraints\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* In this trait all manufacturer related properties of a part are collected (like MPN, manufacturer URL).

View file

@ -44,6 +44,7 @@ namespace App\Entity\Parts\PartTraits;
use App\Entity\PriceInformations\Orderdetail;
use App\Security\Annotations\ColumnSecurity;
use Symfony\Component\Validator\Constraints as Assert;
use function count;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

View file

@ -235,7 +235,7 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
if ($this->orderdetail && $this->orderdetail->getPart() && !$this->orderdetail->getPart()->useFloatAmount()) {
$tmp = round($this->min_discount_quantity);
return $tmp < 1 ? 1 : $tmp;
return max($tmp, 1);
}
return $this->min_discount_quantity;

View file

@ -518,8 +518,6 @@ class PermissionsEmbed
$mask = 0b11 << $n; //Mask all bits that should be written
$newval = $new << $n; //The new value.
$data = ($data & ~$mask) | ($newval & $mask);
return $data;
return ($data & ~$mask) | ($newval & $mask);
}
}

View file

@ -721,7 +721,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/
public function isGoogleAuthenticatorEnabled(): bool
{
return $this->googleAuthenticatorSecret ? true : false;
return (bool)$this->googleAuthenticatorSecret;
}
/**

View file

@ -42,7 +42,9 @@ declare(strict_types=1);
namespace App\Exceptions;
class LogEntryObsoleteException extends \RuntimeException
use RuntimeException;
class LogEntryObsoleteException extends RuntimeException
{
protected $message = 'This log entry is obsolete and exists only for compatibility reasons with old Part-DB versions. You should not use it!';
}

View file

@ -23,9 +23,10 @@ declare(strict_types=1);
namespace App\Exceptions;
use RuntimeException;
use Twig\Error\Error;
class TwigModeException extends \RuntimeException
class TwigModeException extends RuntimeException
{
public function __construct(?Error $previous = null)
{

View file

@ -25,6 +25,8 @@ namespace App\Form;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use ReflectionClass;
use ReflectionException;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormBuilder;
@ -104,12 +106,12 @@ class CollectionTypeExtension extends AbstractTypeExtension
* Set the option of the form.
* This a bit hacky cause we access private properties....
*
* @throws \ReflectionException
* @throws ReflectionException
*/
public function setOption(FormBuilder $builder, string $option, $value): void
{
//We have to use FormConfigBuilder::class here, because options is private and not available in sub classes
$reflection = new \ReflectionClass(FormConfigBuilder::class);
$reflection = new ReflectionClass(FormConfigBuilder::class);
$property = $reflection->getProperty('options');
$property->setAccessible(true);
$tmp = $property->getValue($builder);

View file

@ -47,6 +47,7 @@ use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\PriceInformations\Currency;
use App\Services\Trees\NodesListBuilder;
use Doctrine\ORM\EntityManagerInterface;
use RuntimeException;
use Symfony\Component\Intl\Currencies;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -96,7 +97,7 @@ class CurrencyEntityType extends StructuralEntityType
protected function getChoiceContent(AbstractStructuralDBElement $choice, $key, $value, $options): string
{
if(!$choice instanceof Currency) {
throw new \RuntimeException('$choice must be an instance of Currency!');
throw new RuntimeException('$choice must be an instance of Currency!');
}
//Generate the level spacing

View file

@ -45,6 +45,7 @@ namespace App\Form\Type;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Contracts\HasMasterAttachmentInterface;
use RuntimeException;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -85,7 +86,7 @@ class MasterPictureAttachmentType extends AbstractType
static function () use ($options) {
$entity = $options['entity'];
if (!$entity instanceof AttachmentContainingDBElement) {
throw new \RuntimeException('$entity must have Attachments! (be of type AttachmentContainingDBElement)');
throw new RuntimeException('$entity must have Attachments! (be of type AttachmentContainingDBElement)');
}
return $entity->getAttachments()->toArray();

View file

@ -21,6 +21,7 @@
namespace App\Helpers;
use Brick\Math\BigDecimal;
use Brick\Math\BigNumber;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
@ -36,7 +37,7 @@ class BigDecimalType extends Type
/**
* @param string|null $value
*
* @return BigDecimal|\Brick\Math\BigNumber|mixed
* @return BigDecimal|BigNumber|mixed
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{

View file

@ -23,9 +23,12 @@ declare(strict_types=1);
namespace App\Helpers;
use DateTime;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use function ord;
class LabelResponse extends Response
{
public function __construct($content = '', int $status = 200, array $headers = [])
@ -63,7 +66,7 @@ class LabelResponse extends Response
*/
public function setAutoLastModified(): LabelResponse
{
$this->setLastModified(new \DateTime());
$this->setLastModified(new DateTime());
return $this;
}
@ -95,7 +98,7 @@ class LabelResponse extends Response
for ($i = 0, $filenameLength = mb_strlen($filename, $encoding); $i < $filenameLength; ++$i) {
$char = mb_substr($filename, $i, 1, $encoding);
if ('%' === $char || \ord($char) < 32 || \ord($char) > 126) {
if ('%' === $char || ord($char) < 32 || ord($char) > 126) {
$filenameFallback .= '_';
} else {
$filenameFallback .= $char;

View file

@ -45,6 +45,7 @@ namespace App\Helpers\Trees;
use App\Entity\Base\AbstractStructuralDBElement;
use ArrayIterator;
use Doctrine\Common\Collections\Collection;
use InvalidArgumentException;
use RecursiveIterator;
final class StructuralDBElementIterator extends ArrayIterator implements RecursiveIterator
@ -73,7 +74,7 @@ final class StructuralDBElementIterator extends ArrayIterator implements Recursi
} elseif ($subelements instanceof Collection) {
$array = $subelements->toArray();
} else {
throw new \InvalidArgumentException('Invalid subelements type on $element!');
throw new InvalidArgumentException('Invalid subelements type on $element!');
}
return new self($array);

View file

@ -23,6 +23,7 @@ namespace App\Repository;
use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Base\PartsContainingRepositoryInterface;
use App\Entity\Parts\Part;
use InvalidArgumentException;
abstract class AbstractPartsContainingRepository extends StructuralDBElementRepository implements PartsContainingRepositoryInterface
{
@ -46,7 +47,7 @@ abstract class AbstractPartsContainingRepository extends StructuralDBElementRepo
protected function getPartsByField(object $element, array $order_by, string $field_name): array
{
if (!$element instanceof AbstractPartsContainingDBElement) {
throw new \InvalidArgumentException('$element must be an instance of AbstractPartContainingDBElement!');
throw new InvalidArgumentException('$element must be an instance of AbstractPartContainingDBElement!');
}
$repo = $this->getEntityManager()->getRepository(Part::class);
@ -57,7 +58,7 @@ abstract class AbstractPartsContainingRepository extends StructuralDBElementRepo
protected function getPartsCountByField(object $element, string $field_name): int
{
if (!$element instanceof AbstractPartsContainingDBElement) {
throw new \InvalidArgumentException('$element must be an instance of AbstractPartContainingDBElement!');
throw new InvalidArgumentException('$element must be an instance of AbstractPartContainingDBElement!');
}
$repo = $this->getEntityManager()->getRepository(Part::class);

View file

@ -23,6 +23,9 @@ declare(strict_types=1);
namespace App\Repository;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
class AttachmentRepository extends DBElementRepository
{
/**
@ -42,8 +45,8 @@ class AttachmentRepository extends DBElementRepository
/**
* Gets the count of all external attachments (attachments only containing an URL).
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws NoResultException
* @throws NonUniqueResultException
*/
public function getExternalAttachments(): int
{
@ -61,8 +64,8 @@ class AttachmentRepository extends DBElementRepository
/**
* Gets the count of all attachments where an user uploaded an file.
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws NoResultException
* @throws NonUniqueResultException
*/
public function getUserUploadedAttachments(): int
{

View file

@ -25,6 +25,7 @@ namespace App\Repository;
use App\Entity\Base\AbstractDBElement;
use Doctrine\ORM\EntityRepository;
use ReflectionClass;
class DBElementRepository extends EntityRepository
{
@ -68,7 +69,7 @@ class DBElementRepository extends EntityRepository
protected function setField(AbstractDBElement $element, string $field, int $new_value): void
{
$reflection = new \ReflectionClass(get_class($element));
$reflection = new ReflectionClass(get_class($element));
$property = $reflection->getProperty($field);
$property->setAccessible(true);
$property->setValue($element, $new_value);

View file

@ -26,6 +26,7 @@ namespace App\Repository;
use App\Entity\LabelSystem\LabelOptions;
use App\Entity\LabelSystem\LabelProfile;
use App\Helpers\Trees\TreeViewNode;
use InvalidArgumentException;
class LabelProfileRepository extends NamedDBElementRepository
{
@ -36,7 +37,7 @@ class LabelProfileRepository extends NamedDBElementRepository
public function getDropdownProfiles(string $type): array
{
if (!in_array($type, LabelOptions::SUPPORTED_ELEMENTS, true)) {
throw new \InvalidArgumentException('Invalid supported_element type given.');
throw new InvalidArgumentException('Invalid supported_element type given.');
}
return $this->findBy([
@ -85,7 +86,7 @@ class LabelProfileRepository extends NamedDBElementRepository
public function findForSupportedElement(string $type, array $order_by = ['name' => 'ASC']): array
{
if (!in_array($type, LabelOptions::SUPPORTED_ELEMENTS, true)) {
throw new \InvalidArgumentException('Invalid supported_element type given.');
throw new InvalidArgumentException('Invalid supported_element type given.');
}
return $this->findBy(['options.supported_element' => $type], $order_by);

View file

@ -49,6 +49,11 @@ use App\Entity\LogSystem\ElementCreatedLogEntry;
use App\Entity\LogSystem\ElementDeletedLogEntry;
use App\Entity\LogSystem\ElementEditedLogEntry;
use App\Entity\UserSystem\User;
use DateTime;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\TransactionRequiredException;
use RuntimeException;
class LogEntryRepository extends DBElementRepository
{
@ -108,7 +113,7 @@ class LogEntryRepository extends DBElementRepository
$results = $query->execute();
if (empty($results)) {
throw new \RuntimeException('No undelete data could be found for this element');
throw new RuntimeException('No undelete data could be found for this element');
}
return $results[0];
@ -118,11 +123,11 @@ class LogEntryRepository extends DBElementRepository
* Gets all log entries that are related to time travelling.
*
* @param AbstractDBElement $element The element for which the time travel data should be retrieved
* @param \DateTime $until Back to which timestamp should the data be get (including the timestamp)
* @param DateTime $until Back to which timestamp should the data be get (including the timestamp)
*
* @return AbstractLogEntry[]
*/
public function getTimetravelDataForElement(AbstractDBElement $element, \DateTime $until): array
public function getTimetravelDataForElement(AbstractDBElement $element, DateTime $until): array
{
$qb = $this->createQueryBuilder('log');
$qb->select('log')
@ -150,7 +155,7 @@ class LogEntryRepository extends DBElementRepository
*
* @return bool True if the element existed at the given timestamp
*/
public function getElementExistedAtTimestamp(AbstractDBElement $element, \DateTime $timestamp): bool
public function getElementExistedAtTimestamp(AbstractDBElement $element, DateTime $timestamp): bool
{
$qb = $this->createQueryBuilder('log');
$qb->select('count(log)')
@ -190,9 +195,9 @@ class LogEntryRepository extends DBElementRepository
* @return AbstractDBElement|null returns the associated DBElement or null if the log either has no target or the element
* was deleted from DB
*
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\OptimisticLockException
* @throws \Doctrine\ORM\TransactionRequiredException
* @throws ORMException
* @throws OptimisticLockException
* @throws TransactionRequiredException
*/
public function getTargetElement(AbstractLogEntry $logEntry): ?AbstractDBElement
{

View file

@ -43,6 +43,8 @@ declare(strict_types=1);
namespace App\Repository;
use App\Entity\Parts\PartLot;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Doctrine\ORM\QueryBuilder;
class PartRepository extends NamedDBElementRepository
@ -50,8 +52,8 @@ class PartRepository extends NamedDBElementRepository
/**
* Gets the summed up instock of all parts (only parts without an measurent unit).
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws NoResultException
* @throws NonUniqueResultException
*/
public function getPartsInstockSum(): float
{
@ -69,8 +71,8 @@ class PartRepository extends NamedDBElementRepository
/**
* Gets the number of parts that has price informations.
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws NoResultException
* @throws NonUniqueResultException
*/
public function getPartsCountWithPrice(): int
{

View file

@ -22,13 +22,14 @@ namespace App\Repository\Parts;
use App\Entity\Parts\Category;
use App\Repository\AbstractPartsContainingRepository;
use InvalidArgumentException;
class CategoryRepository extends AbstractPartsContainingRepository
{
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
{
if (!$element instanceof Category) {
throw new \InvalidArgumentException('$element must be an Category!');
throw new InvalidArgumentException('$element must be an Category!');
}
return $this->getPartsByField($element, $order_by, 'category');
@ -37,7 +38,7 @@ class CategoryRepository extends AbstractPartsContainingRepository
public function getPartsCount(object $element): int
{
if (!$element instanceof Category) {
throw new \InvalidArgumentException('$element must be an Category!');
throw new InvalidArgumentException('$element must be an Category!');
}
return $this->getPartsCountByField($element, 'category');

View file

@ -9,6 +9,7 @@ use App\Entity\Devices\Device;
use App\Entity\Parts\Category;
use App\Entity\Parts\Part;
use App\Repository\AbstractPartsContainingRepository;
use InvalidArgumentException;
class DeviceRepository extends AbstractPartsContainingRepository
{
@ -16,7 +17,7 @@ class DeviceRepository extends AbstractPartsContainingRepository
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
{
if (!$element instanceof Device) {
throw new \InvalidArgumentException('$element must be an Device!');
throw new InvalidArgumentException('$element must be an Device!');
}
@ -27,7 +28,7 @@ class DeviceRepository extends AbstractPartsContainingRepository
public function getPartsCount(object $element): int
{
if (!$element instanceof Device) {
throw new \InvalidArgumentException('$element must be an Device!');
throw new InvalidArgumentException('$element must be an Device!');
}
//TODO: Change this later, when properly implemented devices

View file

@ -22,13 +22,14 @@ namespace App\Repository\Parts;
use App\Entity\Parts\Footprint;
use App\Repository\AbstractPartsContainingRepository;
use InvalidArgumentException;
class FootprintRepository extends AbstractPartsContainingRepository
{
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
{
if (!$element instanceof Footprint) {
throw new \InvalidArgumentException('$element must be an Footprint!');
throw new InvalidArgumentException('$element must be an Footprint!');
}
return $this->getPartsByField($element, $order_by, 'footprint');
@ -37,7 +38,7 @@ class FootprintRepository extends AbstractPartsContainingRepository
public function getPartsCount(object $element): int
{
if (!$element instanceof Footprint) {
throw new \InvalidArgumentException('$element must be an Footprint!');
throw new InvalidArgumentException('$element must be an Footprint!');
}
return $this->getPartsCountByField($element, 'footprint');

View file

@ -22,13 +22,14 @@ namespace App\Repository\Parts;
use App\Entity\Parts\Manufacturer;
use App\Repository\AbstractPartsContainingRepository;
use InvalidArgumentException;
class ManufacturerRepository extends AbstractPartsContainingRepository
{
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
{
if (!$element instanceof Manufacturer) {
throw new \InvalidArgumentException('$element must be an Manufacturer!');
throw new InvalidArgumentException('$element must be an Manufacturer!');
}
return $this->getPartsByField($element, $order_by, 'manufacturer');
@ -37,7 +38,7 @@ class ManufacturerRepository extends AbstractPartsContainingRepository
public function getPartsCount(object $element): int
{
if (!$element instanceof Manufacturer) {
throw new \InvalidArgumentException('$element must be an Manufacturer!');
throw new InvalidArgumentException('$element must be an Manufacturer!');
}
return $this->getPartsCountByField($element, 'manufacturer');

View file

@ -22,13 +22,14 @@ namespace App\Repository\Parts;
use App\Entity\Parts\MeasurementUnit;
use App\Repository\AbstractPartsContainingRepository;
use InvalidArgumentException;
class MeasurementUnitRepository extends AbstractPartsContainingRepository
{
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
{
if (!$element instanceof MeasurementUnit) {
throw new \InvalidArgumentException('$element must be an MeasurementUnit!');
throw new InvalidArgumentException('$element must be an MeasurementUnit!');
}
return $this->getPartsByField($element, $order_by, 'partUnit');
@ -37,7 +38,7 @@ class MeasurementUnitRepository extends AbstractPartsContainingRepository
public function getPartsCount(object $element): int
{
if (!$element instanceof MeasurementUnit) {
throw new \InvalidArgumentException('$element must be an MeasurementUnit!');
throw new InvalidArgumentException('$element must be an MeasurementUnit!');
}
return $this->getPartsCountByField($element, 'partUnit');

View file

@ -24,6 +24,7 @@ use App\Entity\Parts\Part;
use App\Entity\Parts\Storelocation;
use App\Repository\AbstractPartsContainingRepository;
use Doctrine\ORM\QueryBuilder;
use InvalidArgumentException;
class StorelocationRepository extends AbstractPartsContainingRepository
{
@ -33,7 +34,7 @@ class StorelocationRepository extends AbstractPartsContainingRepository
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
{
if (!$element instanceof Storelocation) {
throw new \InvalidArgumentException('$element must be an Storelocation!');
throw new InvalidArgumentException('$element must be an Storelocation!');
}
$qb = new QueryBuilder($this->getEntityManager());
@ -54,7 +55,7 @@ class StorelocationRepository extends AbstractPartsContainingRepository
public function getPartsCount(object $element): int
{
if (!$element instanceof Storelocation) {
throw new \InvalidArgumentException('$element must be an Storelocation!');
throw new InvalidArgumentException('$element must be an Storelocation!');
}
$qb = new QueryBuilder($this->getEntityManager());

View file

@ -24,13 +24,14 @@ use App\Entity\Parts\Part;
use App\Entity\Parts\Supplier;
use App\Repository\AbstractPartsContainingRepository;
use Doctrine\ORM\QueryBuilder;
use InvalidArgumentException;
class SupplierRepository extends AbstractPartsContainingRepository
{
public function getParts(object $element, array $order_by = ['name' => 'ASC']): array
{
if (!$element instanceof Supplier) {
throw new \InvalidArgumentException('$element must be an Supplier!');
throw new InvalidArgumentException('$element must be an Supplier!');
}
$qb = new QueryBuilder($this->getEntityManager());
@ -51,7 +52,7 @@ class SupplierRepository extends AbstractPartsContainingRepository
public function getPartsCount(object $element): int
{
if (!$element instanceof Supplier) {
throw new \InvalidArgumentException('$element must be an Supplier!');
throw new InvalidArgumentException('$element must be an Supplier!');
}
$qb = new QueryBuilder($this->getEntityManager());

View file

@ -63,6 +63,7 @@ use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Exceptions\EntityNotSupportedException;
use App\Services\Attachments\AttachmentURLGenerator;
use DateTime;
use function array_key_exists;
use function get_class;
use InvalidArgumentException;
@ -128,7 +129,7 @@ class EntityURLGenerator
/**
* Gets the URL to view the given element at a given timestamp.
*/
public function timeTravelURL(AbstractDBElement $entity, \DateTime $dateTime): string
public function timeTravelURL(AbstractDBElement $entity, DateTime $dateTime): string
{
$map = [
Part::class => 'part_info',

View file

@ -26,6 +26,7 @@ namespace App\Services\LabelSystem;
use App\Entity\LabelSystem\LabelOptions;
use App\Services\LabelSystem\Barcodes\BarcodeContentGenerator;
use Com\Tecnick\Barcode\Barcode;
use InvalidArgumentException;
final class BarcodeGenerator
{
@ -64,7 +65,7 @@ final class BarcodeGenerator
case 'none':
return null;
default:
throw new \InvalidArgumentException('Unknown label type!');
throw new InvalidArgumentException('Unknown label type!');
}
$bobj = $barcode->getBarcodeObj($type, $this->getContent($options, $target));
@ -85,7 +86,7 @@ final class BarcodeGenerator
case 'none':
return null;
default:
throw new \InvalidArgumentException('Unknown label type!');
throw new InvalidArgumentException('Unknown label type!');
}
}
}

View file

@ -27,6 +27,7 @@ use App\Entity\Base\AbstractDBElement;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use InvalidArgumentException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
final class BarcodeContentGenerator
@ -88,6 +89,6 @@ final class BarcodeContentGenerator
}
}
throw new \InvalidArgumentException('Unknown object class '.get_class($target));
throw new InvalidArgumentException('Unknown object class '.get_class($target));
}
}

View file

@ -30,6 +30,9 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use DateTime;
use InvalidArgumentException;
use ReflectionClass;
final class BarcodeExampleElementsGenerator
{
@ -43,7 +46,7 @@ final class BarcodeExampleElementsGenerator
case 'storelocation':
return $this->getStorelocation();
default:
throw new \InvalidArgumentException('Unknown $type.');
throw new InvalidArgumentException('Unknown $type.');
}
}
@ -78,7 +81,7 @@ final class BarcodeExampleElementsGenerator
$lot->setDescription('Example Lot');
$lot->setComment('Lot comment');
$lot->setExpirationDate(new \DateTime('+1 days'));
$lot->setExpirationDate(new DateTime('+1 days'));
$lot->setStorageLocation($this->getStructuralData(Storelocation::class));
$lot->setAmount(123);
@ -103,7 +106,7 @@ final class BarcodeExampleElementsGenerator
private function getStructuralData(string $class): AbstractStructuralDBElement
{
if (!is_a($class, AbstractStructuralDBElement::class, true)) {
throw new \InvalidArgumentException('$class must be an child of AbstractStructuralDBElement');
throw new InvalidArgumentException('$class must be an child of AbstractStructuralDBElement');
}
/** @var AbstractStructuralDBElement $parent */
@ -112,7 +115,7 @@ final class BarcodeExampleElementsGenerator
/** @var AbstractStructuralDBElement $child */
$child = new $class();
$child->setName((new \ReflectionClass($class))->getShortName());
$child->setName((new ReflectionClass($class))->getShortName());
$child->setParent($parent);
return $child;

View file

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace App\Services\LabelSystem\Barcodes;
use InvalidArgumentException;
final class BarcodeNormalizer
{
private const PREFIX_TYPE_MAP = [
@ -54,7 +56,7 @@ final class BarcodeNormalizer
$id = (int) $matches[2];
if (!isset(self::PREFIX_TYPE_MAP[$prefix])) {
throw new \InvalidArgumentException('Unknown prefix '.$prefix);
throw new InvalidArgumentException('Unknown prefix '.$prefix);
}
return [self::PREFIX_TYPE_MAP[$prefix], $id];
@ -66,7 +68,7 @@ final class BarcodeNormalizer
$id = (int) $matches[2];
if (!isset(self::PREFIX_TYPE_MAP[$prefix])) {
throw new \InvalidArgumentException('Unknown prefix '.$prefix);
throw new InvalidArgumentException('Unknown prefix '.$prefix);
}
return [self::PREFIX_TYPE_MAP[$prefix], $id];
@ -82,6 +84,6 @@ final class BarcodeNormalizer
return ['part', (int) $matches[1]];
}
throw new \InvalidArgumentException('Unknown barcode format!');
throw new InvalidArgumentException('Unknown barcode format!');
}
}

View file

@ -26,6 +26,7 @@ namespace App\Services\LabelSystem\Barcodes;
use App\Entity\Parts\PartLot;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityNotFoundException;
use InvalidArgumentException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
final class BarcodeRedirector
@ -67,7 +68,7 @@ final class BarcodeRedirector
return $this->urlGenerator->generate('part_list_store_location', ['id' => $id]);
default:
throw new \InvalidArgumentException('Unknown $type: '.$type);
throw new InvalidArgumentException('Unknown $type: '.$type);
}
}
}

View file

@ -28,6 +28,7 @@ use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use Dompdf\Dompdf;
use InvalidArgumentException;
final class LabelGenerator
{
@ -52,7 +53,7 @@ final class LabelGenerator
public function generateLabel(LabelOptions $options, $elements): string
{
if (!is_array($elements) && !is_object($elements)) {
throw new \InvalidArgumentException('$element must be an object or an array of objects!');
throw new InvalidArgumentException('$element must be an object or an array of objects!');
}
if (!is_array($elements)) {
@ -61,7 +62,7 @@ final class LabelGenerator
foreach ($elements as $element) {
if (!$this->supports($options, $element)) {
throw new \InvalidArgumentException('The given options are not compatible with the given element!');
throw new InvalidArgumentException('The given options are not compatible with the given element!');
}
}
@ -80,7 +81,7 @@ final class LabelGenerator
{
$supported_type = $options->getSupportedElement();
if (!isset(static::CLASS_SUPPORT_MAPPING[$supported_type])) {
throw new \InvalidArgumentException('Supported type name of the Label options not known!');
throw new InvalidArgumentException('Supported type name of the Label options not known!');
}
return is_a($element, static::CLASS_SUPPORT_MAPPING[$supported_type]);

View file

@ -27,6 +27,7 @@ use App\Entity\Contracts\NamedElementInterface;
use App\Entity\LabelSystem\LabelOptions;
use App\Exceptions\TwigModeException;
use App\Services\ElementTypeNameGenerator;
use InvalidArgumentException;
use Symfony\Component\Security\Core\Security;
use Twig\Environment;
use Twig\Error\Error;
@ -56,7 +57,7 @@ final class LabelHTMLGenerator
public function getLabelHTML(LabelOptions $options, array $elements): string
{
if (empty($elements)) {
throw new \InvalidArgumentException('$elements must not be empty');
throw new InvalidArgumentException('$elements must not be empty');
}
$twig_elements = [];

View file

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\UserSystem\User;
use DateTime;
use IntlDateFormatter;
use Locale;
use Symfony\Component\Security\Core\Security;
@ -65,7 +66,7 @@ final class GlobalProviders implements PlaceholderProviderInterface
return 'anonymous';
}
$now = new \DateTime();
$now = new DateTime();
if ('[[DATETIME]]' === $placeholder) {
$formatter = IntlDateFormatter::create(

View file

@ -25,6 +25,7 @@ namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Parts\Part;
use App\Services\SIFormatter;
use Parsedown;
use Symfony\Contracts\Translation\TranslatorInterface;
final class PartProvider implements PlaceholderProviderInterface
@ -88,7 +89,7 @@ final class PartProvider implements PlaceholderProviderInterface
return $this->translator->trans('m_status.'.$part->getManufacturingStatus());
}
$parsedown = new \Parsedown();
$parsedown = new Parsedown();
if ('[[DESCRIPTION]]' === $placeholder) {
return $parsedown->line($part->getDescription());

View file

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Services\LabelSystem\PlaceholderProviders;
use App\Entity\Contracts\TimeStampableInterface;
use DateTime;
use IntlDateFormatter;
use Locale;
@ -35,11 +36,11 @@ final class TimestampableElementProvider implements PlaceholderProviderInterface
$formatter = new IntlDateFormatter(Locale::getDefault(), IntlDateFormatter::SHORT, IntlDateFormatter::SHORT);
if ('[[LAST_MODIFIED]]' === $placeholder) {
return $formatter->format($label_target->getLastModified() ?? new \DateTime());
return $formatter->format($label_target->getLastModified() ?? new DateTime());
}
if ('[[CREATION_DATE]]' === $placeholder) {
return $formatter->format($label_target->getAddedDate() ?? new \DateTime());
return $formatter->format($label_target->getAddedDate() ?? new DateTime());
}
}

View file

@ -43,9 +43,11 @@ use App\Entity\PriceInformations\Pricedetail;
use App\Entity\UserSystem\User;
use App\Twig\AppExtension;
use App\Twig\Sandbox\InheritanceSecurityPolicy;
use InvalidArgumentException;
use Twig\Environment;
use Twig\Extension\SandboxExtension;
use Twig\Extra\Intl\IntlExtension;
use Twig\Loader\ArrayLoader;
use Twig\Sandbox\SecurityPolicyInterface;
final class SandboxedTwigProvider
@ -104,10 +106,10 @@ final class SandboxedTwigProvider
public function getTwig(LabelOptions $options): Environment
{
if ('twig' !== $options->getLinesMode()) {
throw new \InvalidArgumentException('The LabelOptions must explicitly allow twig via lines_mode = "twig"!');
throw new InvalidArgumentException('The LabelOptions must explicitly allow twig via lines_mode = "twig"!');
}
$loader = new \Twig\Loader\ArrayLoader([
$loader = new ArrayLoader([
'lines' => $options->getLines(),
]);
$twig = new Environment($loader);

View file

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace App\Services\LogSystem;
use App\Entity\LogSystem\AbstractLogEntry;
use InvalidArgumentException;
class EventUndoHelper
{
@ -44,7 +45,7 @@ class EventUndoHelper
public function setMode(string $mode): void
{
if (!in_array($mode, self::ALLOWED_MODES, true)) {
throw new \InvalidArgumentException('Invalid mode passed!');
throw new InvalidArgumentException('Invalid mode passed!');
}
$this->mode = $mode;
}

View file

@ -26,6 +26,7 @@ namespace App\Services\LogSystem;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parts\Part;
class HistoryHelper
@ -38,7 +39,7 @@ class HistoryHelper
* Returns an array containing all elements that are associated with the argument.
* The returned array contains the given element.
*
* @psalm-return array<\App\Entity\Parameters\AbstractParameter|array-key, mixed>
* @psalm-return array<AbstractParameter|array-key, mixed>
*/
public function getAssociatedElements(AbstractDBElement $element): array
{

View file

@ -33,9 +33,14 @@ use App\Entity\LogSystem\AbstractLogEntry;
use App\Entity\LogSystem\CollectionElementDeleted;
use App\Entity\LogSystem\ElementEditedLogEntry;
use Brick\Math\BigDecimal;
use DateTime;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\MappingException;
use Exception;
use InvalidArgumentException;
use ReflectionClass;
class TimeTravel
{
@ -74,16 +79,16 @@ class TimeTravel
*
* @param AbstractLogEntry[] $reverted_elements
*
* @throws \Exception
* @throws Exception
*/
public function revertEntityToTimestamp(AbstractDBElement $element, \DateTime $timestamp, array $reverted_elements = []): void
public function revertEntityToTimestamp(AbstractDBElement $element, DateTime $timestamp, array $reverted_elements = []): void
{
if (!$element instanceof TimeStampableInterface) {
throw new \InvalidArgumentException('$element must have a Timestamp!');
throw new InvalidArgumentException('$element must have a Timestamp!');
}
if ($timestamp > new \DateTime('now')) {
throw new \InvalidArgumentException('You can not travel to the future (yet)...');
if ($timestamp > new DateTime('now')) {
throw new InvalidArgumentException('You can not travel to the future (yet)...');
}
//Skip this process if already were reverted...
@ -168,7 +173,7 @@ class TimeTravel
/**
* Apply the changeset in the given LogEntry to the element.
*
* @throws \Doctrine\ORM\Mapping\MappingException
* @throws MappingException
*/
public function applyEntry(AbstractDBElement $element, TimeTravelInterface $logEntry): void
{
@ -207,7 +212,7 @@ class TimeTravel
protected function getField(AbstractDBElement $element, string $field)
{
$reflection = new \ReflectionClass(get_class($element));
$reflection = new ReflectionClass(get_class($element));
$property = $reflection->getProperty($field);
$property->setAccessible(true);
@ -215,11 +220,11 @@ class TimeTravel
}
/**
* @param \DateTime|int|null $new_value
* @param DateTime|int|null $new_value
*/
protected function setField(AbstractDBElement $element, string $field, $new_value): void
{
$reflection = new \ReflectionClass(get_class($element));
$reflection = new ReflectionClass(get_class($element));
$property = $reflection->getProperty($field);
$property->setAccessible(true);

View file

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace App\Services\Misc;
use InvalidArgumentException;
/**
* This Parser allows to parse number ranges like 1-3, 4, 5.
*/
@ -53,7 +55,7 @@ class RangeParser
} elseif (empty($number)) { //Allow empty tokens
continue;
} else {
throw new \InvalidArgumentException('Invalid range encoutered: '.$number);
throw new InvalidArgumentException('Invalid range encoutered: '.$number);
}
}
@ -74,7 +76,7 @@ class RangeParser
$this->parse($range_str);
return true;
} catch (\InvalidArgumentException $exception) {
} catch (InvalidArgumentException $exception) {
return false;
}
}

View file

@ -74,9 +74,9 @@ class MoneyFormatter
$number_formatter = new NumberFormatter($this->locale, NumberFormatter::CURRENCY);
if ($show_all_digits) {
$number_formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $decimals);
$number_formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $decimals);
} else {
$number_formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
$number_formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
}
return $number_formatter->formatCurrency((float) $value, $iso_code);

View file

@ -25,6 +25,9 @@ namespace App\Services\Parameters;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parameters\PartParameter;
use InvalidArgumentException;
use function preg_match;
class ParameterExtractor
{
@ -41,7 +44,7 @@ class ParameterExtractor
public function extractParameters(string $input, string $class = PartParameter::class): array
{
if (!is_a($class, AbstractParameter::class, true)) {
throw new \InvalidArgumentException('$class must be a child class of AbstractParameter!');
throw new InvalidArgumentException('$class must be a child class of AbstractParameter!');
}
//Restrict search length
@ -67,7 +70,7 @@ class ParameterExtractor
$regex = '/^(.*) *(?:=|:) *(.+)/u';
$matches = [];
\preg_match($regex, $input, $matches);
preg_match($regex, $input, $matches);
if (!empty($matches)) {
[, $name, $value] = $matches;
$value = trim($value);

View file

@ -28,6 +28,7 @@ use App\Entity\Parts\Part;
use App\Repository\DBElementRepository;
use App\Repository\PartRepository;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Security;
@ -67,7 +68,7 @@ final class PartsTableActionHandler
//Iterate over the parts and apply the action to it:
foreach ($selected_parts as $part) {
if (!$part instanceof Part) {
throw new \InvalidArgumentException('$selected_parts must be an array of Part elements!');
throw new InvalidArgumentException('$selected_parts must be an array of Part elements!');
}
//We modify parts, so you have to have the permission to modify it
@ -102,7 +103,7 @@ final class PartsTableActionHandler
break;
default:
throw new \InvalidArgumentException('The given action is unknown! ('.$action.')');
throw new InvalidArgumentException('The given action is unknown! ('.$action.')');
}
}
}

View file

@ -43,15 +43,14 @@ declare(strict_types=1);
namespace App\Services;
use App\Entity\UserSystem\User;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class PasswordResetManager
@ -88,7 +87,7 @@ class PasswordResetManager
$user->setPwResetToken($this->passwordEncoder->hash($unencrypted_token, null));
//Determine the expiration datetime of
$expiration_date = new \DateTime();
$expiration_date = new DateTime();
$expiration_date->add(date_interval_create_from_date_string('1 day'));
$user->setPwResetExpires($expiration_date);
@ -135,7 +134,7 @@ class PasswordResetManager
}
//Check if token is expired yet
if ($user->getPwResetExpires() < new \DateTime()) {
if ($user->getPwResetExpires() < new DateTime()) {
return false;
}
@ -149,7 +148,7 @@ class PasswordResetManager
//Remove token
$user->setPwResetToken(null);
$user->setPwResetExpires(new \DateTime());
$user->setPwResetExpires(new DateTime());
//Save to DB
$this->em->flush();

View file

@ -46,6 +46,7 @@ use App\Configuration\PermissionsConfiguration;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Security\Interfaces\HasPermissionsInterface;
use InvalidArgumentException;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Resource\FileResource;
@ -172,7 +173,7 @@ class PermissionResolver
public function listOperationsForPermission(string $permission): array
{
if (!$this->isValidPermission($permission)) {
throw new \InvalidArgumentException(sprintf('A permission with that name is not existing! Got %s.', $permission));
throw new InvalidArgumentException(sprintf('A permission with that name is not existing! Got %s.', $permission));
}
$operations = $this->permission_structure['perms'][$permission]['operations'];

View file

@ -50,6 +50,8 @@ use Brick\Math\RoundingMode;
use Doctrine\ORM\PersistentCollection;
use Locale;
use function count;
class PricedetailHelper
{
protected $base_currency;
@ -74,7 +76,7 @@ class PricedetailHelper
foreach ($orderdetails as $orderdetail) {
$pricedetails = $orderdetail->getPricedetails();
//The orderdetail must have pricedetails, otherwise this will not work!
if (0 === \count($pricedetails)) {
if (0 === count($pricedetails)) {
continue;
}
@ -121,7 +123,7 @@ class PricedetailHelper
foreach ($orderdetails as $orderdetail) {
$pricedetails = $orderdetail->getPricedetails();
//The orderdetail must have pricedetails, otherwise this will not work!
if (0 === \count($pricedetails)) {
if (0 === count($pricedetails)) {
continue;
}

View file

@ -36,6 +36,9 @@ use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use InvalidArgumentException;
class StatisticsHelper
{
@ -61,8 +64,8 @@ class StatisticsHelper
/**
* Returns the summed instocked over all parts (only parts without a measurement unit).
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws NoResultException
* @throws NonUniqueResultException
*/
public function getPartsInstockSum(): float
{
@ -72,8 +75,8 @@ class StatisticsHelper
/**
* Returns the number of all parts which have price informations.
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws NoResultException
* @throws NonUniqueResultException
*/
public function getPartsCountWithPrice(): int
{
@ -98,7 +101,7 @@ class StatisticsHelper
];
if (!isset($arr[$type])) {
throw new \InvalidArgumentException('No count for the given type available!');
throw new InvalidArgumentException('No count for the given type available!');
}
/** @var EntityRepository $repo */
@ -126,8 +129,8 @@ class StatisticsHelper
/**
* Gets the count of all external (only containing an URL) attachments.
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws NoResultException
* @throws NonUniqueResultException
*/
public function getExternalAttachmentsCount(): int
{
@ -137,8 +140,8 @@ class StatisticsHelper
/**
* Gets the count of all attachments where the user uploaded an file.
*
* @throws \Doctrine\ORM\NoResultException
* @throws \Doctrine\ORM\NonUniqueResultException
* @throws NoResultException
* @throws NonUniqueResultException
*/
public function getUserUploadedAttachmentsCount(): int
{

View file

@ -42,6 +42,9 @@ declare(strict_types=1);
namespace App\Services\TFA;
use Exception;
use RuntimeException;
/**
* This class generates random backup codes for two factor authentication.
*/
@ -59,10 +62,10 @@ class BackupCodeGenerator
public function __construct(int $code_length, int $code_count)
{
if ($code_length > 32) {
throw new \RuntimeException('Backup code can have maximum 32 digits!');
throw new RuntimeException('Backup code can have maximum 32 digits!');
}
if ($code_length < 6) {
throw new \RuntimeException('Code must have at least 6 digits to ensure security!');
throw new RuntimeException('Code must have at least 6 digits to ensure security!');
}
$this->code_count = $code_count;
@ -75,7 +78,7 @@ class BackupCodeGenerator
*
* @return string The generated backup code (e.g. 1f3870be2)
*
* @throws \Exception if no entropy source is available
* @throws Exception if no entropy source is available
*/
public function generateSingleCode(): string
{

View file

@ -46,6 +46,8 @@ use App\Entity\Parts\Part;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use function array_slice;
/**
* A service related for searching for tags. Mostly useful for autocomplete reasons.
*/
@ -101,7 +103,7 @@ class TagFinder
$results = array_unique($results);
//Limit the returned tag count to specified value.
return \array_slice($results, 0, $options['return_limit']);
return array_slice($results, 0, $options['return_limit']);
}
protected function configureOptions(OptionsResolver $resolver): void

View file

@ -59,10 +59,14 @@ use App\Services\EntityURLGenerator;
use App\Services\MarkdownParser;
use App\Services\UserCacheKeyGenerator;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
use RecursiveIteratorIterator;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\Contracts\Cache\TagAwareCacheInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function count;
class TreeViewGenerator
{
protected $urlGenerator;
@ -131,7 +135,7 @@ class TreeViewGenerator
$generic = $this->getGenericTree($class, $parent);
$treeIterator = new TreeViewNodeIterator($generic);
$recursiveIterator = new \RecursiveIteratorIterator($treeIterator, \RecursiveIteratorIterator::SELF_FIRST);
$recursiveIterator = new RecursiveIteratorIterator($treeIterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($recursiveIterator as $item) {
/** @var TreeViewNode $item */
if (null !== $selectedElement && $item->getId() === $selectedElement->getID()) {
@ -139,7 +143,7 @@ class TreeViewGenerator
}
if (!empty($item->getNodes())) {
$item->addTag((string) \count($item->getNodes()));
$item->addTag((string) count($item->getNodes()));
}
if (!empty($href_type) && null !== $item->getId()) {
@ -218,10 +222,10 @@ class TreeViewGenerator
public function getGenericTree(string $class, ?AbstractStructuralDBElement $parent = null): array
{
if (!is_a($class, AbstractNamedDBElement::class, true)) {
throw new \InvalidArgumentException('$class must be a class string that implements StructuralDBElement or NamedDBElement!');
throw new InvalidArgumentException('$class must be a class string that implements StructuralDBElement or NamedDBElement!');
}
if (null !== $parent && !is_a($parent, $class)) {
throw new \InvalidArgumentException('$parent must be of the type $class!');
throw new InvalidArgumentException('$parent must be of the type $class!');
}
/** @var StructuralDBElementRepository $repo */

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Services;
use App\Entity\UserSystem\User;
use Locale;
use Symfony\Component\Security\Core\Security;
/**
@ -65,7 +66,7 @@ class UserCacheKeyGenerator
*/
public function generateKey(?User $user = null): string
{
$locale = \Locale::getDefault();
$locale = Locale::getDefault();
//If no user was specified, use the currently used one.
if (null === $user) {

View file

@ -61,6 +61,8 @@ use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\TwigTest;
use function get_class;
class AppExtension extends AbstractExtension
{
protected $entityURLGenerator;
@ -128,7 +130,7 @@ class AppExtension extends AbstractExtension
public function treeData(AbstractDBElement $element, string $type = 'newEdit'): string
{
$tree = $this->treeBuilder->getTreeView(\get_class($element), null, $type, $element);
$tree = $this->treeBuilder->getTreeView(get_class($element), null, $type, $element);
return json_encode($tree);
}

View file

@ -24,13 +24,14 @@ declare(strict_types=1);
namespace App\Twig;
use App\Entity\LogSystem\AbstractLogEntry;
use App\Repository\LogEntryRepository;
use Doctrine\ORM\EntityManagerInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class LastUserExtension extends AbstractExtension
{
/** @var \App\Repository\LogEntryRepository */
/** @var LogEntryRepository */
private $repo;
public function __construct(EntityManagerInterface $em)

View file

@ -22,6 +22,10 @@ use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityPolicyInterface;
use Twig\Template;
use function get_class;
use function in_array;
use function is_array;
/**
* Represents a security policy which need to be enforced when sandbox mode is enabled.
*
@ -61,7 +65,7 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
$this->allowedMethods = [];
foreach ($methods as $class => $m) {
$this->allowedMethods[$class] = array_map(
static function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, \is_array($m) ? $m : [$m]);
static function ($value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); }, is_array($m) ? $m : [$m]);
}
}
@ -78,19 +82,19 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
public function checkSecurity($tags, $filters, $functions): void
{
foreach ($tags as $tag) {
if (!\in_array($tag, $this->allowedTags, true)) {
if (!in_array($tag, $this->allowedTags, true)) {
throw new SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag);
}
}
foreach ($filters as $filter) {
if (!\in_array($filter, $this->allowedFilters, true)) {
if (!in_array($filter, $this->allowedFilters, true)) {
throw new SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter);
}
}
foreach ($functions as $function) {
if (!\in_array($function, $this->allowedFunctions, true)) {
if (!in_array($function, $this->allowedFunctions, true)) {
throw new SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function);
}
}
@ -106,7 +110,7 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
$method = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');
foreach ($this->allowedMethods as $class => $methods) {
if ($obj instanceof $class) {
$allowed = \in_array($method, $methods, true);
$allowed = in_array($method, $methods, true);
//CHANGED: Only break if we the method is allowed, otherwise try it on the other methods
if ($allowed) {
@ -116,7 +120,7 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
}
if (!$allowed) {
$class = \get_class($obj);
$class = get_class($obj);
throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method);
}
@ -127,7 +131,7 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
$allowed = false;
foreach ($this->allowedProperties as $class => $properties) {
if ($obj instanceof $class) {
$allowed = \in_array($property, \is_array($properties) ? $properties : [$properties], true);
$allowed = in_array($property, is_array($properties) ? $properties : [$properties], true);
//CHANGED: Only break if we the method is allowed, otherwise try it on the other methods
if ($allowed) {
@ -137,7 +141,7 @@ final class InheritanceSecurityPolicy implements SecurityPolicyInterface
}
if (!$allowed) {
$class = \get_class($obj);
$class = get_class($obj);
throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property);
}

View file

@ -21,7 +21,6 @@
namespace App\Validator\Constraints\BigDecimal;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\NumberConstraintTrait;
/**
* @Annotation

View file

@ -21,7 +21,6 @@
namespace App\Validator\Constraints\BigDecimal;
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
use Symfony\Component\Validator\Constraints\NumberConstraintTrait;
/**
* @Annotation

View file

@ -4,13 +4,15 @@ namespace App\Validator\Constraints\BigDecimal;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use function is_array;
trait BigNumberConstraintTrait
{
private function configureNumberConstraintOptions($options): array
{
if (null === $options) {
$options = [];
} elseif (!\is_array($options)) {
} elseif (!is_array($options)) {
$options = [$this->getDefaultOption() => $options];
}

View file

@ -96,8 +96,6 @@ class NoneOfItsChildrenValidator extends ConstraintValidator
//Set the entity to a valid state
$entity->setParent(null);
$this->context->buildViolation($constraint->children_message)->addViolation();
return;
}
}
}

View file

@ -47,6 +47,9 @@ use Symfony\Component\Validator\Constraints\UrlValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
use function in_array;
use function is_object;
/**
* The validator for UrlOrBuiltin.
* It checks if the value is either a builtin ressource or a valid url.
@ -63,7 +66,7 @@ class UrlOrBuiltinValidator extends UrlValidator
if (null === $value || '' === $value) {
return;
}
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedValueException($value, 'string');
}
$value = (string) $value;
@ -74,7 +77,7 @@ class UrlOrBuiltinValidator extends UrlValidator
//After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode
$tmp = explode('/', $value);
//Builtins must have a %PLACEHOLDER% construction
if (\in_array($tmp[0], $constraint->allowed_placeholders, false)) {
if (in_array($tmp[0], $constraint->allowed_placeholders, false)) {
return;
}

View file

@ -48,6 +48,8 @@ use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
use function is_string;
class ValidFileFilterValidator extends ConstraintValidator
{
protected $filterTools;
@ -73,7 +75,7 @@ class ValidFileFilterValidator extends ConstraintValidator
return;
}
if (!\is_string($value)) {
if (!is_string($value)) {
// throw this exception if your validator cannot handle the passed type so that it can be marked as invalid
throw new UnexpectedValueException($value, 'string');
}

View file

@ -51,6 +51,9 @@ use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
use function is_string;
use function strlen;
class ValidGoogleAuthCodeValidator extends ConstraintValidator
{
protected $googleAuthenticator;
@ -70,7 +73,7 @@ class ValidGoogleAuthCodeValidator extends ConstraintValidator
return;
}
if (!\is_string($value)) {
if (!is_string($value)) {
throw new UnexpectedValueException($value, 'string');
}
@ -79,7 +82,7 @@ class ValidGoogleAuthCodeValidator extends ConstraintValidator
}
//Number must have 6 digits
if (6 !== \strlen($value)) {
if (6 !== strlen($value)) {
$this->context->addViolation('validator.google_code.wrong_digit_count');
}

View file

@ -42,6 +42,7 @@ declare(strict_types=1);
namespace App\Tests;
use Generator;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
@ -73,7 +74,7 @@ class ApplicationAvailabilityFunctionalTest extends WebTestCase
$this->assertTrue($client->getResponse()->isSuccessful(), 'Request not successful. Status code is '.$client->getResponse()->getStatusCode());
}
public function urlProvider(): ?\Generator
public function urlProvider(): ?Generator
{
//Homepage
//yield ['/'];