| Conditions | 8 |
| Paths | 27 |
| Total Lines | 79 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 60 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 61 | { |
||
| 62 | $registrationStatus = $input->getArgument('registration-status'); |
||
| 63 | $this->bootstrapService->validRegistrationStatus($registrationStatus); |
||
| 64 | |||
| 65 | $nameId = new NameId($input->getArgument('name-id')); |
||
| 66 | $institutionText = $input->getArgument('institution'); |
||
| 67 | $institution = new Institution($institutionText); |
||
| 68 | $mailVerificationRequired = $this->bootstrapService->requiresMailVerification($institutionText); |
||
| 69 | $phoneNumber = $input->getArgument('phone-number'); |
||
| 70 | $actorId = $input->getArgument('actor-id'); |
||
| 71 | $this->bootstrapService->enrichEventMetadata($actorId); |
||
| 72 | if (!$this->bootstrapService->identityExists($nameId, $institution)) { |
||
| 73 | $output->writeln( |
||
| 74 | sprintf( |
||
| 75 | '<error>An identity with name ID "%s" from institution "%s" does not exist, create it first.</error>', |
||
| 76 | $nameId->getNameId(), |
||
| 77 | $institution->getInstitution(), |
||
| 78 | ), |
||
| 79 | ); |
||
| 80 | |||
| 81 | return 1; |
||
| 82 | } |
||
| 83 | $identity = $this->bootstrapService->getIdentity($nameId, $institution); |
||
| 84 | $output->writeln( |
||
| 85 | sprintf('<comment>Adding a %s SMS token for %s</comment>', $registrationStatus, $identity->commonName), |
||
| 86 | ); |
||
| 87 | $this->transactionHelper->beginTransaction(); |
||
| 88 | $secondFactorId = Uuid::uuid4()->toString(); |
||
| 89 | |||
| 90 | try { |
||
| 91 | switch ($registrationStatus) { |
||
| 92 | case "unverified": |
||
| 93 | $output->writeln('<comment>Creating an unverified SMS token</comment>'); |
||
| 94 | $this->bootstrapService->provePhonePossession($secondFactorId, $identity, $phoneNumber); |
||
| 95 | break; |
||
| 96 | case "verified": |
||
| 97 | $output->writeln('<comment>Creating an unverified SMS token</comment>'); |
||
| 98 | $this->bootstrapService->provePhonePossession($secondFactorId, $identity, $phoneNumber); |
||
| 99 | if ($mailVerificationRequired) { |
||
| 100 | $output->writeln('<comment>Creating a verified SMS token</comment>'); |
||
| 101 | $this->bootstrapService->verifyEmail($identity, 'sms'); |
||
| 102 | } |
||
| 103 | break; |
||
| 104 | case "vetted": |
||
| 105 | $output->writeln('<comment>Creating an unverified SMS token</comment>'); |
||
| 106 | $this->bootstrapService->provePhonePossession($secondFactorId, $identity, $phoneNumber); |
||
| 107 | if ($mailVerificationRequired) { |
||
| 108 | $output->writeln('<comment>Creating a verified SMS token</comment>'); |
||
| 109 | $this->bootstrapService->verifyEmail($identity, 'sms'); |
||
| 110 | } |
||
| 111 | $output->writeln('<comment>Vetting the verified SMS token</comment>'); |
||
| 112 | $this->bootstrapService->vetSecondFactor( |
||
| 113 | 'sms', |
||
| 114 | $actorId, |
||
| 115 | $identity, |
||
| 116 | $secondFactorId, |
||
| 117 | $phoneNumber, |
||
| 118 | ); |
||
| 119 | break; |
||
| 120 | } |
||
| 121 | $this->transactionHelper->finishTransaction(); |
||
| 122 | } catch (Exception $e) { |
||
| 123 | $output->writeln( |
||
| 124 | sprintf( |
||
| 125 | '<error>An Error occurred when trying to bootstrap the SMS token: "%s"</error>', |
||
| 126 | $e->getMessage(), |
||
| 127 | ), |
||
| 128 | ); |
||
| 129 | $this->transactionHelper->rollback(); |
||
| 130 | return 1; |
||
| 131 | } |
||
| 132 | $output->writeln( |
||
| 133 | sprintf( |
||
| 134 | '<info>Successfully registered a SMS token with UUID %s</info>', |
||
| 135 | $secondFactorId, |
||
| 136 | ), |
||
| 137 | ); |
||
| 138 | return 0; |
||
| 139 | } |
||
| 141 |