| Conditions | 8 |
| Paths | 27 |
| Total Lines | 80 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 | $registrationStatus = $input->getArgument('registration-status'); |
||
| 70 | $yubikey = $input->getArgument('yubikey'); |
||
| 71 | $actorId = $input->getArgument('actor-id'); |
||
| 72 | $this->bootstrapService->enrichEventMetadata($actorId); |
||
| 73 | if (!$this->bootstrapService->identityExists($nameId, $institution)) { |
||
| 74 | $output->writeln( |
||
| 75 | sprintf( |
||
| 76 | '<error>An identity with name ID "%s" from institution "%s" does not exist, create it first.</error>', |
||
| 77 | $nameId->getNameId(), |
||
| 78 | $institution->getInstitution(), |
||
| 79 | ), |
||
| 80 | ); |
||
| 81 | |||
| 82 | return 1; |
||
| 83 | } |
||
| 84 | $identity = $this->bootstrapService->getIdentity($nameId, $institution); |
||
| 85 | $output->writeln( |
||
| 86 | sprintf('<comment>Adding a %s Yubikey token for %s</comment>', $registrationStatus, $identity->commonName), |
||
| 87 | ); |
||
| 88 | $this->transactionHelper->beginTransaction(); |
||
| 89 | $secondFactorId = Uuid::uuid4()->toString(); |
||
| 90 | |||
| 91 | try { |
||
| 92 | switch ($registrationStatus) { |
||
| 93 | case "unverified": |
||
| 94 | $output->writeln('<comment>Creating an unverified Yubikey token</comment>'); |
||
| 95 | $this->bootstrapService->proveYubikeyPossession($secondFactorId, $identity, $yubikey); |
||
| 96 | break; |
||
| 97 | case "verified": |
||
| 98 | $output->writeln('<comment>Creating an unverified Yubikey token</comment>'); |
||
| 99 | $this->bootstrapService->proveYubikeyPossession($secondFactorId, $identity, $yubikey); |
||
| 100 | if ($mailVerificationRequired) { |
||
| 101 | $output->writeln('<comment>Creating a verified Yubikey token</comment>'); |
||
| 102 | $this->bootstrapService->verifyEmail($identity, 'yubikey'); |
||
| 103 | } |
||
| 104 | break; |
||
| 105 | case "vetted": |
||
| 106 | $output->writeln('<comment>Creating an unverified Yubikey token</comment>'); |
||
| 107 | $this->bootstrapService->proveYubikeyPossession($secondFactorId, $identity, $yubikey); |
||
| 108 | if ($mailVerificationRequired) { |
||
| 109 | $output->writeln('<comment>Creating a verified Yubikey token</comment>'); |
||
| 110 | $this->bootstrapService->verifyEmail($identity, 'yubikey'); |
||
| 111 | } |
||
| 112 | $output->writeln('<comment>Vetting the verified Yubikey token</comment>'); |
||
| 113 | $this->bootstrapService->vetSecondFactor( |
||
| 114 | 'yubikey', |
||
| 115 | $actorId, |
||
| 116 | $identity, |
||
| 117 | $secondFactorId, |
||
| 118 | $yubikey, |
||
| 119 | ); |
||
| 120 | break; |
||
| 121 | } |
||
| 122 | $this->transactionHelper->finishTransaction(); |
||
| 123 | } catch (Exception $e) { |
||
| 124 | $output->writeln( |
||
| 125 | sprintf( |
||
| 126 | '<error>An Error occurred when trying to bootstrap the Yubikey token: "%s"</error>', |
||
| 127 | $e->getMessage(), |
||
| 128 | ), |
||
| 129 | ); |
||
| 130 | $this->transactionHelper->rollback(); |
||
| 131 | return 1; |
||
| 132 | } |
||
| 133 | $output->writeln( |
||
| 134 | sprintf( |
||
| 135 | '<info>Successfully registered a second factor with UUID %s</info>', |
||
| 136 | $secondFactorId, |
||
| 137 | ), |
||
| 138 | ); |
||
| 139 | return 0; |
||
| 140 | } |
||
| 142 |