From 1aed1d1d26e8bce168086501d0d886404a12a529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 4 Jan 2020 20:14:42 +0100 Subject: [PATCH] Fixed some inspection issues. --- src/Controller/SecurityController.php | 16 ++++------------ src/Controller/TreeController.php | 3 --- src/Controller/UserController.php | 13 ------------- src/Controller/UserSettingsController.php | 8 +++++--- src/Entity/Attachments/Attachment.php | 1 - src/Entity/Base/MasterAttachmentTrait.php | 1 - src/Entity/Devices/Device.php | 3 ++- src/Entity/Parts/Part.php | 1 - src/Entity/Parts/PartLot.php | 1 + .../Parts/PartTraits/BasicPropertyTrait.php | 1 - src/Entity/Parts/PartTraits/OrderTrait.php | 1 - src/Entity/UserSystem/User.php | 3 ++- src/Repository/NamedDBElementRepository.php | 2 -- src/Repository/StructuralDBElementRepository.php | 2 -- src/Repository/UserRepository.php | 5 ----- 15 files changed, 14 insertions(+), 47 deletions(-) diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 127605c6..26f53cfa 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -21,24 +21,16 @@ namespace App\Controller; -use App\Entity\Parts\Part; -use App\Entity\UserSystem\U2FKey; -use App\Entity\UserSystem\User; use App\Services\PasswordResetManager; -use App\Services\TFA\BackupCodeManager; -use Doctrine\ORM\EntityManagerInterface; use Gregwar\CaptchaBundle\Type\CaptchaType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; 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\HttpKernel\Exception\AccessDeniedHttpException; -use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Routing\Annotation\Route; -use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; @@ -78,11 +70,11 @@ class SecurityController extends AbstractController public function requestPwReset(PasswordResetManager $passwordReset, Request $request) { if (!$this->allow_email_pw_reset) { - throw new AccessDeniedHttpException("The password reset via email is disabled!"); + throw new AccessDeniedHttpException('The password reset via email is disabled!'); } if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { - throw new AccessDeniedHttpException("You are already logged in, so you can not reset your password!"); + throw new AccessDeniedHttpException('You are already logged in, so you can not reset your password!'); } $builder = $this->createFormBuilder(); @@ -119,11 +111,11 @@ class SecurityController extends AbstractController public function pwResetNewPw(PasswordResetManager $passwordReset, Request $request, string $user = null, string $token = null) { if (!$this->allow_email_pw_reset) { - throw new AccessDeniedHttpException("The password reset via email is disabled!"); + throw new AccessDeniedHttpException('The password reset via email is disabled!'); } if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { - throw new AccessDeniedHttpException("You are already logged in, so you can not reset your password!"); + throw new AccessDeniedHttpException('You are already logged in, so you can not reset your password!'); } $data = ['username' => $user, 'token' => $token]; diff --git a/src/Controller/TreeController.php b/src/Controller/TreeController.php index 6482fb82..b6f04609 100644 --- a/src/Controller/TreeController.php +++ b/src/Controller/TreeController.php @@ -27,10 +27,7 @@ use App\Entity\Parts\Footprint; use App\Entity\Parts\Manufacturer; use App\Entity\Parts\Storelocation; use App\Entity\Parts\Supplier; -use App\Entity\UserSystem\U2FKey; -use App\Entity\UserSystem\User; use App\Services\Trees\ToolsTreeBuilder; -use App\Services\Trees\NodesListBuilder; use App\Services\Trees\TreeViewGenerator; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 775493c9..fd425e22 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -25,29 +25,16 @@ use App\Entity\Attachments\AttachmentType; use App\Entity\Attachments\UserAttachment; use App\Entity\UserSystem\User; use App\Form\Permissions\PermissionsType; -use App\Form\TFAGoogleSettingsType; use App\Form\UserAdminForm; -use App\Form\UserSettingsType; use App\Services\EntityExporter; use App\Services\EntityImporter; use App\Services\StructuralElementRecursionHelper; -use App\Services\TFA\BackupCodeManager; use Doctrine\ORM\EntityManagerInterface; -use \Exception; -use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticator; use Symfony\Component\Asset\Packages; -use Symfony\Component\Form\Extension\Core\Type\HiddenType; -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\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; -use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; -use Symfony\Component\Security\Core\Validator\Constraints\UserPassword; use Symfony\Component\Serializer\SerializerInterface; -use Symfony\Component\Validator\Constraints\Length; /** * @Route("/user") diff --git a/src/Controller/UserSettingsController.php b/src/Controller/UserSettingsController.php index afa62297..d7163adb 100644 --- a/src/Controller/UserSettingsController.php +++ b/src/Controller/UserSettingsController.php @@ -70,7 +70,7 @@ class UserSettingsController extends AbstractController if (empty($user->getBackupCodes())) { $this->addFlash('error', 'tfa_backup.no_codes_enabled'); - throw new Exception('You do not have any backup codes enabled, therefore you can not view them!'); + throw new \RuntimeException('You do not have any backup codes enabled, therefore you can not view them!'); } return $this->render('Users/backup_codes.html.twig', [ @@ -253,7 +253,7 @@ class UserSettingsController extends AbstractController } $google_form->handleRequest($request); - if($google_form->isSubmitted() && $google_form->isValid() && !$this->demo_mode) { + if ($google_form->isSubmitted() && $google_form->isValid() && !$this->demo_mode) { if (!$google_enabled) { //Save 2FA settings (save secrets) $user->setGoogleAuthenticatorSecret($google_form->get('googleAuthenticatorSecret')->getData()); @@ -261,7 +261,9 @@ class UserSettingsController extends AbstractController $em->flush(); $this->addFlash('success', 'user.settings.2fa.google.activated'); return $this->redirectToRoute('user_settings'); - } elseif ($google_enabled) { + } + + if ($google_enabled) { //Remove secret to disable google authenticator $user->setGoogleAuthenticatorSecret(null); $backupCodeManager->disableBackupCodesIfUnused($user); diff --git a/src/Entity/Attachments/Attachment.php b/src/Entity/Attachments/Attachment.php index d3011458..3cdff01d 100644 --- a/src/Entity/Attachments/Attachment.php +++ b/src/Entity/Attachments/Attachment.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace App\Entity\Attachments; use App\Entity\Base\NamedDBElement; -use App\Entity\Parts\Category; use App\Validator\Constraints\Selectable; use Doctrine\ORM\Mapping as ORM; diff --git a/src/Entity/Base/MasterAttachmentTrait.php b/src/Entity/Base/MasterAttachmentTrait.php index bdef230d..c1a650a7 100644 --- a/src/Entity/Base/MasterAttachmentTrait.php +++ b/src/Entity/Base/MasterAttachmentTrait.php @@ -22,7 +22,6 @@ namespace App\Entity\Base; use App\Entity\Attachments\Attachment; -use App\Entity\Parts\Part; use Symfony\Component\Validator\Constraints as Assert; /** diff --git a/src/Entity/Devices/Device.php b/src/Entity/Devices/Device.php index 672b2daa..5b9072e3 100644 --- a/src/Entity/Devices/Device.php +++ b/src/Entity/Devices/Device.php @@ -133,7 +133,8 @@ class Device extends PartsContainingDBElement /** * Set the order quantity. * - * @param int $new_order_quantity the new order quantity + * @param int $new_order_quantity the new order quantity + * @return $this */ public function setOrderQuantity(int $new_order_quantity): self { diff --git a/src/Entity/Parts/Part.php b/src/Entity/Parts/Part.php index 4a89c759..7d7e74aa 100644 --- a/src/Entity/Parts/Part.php +++ b/src/Entity/Parts/Part.php @@ -53,7 +53,6 @@ namespace App\Entity\Parts; use App\Entity\Attachments\Attachment; use App\Entity\Attachments\AttachmentContainingDBElement; -use App\Entity\Base\MasterAttachmentTrait; use App\Entity\Devices\Device; use App\Entity\Parts\PartTraits\AdvancedPropertyTrait; use App\Entity\Parts\PartTraits\BasicPropertyTrait; diff --git a/src/Entity/Parts/PartLot.php b/src/Entity/Parts/PartLot.php index 1bb1dc83..e4140cae 100644 --- a/src/Entity/Parts/PartLot.php +++ b/src/Entity/Parts/PartLot.php @@ -112,6 +112,7 @@ class PartLot extends DBElement * This is the case, if the expiration date is greater the the current date. * * @return bool|null True, if the part lot is expired. Returns null, if no expiration date was set. + * @throws \Exception If an error with the DateTime occurs */ public function isExpired(): ?bool { diff --git a/src/Entity/Parts/PartTraits/BasicPropertyTrait.php b/src/Entity/Parts/PartTraits/BasicPropertyTrait.php index 01c23f3e..56064e14 100644 --- a/src/Entity/Parts/PartTraits/BasicPropertyTrait.php +++ b/src/Entity/Parts/PartTraits/BasicPropertyTrait.php @@ -23,7 +23,6 @@ namespace App\Entity\Parts\PartTraits; use App\Entity\Parts\Category; use App\Entity\Parts\Footprint; -use App\Entity\Parts\Part; use App\Security\Annotations\ColumnSecurity; use App\Validator\Constraints\Selectable; diff --git a/src/Entity/Parts/PartTraits/OrderTrait.php b/src/Entity/Parts/PartTraits/OrderTrait.php index 642eabbe..de791426 100644 --- a/src/Entity/Parts/PartTraits/OrderTrait.php +++ b/src/Entity/Parts/PartTraits/OrderTrait.php @@ -21,7 +21,6 @@ namespace App\Entity\Parts\PartTraits; -use App\Entity\Parts\Part; use App\Entity\PriceInformations\Orderdetail; use App\Security\Annotations\ColumnSecurity; use Doctrine\Common\Collections\Collection; diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index e933b583..84b516bf 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -770,8 +770,9 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe /** * Set the backup codes for this user. Existing backup codes are overridden. - * @param string[] $codes A + * @param string[] $codes An array containing the backup codes * @return $this + * @throws \Exception If an error with the datetime occurs */ public function setBackupCodes(array $codes) : self { diff --git a/src/Repository/NamedDBElementRepository.php b/src/Repository/NamedDBElementRepository.php index c27fdb86..418e0b98 100644 --- a/src/Repository/NamedDBElementRepository.php +++ b/src/Repository/NamedDBElementRepository.php @@ -23,10 +23,8 @@ namespace App\Repository; use App\Entity\Base\NamedDBElement; -use App\Entity\Base\StructuralDBElement; use App\Helpers\Trees\TreeViewNode; use Doctrine\ORM\EntityRepository; -use Doctrine\ORM\Mapping\Entity; class NamedDBElementRepository extends EntityRepository diff --git a/src/Repository/StructuralDBElementRepository.php b/src/Repository/StructuralDBElementRepository.php index 5e18e880..710bb480 100644 --- a/src/Repository/StructuralDBElementRepository.php +++ b/src/Repository/StructuralDBElementRepository.php @@ -24,8 +24,6 @@ namespace App\Repository; use App\Entity\Base\StructuralDBElement; use App\Helpers\Trees\StructuralDBElementIterator; use App\Helpers\Trees\TreeViewNode; -use Doctrine\ORM\EntityRepository; -use Symfony\Component\Stopwatch\Stopwatch; class StructuralDBElementRepository extends NamedDBElementRepository { diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 6b95341a..782ccd13 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -22,12 +22,7 @@ namespace App\Repository; use App\Entity\UserSystem\User; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\EntityRepository; -use Doctrine\ORM\Mapping; use Doctrine\ORM\NonUniqueResultException; -use Symfony\Bridge\Doctrine\RegistryInterface; use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; use Symfony\Component\Security\Core\User\UserInterface;