diff --git a/src/Command/Attachments/CleanAttachmentsCommand.php b/src/Command/Attachments/CleanAttachmentsCommand.php index 5db8e500..465fe1a7 100644 --- a/src/Command/Attachments/CleanAttachmentsCommand.php +++ b/src/Command/Attachments/CleanAttachmentsCommand.php @@ -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 diff --git a/src/Controller/AdminPages/BaseAdminController.php b/src/Controller/AdminPages/BaseAdminController.php index dc7e638a..fe900c5f 100644 --- a/src/Controller/AdminPages/BaseAdminController.php +++ b/src/Controller/AdminPages/BaseAdminController.php @@ -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()]); diff --git a/src/Controller/AdminPages/CurrencyController.php b/src/Controller/AdminPages/CurrencyController.php index 4b9342df..169b451f 100644 --- a/src/Controller/AdminPages/CurrencyController.php +++ b/src/Controller/AdminPages/CurrencyController.php @@ -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; /** diff --git a/src/Controller/AdminPages/FootprintController.php b/src/Controller/AdminPages/FootprintController.php index 6b5f437e..7f1f8155 100644 --- a/src/Controller/AdminPages/FootprintController.php +++ b/src/Controller/AdminPages/FootprintController.php @@ -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); } diff --git a/src/Controller/AdminPages/LabelProfileController.php b/src/Controller/AdminPages/LabelProfileController.php index 4242a47e..c90e5792 100644 --- a/src/Controller/AdminPages/LabelProfileController.php +++ b/src/Controller/AdminPages/LabelProfileController.php @@ -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") */ diff --git a/src/Controller/AdminPages/ManufacturerController.php b/src/Controller/AdminPages/ManufacturerController.php index 4cf9c48f..93880542 100644 --- a/src/Controller/AdminPages/ManufacturerController.php +++ b/src/Controller/AdminPages/ManufacturerController.php @@ -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); } diff --git a/src/Controller/AdminPages/MeasurementUnitController.php b/src/Controller/AdminPages/MeasurementUnitController.php index f67cad31..be01cf04 100644 --- a/src/Controller/AdminPages/MeasurementUnitController.php +++ b/src/Controller/AdminPages/MeasurementUnitController.php @@ -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); } diff --git a/src/Controller/LabelController.php b/src/Controller/LabelController.php index ef9c20f2..920233c7 100644 --- a/src/Controller/LabelController.php +++ b/src/Controller/LabelController.php @@ -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); diff --git a/src/Controller/LogController.php b/src/Controller/LogController.php index 9195c70c..991cd0e4 100644 --- a/src/Controller/LogController.php +++ b/src/Controller/LogController.php @@ -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()); diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index dd28a401..19c16662 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -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)); diff --git a/src/Controller/ScanController.php b/src/Controller/ScanController.php index 2da4e71a..685c91ff 100644 --- a/src/Controller/ScanController.php +++ b/src/Controller/ScanController.php @@ -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'); } } diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 38fd9100..e304072f 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -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) { diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 5ea169a4..292a14ca 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -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 { diff --git a/src/Controller/UserSettingsController.php b/src/Controller/UserSettingsController.php index 3428163d..a6e65a7b 100644 --- a/src/Controller/UserSettingsController.php +++ b/src/Controller/UserSettingsController.php @@ -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) { diff --git a/src/DataFixtures/PartFixtures.php b/src/DataFixtures/PartFixtures.php index 17b0d617..fb5821fe 100644 --- a/src/DataFixtures/PartFixtures.php +++ b/src/DataFixtures/PartFixtures.php @@ -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)); diff --git a/src/DataFixtures/UserFixtures.php b/src/DataFixtures/UserFixtures.php index 24c81b03..8251ba93 100644 --- a/src/DataFixtures/UserFixtures.php +++ b/src/DataFixtures/UserFixtures.php @@ -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 { diff --git a/src/DataTables/Column/LocaleDateTimeColumn.php b/src/DataTables/Column/LocaleDateTimeColumn.php index 87e7fd96..f9103f86 100644 --- a/src/DataTables/Column/LocaleDateTimeColumn.php +++ b/src/DataTables/Column/LocaleDateTimeColumn.php @@ -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 { diff --git a/src/Doctrine/Purger/ResetAutoIncrementORMPurger.php b/src/Doctrine/Purger/ResetAutoIncrementORMPurger.php index f5d79b61..0555394c 100644 --- a/src/Doctrine/Purger/ResetAutoIncrementORMPurger.php +++ b/src/Doctrine/Purger/ResetAutoIncrementORMPurger.php @@ -288,7 +288,7 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface } /** - * @param mixed[] $assoc + * @param array $assoc */ private function getJoinTableName( array $assoc, diff --git a/src/Entity/Attachments/Attachment.php b/src/Entity/Attachments/Attachment.php index 9f9b54b8..21370064 100644 --- a/src/Entity/Attachments/Attachment.php +++ b/src/Entity/Attachments/Attachment.php @@ -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)); } /** diff --git a/src/Entity/Base/AbstractDBElement.php b/src/Entity/Base/AbstractDBElement.php index 3a97473c..a526e8ce 100644 --- a/src/Entity/Base/AbstractDBElement.php +++ b/src/Entity/Base/AbstractDBElement.php @@ -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. diff --git a/src/Entity/Base/MasterAttachmentTrait.php b/src/Entity/Base/MasterAttachmentTrait.php index 4f1a2eb2..ce315fa8 100644 --- a/src/Entity/Base/MasterAttachmentTrait.php +++ b/src/Entity/Base/MasterAttachmentTrait.php @@ -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; /** diff --git a/src/Entity/Base/TimestampTrait.php b/src/Entity/Base/TimestampTrait.php index c34c2cea..004b301c 100644 --- a/src/Entity/Base/TimestampTrait.php +++ b/src/Entity/Base/TimestampTrait.php @@ -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; /** diff --git a/src/Entity/Contracts/TimeTravelInterface.php b/src/Entity/Contracts/TimeTravelInterface.php index 2cd43161..308b5c94 100644 --- a/src/Entity/Contracts/TimeTravelInterface.php +++ b/src/Entity/Contracts/TimeTravelInterface.php @@ -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; } diff --git a/src/Entity/LogSystem/AbstractLogEntry.php b/src/Entity/LogSystem/AbstractLogEntry.php index fe573395..834ccbcb 100644 --- a/src/Entity/LogSystem/AbstractLogEntry.php +++ b/src/Entity/LogSystem/AbstractLogEntry.php @@ -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!'); } } diff --git a/src/Entity/LogSystem/CollectionElementDeleted.php b/src/Entity/LogSystem/CollectionElementDeleted.php index 53cb9529..20530b58 100644 --- a/src/Entity/LogSystem/CollectionElementDeleted.php +++ b/src/Entity/LogSystem/CollectionElementDeleted.php @@ -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; diff --git a/src/Entity/LogSystem/ElementCreatedLogEntry.php b/src/Entity/LogSystem/ElementCreatedLogEntry.php index 51ff75fa..e36b888c 100644 --- a/src/Entity/LogSystem/ElementCreatedLogEntry.php +++ b/src/Entity/LogSystem/ElementCreatedLogEntry.php @@ -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; diff --git a/src/Entity/LogSystem/ElementDeletedLogEntry.php b/src/Entity/LogSystem/ElementDeletedLogEntry.php index 7768b4bd..da480f9b 100644 --- a/src/Entity/LogSystem/ElementDeletedLogEntry.php +++ b/src/Entity/LogSystem/ElementDeletedLogEntry.php @@ -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; diff --git a/src/Entity/LogSystem/ElementEditedLogEntry.php b/src/Entity/LogSystem/ElementEditedLogEntry.php index dd32eaa2..9696d4ad 100644 --- a/src/Entity/LogSystem/ElementEditedLogEntry.php +++ b/src/Entity/LogSystem/ElementEditedLogEntry.php @@ -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; diff --git a/src/Entity/LogSystem/SecurityEventLogEntry.php b/src/Entity/LogSystem/SecurityEventLogEntry.php index 181ee24d..fd7ede34 100644 --- a/src/Entity/LogSystem/SecurityEventLogEntry.php +++ b/src/Entity/LogSystem/SecurityEventLogEntry.php @@ -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; diff --git a/src/Entity/Parameters/AbstractParameter.php b/src/Entity/Parameters/AbstractParameter.php index 8022f9d5..3ac0b080 100644 --- a/src/Entity/Parameters/AbstractParameter.php +++ b/src/Entity/Parameters/AbstractParameter.php @@ -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; } diff --git a/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php b/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php index 111f92dc..3e405bd7 100644 --- a/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php +++ b/src/Entity/Parts/PartTraits/AdvancedPropertyTrait.php @@ -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. diff --git a/src/Entity/Parts/PartTraits/BasicPropertyTrait.php b/src/Entity/Parts/PartTraits/BasicPropertyTrait.php index 200c1559..77409b2c 100644 --- a/src/Entity/Parts/PartTraits/BasicPropertyTrait.php +++ b/src/Entity/Parts/PartTraits/BasicPropertyTrait.php @@ -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 diff --git a/src/Entity/Parts/PartTraits/InstockTrait.php b/src/Entity/Parts/PartTraits/InstockTrait.php index ddc6d960..4f910e38 100644 --- a/src/Entity/Parts/PartTraits/InstockTrait.php +++ b/src/Entity/Parts/PartTraits/InstockTrait.php @@ -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. diff --git a/src/Entity/Parts/PartTraits/ManufacturerTrait.php b/src/Entity/Parts/PartTraits/ManufacturerTrait.php index 78437328..876381c1 100644 --- a/src/Entity/Parts/PartTraits/ManufacturerTrait.php +++ b/src/Entity/Parts/PartTraits/ManufacturerTrait.php @@ -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). diff --git a/src/Entity/Parts/PartTraits/OrderTrait.php b/src/Entity/Parts/PartTraits/OrderTrait.php index a98bb03b..79947596 100644 --- a/src/Entity/Parts/PartTraits/OrderTrait.php +++ b/src/Entity/Parts/PartTraits/OrderTrait.php @@ -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; diff --git a/src/Entity/PriceInformations/Pricedetail.php b/src/Entity/PriceInformations/Pricedetail.php index 6b7d0a1c..494e5de6 100644 --- a/src/Entity/PriceInformations/Pricedetail.php +++ b/src/Entity/PriceInformations/Pricedetail.php @@ -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; diff --git a/src/Entity/UserSystem/PermissionsEmbed.php b/src/Entity/UserSystem/PermissionsEmbed.php index 97987015..4552083d 100644 --- a/src/Entity/UserSystem/PermissionsEmbed.php +++ b/src/Entity/UserSystem/PermissionsEmbed.php @@ -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); } } diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index 3db3ff38..505feae8 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -721,7 +721,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe */ public function isGoogleAuthenticatorEnabled(): bool { - return $this->googleAuthenticatorSecret ? true : false; + return (bool)$this->googleAuthenticatorSecret; } /** diff --git a/src/Exceptions/LogEntryObsoleteException.php b/src/Exceptions/LogEntryObsoleteException.php index a1b31e95..7162712a 100644 --- a/src/Exceptions/LogEntryObsoleteException.php +++ b/src/Exceptions/LogEntryObsoleteException.php @@ -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!'; } diff --git a/src/Exceptions/TwigModeException.php b/src/Exceptions/TwigModeException.php index 52d125e1..f05bd157 100644 --- a/src/Exceptions/TwigModeException.php +++ b/src/Exceptions/TwigModeException.php @@ -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) { diff --git a/src/Form/CollectionTypeExtension.php b/src/Form/CollectionTypeExtension.php index ce121fe5..697f9533 100644 --- a/src/Form/CollectionTypeExtension.php +++ b/src/Form/CollectionTypeExtension.php @@ -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); diff --git a/src/Form/Type/CurrencyEntityType.php b/src/Form/Type/CurrencyEntityType.php index e69a9724..e1f8cf84 100644 --- a/src/Form/Type/CurrencyEntityType.php +++ b/src/Form/Type/CurrencyEntityType.php @@ -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 diff --git a/src/Form/Type/MasterPictureAttachmentType.php b/src/Form/Type/MasterPictureAttachmentType.php index 725dd90b..1ae5543b 100644 --- a/src/Form/Type/MasterPictureAttachmentType.php +++ b/src/Form/Type/MasterPictureAttachmentType.php @@ -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(); diff --git a/src/Helpers/BigDecimalType.php b/src/Helpers/BigDecimalType.php index d953dfb0..fa2e62b8 100644 --- a/src/Helpers/BigDecimalType.php +++ b/src/Helpers/BigDecimalType.php @@ -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) { diff --git a/src/Helpers/LabelResponse.php b/src/Helpers/LabelResponse.php index c9b763b8..3cb65a13 100644 --- a/src/Helpers/LabelResponse.php +++ b/src/Helpers/LabelResponse.php @@ -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; diff --git a/src/Helpers/Trees/StructuralDBElementIterator.php b/src/Helpers/Trees/StructuralDBElementIterator.php index 1bbbd6ef..4f1e914d 100644 --- a/src/Helpers/Trees/StructuralDBElementIterator.php +++ b/src/Helpers/Trees/StructuralDBElementIterator.php @@ -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); diff --git a/src/Repository/AbstractPartsContainingRepository.php b/src/Repository/AbstractPartsContainingRepository.php index f4cdb0bf..83e6c215 100644 --- a/src/Repository/AbstractPartsContainingRepository.php +++ b/src/Repository/AbstractPartsContainingRepository.php @@ -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); diff --git a/src/Repository/AttachmentRepository.php b/src/Repository/AttachmentRepository.php index cdac1c04..86c25556 100644 --- a/src/Repository/AttachmentRepository.php +++ b/src/Repository/AttachmentRepository.php @@ -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 { diff --git a/src/Repository/DBElementRepository.php b/src/Repository/DBElementRepository.php index f265f8c0..1e3c85ff 100644 --- a/src/Repository/DBElementRepository.php +++ b/src/Repository/DBElementRepository.php @@ -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); diff --git a/src/Repository/LabelProfileRepository.php b/src/Repository/LabelProfileRepository.php index 4f6709fd..a36f8ccf 100644 --- a/src/Repository/LabelProfileRepository.php +++ b/src/Repository/LabelProfileRepository.php @@ -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); diff --git a/src/Repository/LogEntryRepository.php b/src/Repository/LogEntryRepository.php index 8f973425..eb0bb82c 100644 --- a/src/Repository/LogEntryRepository.php +++ b/src/Repository/LogEntryRepository.php @@ -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 { diff --git a/src/Repository/PartRepository.php b/src/Repository/PartRepository.php index 1d5c1a7c..cbe3c5fb 100644 --- a/src/Repository/PartRepository.php +++ b/src/Repository/PartRepository.php @@ -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 { diff --git a/src/Repository/Parts/CategoryRepository.php b/src/Repository/Parts/CategoryRepository.php index dad7a306..97c0e4ad 100644 --- a/src/Repository/Parts/CategoryRepository.php +++ b/src/Repository/Parts/CategoryRepository.php @@ -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'); diff --git a/src/Repository/Parts/DeviceRepository.php b/src/Repository/Parts/DeviceRepository.php index 1e6166a8..b56e5a6c 100644 --- a/src/Repository/Parts/DeviceRepository.php +++ b/src/Repository/Parts/DeviceRepository.php @@ -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 diff --git a/src/Repository/Parts/FootprintRepository.php b/src/Repository/Parts/FootprintRepository.php index a9b2ed3e..7bdc65df 100644 --- a/src/Repository/Parts/FootprintRepository.php +++ b/src/Repository/Parts/FootprintRepository.php @@ -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'); diff --git a/src/Repository/Parts/ManufacturerRepository.php b/src/Repository/Parts/ManufacturerRepository.php index 77e2b5d5..f81922ef 100644 --- a/src/Repository/Parts/ManufacturerRepository.php +++ b/src/Repository/Parts/ManufacturerRepository.php @@ -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'); diff --git a/src/Repository/Parts/MeasurementUnitRepository.php b/src/Repository/Parts/MeasurementUnitRepository.php index 7389be28..346e96d1 100644 --- a/src/Repository/Parts/MeasurementUnitRepository.php +++ b/src/Repository/Parts/MeasurementUnitRepository.php @@ -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'); diff --git a/src/Repository/Parts/StorelocationRepository.php b/src/Repository/Parts/StorelocationRepository.php index a5a73b15..92ad482d 100644 --- a/src/Repository/Parts/StorelocationRepository.php +++ b/src/Repository/Parts/StorelocationRepository.php @@ -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()); diff --git a/src/Repository/Parts/SupplierRepository.php b/src/Repository/Parts/SupplierRepository.php index 79a52699..d5727ad1 100644 --- a/src/Repository/Parts/SupplierRepository.php +++ b/src/Repository/Parts/SupplierRepository.php @@ -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()); diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index 4f3080d3..daafa5c9 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -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', diff --git a/src/Services/LabelSystem/BarcodeGenerator.php b/src/Services/LabelSystem/BarcodeGenerator.php index 4d82dc3b..62505fbc 100644 --- a/src/Services/LabelSystem/BarcodeGenerator.php +++ b/src/Services/LabelSystem/BarcodeGenerator.php @@ -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!'); } } } diff --git a/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php b/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php index c2819377..80043ac5 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeContentGenerator.php @@ -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)); } } diff --git a/src/Services/LabelSystem/Barcodes/BarcodeExampleElementsGenerator.php b/src/Services/LabelSystem/Barcodes/BarcodeExampleElementsGenerator.php index d0ac5d97..9804d721 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeExampleElementsGenerator.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeExampleElementsGenerator.php @@ -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; diff --git a/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php b/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php index 542ede10..dcee3b5c 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeNormalizer.php @@ -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!'); } } diff --git a/src/Services/LabelSystem/Barcodes/BarcodeRedirector.php b/src/Services/LabelSystem/Barcodes/BarcodeRedirector.php index 4ce169ef..028909df 100644 --- a/src/Services/LabelSystem/Barcodes/BarcodeRedirector.php +++ b/src/Services/LabelSystem/Barcodes/BarcodeRedirector.php @@ -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); } } } diff --git a/src/Services/LabelSystem/LabelGenerator.php b/src/Services/LabelSystem/LabelGenerator.php index 73efb814..4fc85db7 100644 --- a/src/Services/LabelSystem/LabelGenerator.php +++ b/src/Services/LabelSystem/LabelGenerator.php @@ -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]); diff --git a/src/Services/LabelSystem/LabelHTMLGenerator.php b/src/Services/LabelSystem/LabelHTMLGenerator.php index e41f8301..49ff0d1e 100644 --- a/src/Services/LabelSystem/LabelHTMLGenerator.php +++ b/src/Services/LabelSystem/LabelHTMLGenerator.php @@ -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 = []; diff --git a/src/Services/LabelSystem/PlaceholderProviders/GlobalProviders.php b/src/Services/LabelSystem/PlaceholderProviders/GlobalProviders.php index 919ba58c..66ddad6b 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/GlobalProviders.php +++ b/src/Services/LabelSystem/PlaceholderProviders/GlobalProviders.php @@ -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( diff --git a/src/Services/LabelSystem/PlaceholderProviders/PartProvider.php b/src/Services/LabelSystem/PlaceholderProviders/PartProvider.php index 96145465..3d3fe1a9 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/PartProvider.php +++ b/src/Services/LabelSystem/PlaceholderProviders/PartProvider.php @@ -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()); diff --git a/src/Services/LabelSystem/PlaceholderProviders/TimestampableElementProvider.php b/src/Services/LabelSystem/PlaceholderProviders/TimestampableElementProvider.php index 581a5e88..8e172d5a 100644 --- a/src/Services/LabelSystem/PlaceholderProviders/TimestampableElementProvider.php +++ b/src/Services/LabelSystem/PlaceholderProviders/TimestampableElementProvider.php @@ -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()); } } diff --git a/src/Services/LabelSystem/SandboxedTwigProvider.php b/src/Services/LabelSystem/SandboxedTwigProvider.php index c794741c..ded552d3 100644 --- a/src/Services/LabelSystem/SandboxedTwigProvider.php +++ b/src/Services/LabelSystem/SandboxedTwigProvider.php @@ -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); diff --git a/src/Services/LogSystem/EventUndoHelper.php b/src/Services/LogSystem/EventUndoHelper.php index def06817..4366325d 100644 --- a/src/Services/LogSystem/EventUndoHelper.php +++ b/src/Services/LogSystem/EventUndoHelper.php @@ -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; } diff --git a/src/Services/LogSystem/HistoryHelper.php b/src/Services/LogSystem/HistoryHelper.php index 2278fe7d..ebe1cd9c 100644 --- a/src/Services/LogSystem/HistoryHelper.php +++ b/src/Services/LogSystem/HistoryHelper.php @@ -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 */ public function getAssociatedElements(AbstractDBElement $element): array { diff --git a/src/Services/LogSystem/TimeTravel.php b/src/Services/LogSystem/TimeTravel.php index 25bf42c7..66a5944c 100644 --- a/src/Services/LogSystem/TimeTravel.php +++ b/src/Services/LogSystem/TimeTravel.php @@ -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); diff --git a/src/Services/Misc/RangeParser.php b/src/Services/Misc/RangeParser.php index cf7f754d..13fb2ba9 100644 --- a/src/Services/Misc/RangeParser.php +++ b/src/Services/Misc/RangeParser.php @@ -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; } } diff --git a/src/Services/MoneyFormatter.php b/src/Services/MoneyFormatter.php index ca3e70c3..95602ed2 100644 --- a/src/Services/MoneyFormatter.php +++ b/src/Services/MoneyFormatter.php @@ -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); diff --git a/src/Services/Parameters/ParameterExtractor.php b/src/Services/Parameters/ParameterExtractor.php index 4f2c344f..06efdfc0 100644 --- a/src/Services/Parameters/ParameterExtractor.php +++ b/src/Services/Parameters/ParameterExtractor.php @@ -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); diff --git a/src/Services/Parts/PartsTableActionHandler.php b/src/Services/Parts/PartsTableActionHandler.php index 96120772..e9d38f62 100644 --- a/src/Services/Parts/PartsTableActionHandler.php +++ b/src/Services/Parts/PartsTableActionHandler.php @@ -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.')'); } } } diff --git a/src/Services/PasswordResetManager.php b/src/Services/PasswordResetManager.php index 9cddead8..9d8a0c2c 100644 --- a/src/Services/PasswordResetManager.php +++ b/src/Services/PasswordResetManager.php @@ -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(); diff --git a/src/Services/PermissionResolver.php b/src/Services/PermissionResolver.php index fdfd0ae2..d31c392d 100644 --- a/src/Services/PermissionResolver.php +++ b/src/Services/PermissionResolver.php @@ -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']; diff --git a/src/Services/PricedetailHelper.php b/src/Services/PricedetailHelper.php index a98273be..b7ea933f 100644 --- a/src/Services/PricedetailHelper.php +++ b/src/Services/PricedetailHelper.php @@ -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; } diff --git a/src/Services/StatisticsHelper.php b/src/Services/StatisticsHelper.php index 2afa3068..2e734b6e 100644 --- a/src/Services/StatisticsHelper.php +++ b/src/Services/StatisticsHelper.php @@ -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 { diff --git a/src/Services/TFA/BackupCodeGenerator.php b/src/Services/TFA/BackupCodeGenerator.php index b7ace1c4..419bf2aa 100644 --- a/src/Services/TFA/BackupCodeGenerator.php +++ b/src/Services/TFA/BackupCodeGenerator.php @@ -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 { diff --git a/src/Services/TagFinder.php b/src/Services/TagFinder.php index 0292304b..4038bc34 100644 --- a/src/Services/TagFinder.php +++ b/src/Services/TagFinder.php @@ -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 diff --git a/src/Services/Trees/TreeViewGenerator.php b/src/Services/Trees/TreeViewGenerator.php index 94665e8e..cfd600bc 100644 --- a/src/Services/Trees/TreeViewGenerator.php +++ b/src/Services/Trees/TreeViewGenerator.php @@ -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 */ diff --git a/src/Services/UserCacheKeyGenerator.php b/src/Services/UserCacheKeyGenerator.php index bab87b6f..5dac802b 100644 --- a/src/Services/UserCacheKeyGenerator.php +++ b/src/Services/UserCacheKeyGenerator.php @@ -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) { diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 5f021546..8ded6aca 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -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); } diff --git a/src/Twig/LastUserExtension.php b/src/Twig/LastUserExtension.php index 159909ed..ed781532 100644 --- a/src/Twig/LastUserExtension.php +++ b/src/Twig/LastUserExtension.php @@ -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) diff --git a/src/Twig/Sandbox/InheritanceSecurityPolicy.php b/src/Twig/Sandbox/InheritanceSecurityPolicy.php index ff20e059..f11acc86 100644 --- a/src/Twig/Sandbox/InheritanceSecurityPolicy.php +++ b/src/Twig/Sandbox/InheritanceSecurityPolicy.php @@ -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); } diff --git a/src/Validator/Constraints/BigDecimal/BigDecimalPositive.php b/src/Validator/Constraints/BigDecimal/BigDecimalPositive.php index f58552e4..8b2e5ad7 100644 --- a/src/Validator/Constraints/BigDecimal/BigDecimalPositive.php +++ b/src/Validator/Constraints/BigDecimal/BigDecimalPositive.php @@ -21,7 +21,6 @@ namespace App\Validator\Constraints\BigDecimal; use Symfony\Component\Validator\Constraints\GreaterThan; -use Symfony\Component\Validator\Constraints\NumberConstraintTrait; /** * @Annotation diff --git a/src/Validator/Constraints/BigDecimal/BigDecimalPositiveOrZero.php b/src/Validator/Constraints/BigDecimal/BigDecimalPositiveOrZero.php index 3b6c6943..de87e66e 100644 --- a/src/Validator/Constraints/BigDecimal/BigDecimalPositiveOrZero.php +++ b/src/Validator/Constraints/BigDecimal/BigDecimalPositiveOrZero.php @@ -21,7 +21,6 @@ namespace App\Validator\Constraints\BigDecimal; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; -use Symfony\Component\Validator\Constraints\NumberConstraintTrait; /** * @Annotation diff --git a/src/Validator/Constraints/BigDecimal/BigNumberConstraintTrait.php b/src/Validator/Constraints/BigDecimal/BigNumberConstraintTrait.php index c77ee317..b983c189 100644 --- a/src/Validator/Constraints/BigDecimal/BigNumberConstraintTrait.php +++ b/src/Validator/Constraints/BigDecimal/BigNumberConstraintTrait.php @@ -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]; } diff --git a/src/Validator/Constraints/NoneOfItsChildrenValidator.php b/src/Validator/Constraints/NoneOfItsChildrenValidator.php index 894f4723..31f3ea9c 100644 --- a/src/Validator/Constraints/NoneOfItsChildrenValidator.php +++ b/src/Validator/Constraints/NoneOfItsChildrenValidator.php @@ -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; } } } diff --git a/src/Validator/Constraints/UrlOrBuiltinValidator.php b/src/Validator/Constraints/UrlOrBuiltinValidator.php index 77b20521..785023e1 100644 --- a/src/Validator/Constraints/UrlOrBuiltinValidator.php +++ b/src/Validator/Constraints/UrlOrBuiltinValidator.php @@ -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; } diff --git a/src/Validator/Constraints/ValidFileFilterValidator.php b/src/Validator/Constraints/ValidFileFilterValidator.php index a850111e..2aa31411 100644 --- a/src/Validator/Constraints/ValidFileFilterValidator.php +++ b/src/Validator/Constraints/ValidFileFilterValidator.php @@ -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'); } diff --git a/src/Validator/Constraints/ValidGoogleAuthCodeValidator.php b/src/Validator/Constraints/ValidGoogleAuthCodeValidator.php index 3e5dc11a..7404cb00 100644 --- a/src/Validator/Constraints/ValidGoogleAuthCodeValidator.php +++ b/src/Validator/Constraints/ValidGoogleAuthCodeValidator.php @@ -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'); } diff --git a/tests/ApplicationAvailabilityFunctionalTest.php b/tests/ApplicationAvailabilityFunctionalTest.php index 5bc58be4..3a5ce06f 100644 --- a/tests/ApplicationAvailabilityFunctionalTest.php +++ b/tests/ApplicationAvailabilityFunctionalTest.php @@ -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 ['/'];