| Conditions | 8 |
| Paths | 27 |
| Total Lines | 88 |
| Code Lines | 58 |
| 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 |
||
| 41 | public function __invoke( |
||
| 42 | #[Argument(description: 'The NameID of the identity to create', name: 'name-id')] |
||
| 43 | string $nameId, |
||
| 44 | #[Argument(description: 'The institution of the identity to create', name: 'institution')] |
||
| 45 | string $institution, |
||
| 46 | #[Argument(description: 'The public ID of the Yubikey. Remove the last 32 characters of a Yubikey OTP to acquire this.', name: 'yubikey')] |
||
| 47 | string $yubikey, |
||
| 48 | #[Argument(description: 'Valid arguments: unverified, verified, vetted', name: 'registration-status')] |
||
| 49 | string $registrationStatus, |
||
| 50 | #[Argument(description: 'The id of the vetting actor', name: 'actor-id')] |
||
| 51 | string $actorId, |
||
| 52 | OutputInterface $output |
||
| 53 | ): int { |
||
| 54 | $this->bootstrapService->validRegistrationStatus($registrationStatus); |
||
| 55 | |||
| 56 | $nameId = new NameId($nameId); |
||
| 57 | $institutionText = $institution; |
||
| 58 | $institution = new Institution($institutionText); |
||
| 59 | $mailVerificationRequired = $this->bootstrapService->requiresMailVerification($institutionText); |
||
| 60 | |||
| 61 | $this->bootstrapService->enrichEventMetadata($actorId); |
||
| 62 | if (!$this->bootstrapService->identityExists($nameId, $institution)) { |
||
| 63 | $output->writeln( |
||
| 64 | sprintf( |
||
| 65 | '<error>An identity with name ID "%s" from institution "%s" does not exist, create it first.</error>', |
||
| 66 | $nameId->getNameId(), |
||
| 67 | $institution->getInstitution(), |
||
| 68 | ), |
||
| 69 | ); |
||
| 70 | |||
| 71 | return 1; |
||
| 72 | } |
||
| 73 | $identity = $this->bootstrapService->getIdentity($nameId, $institution); |
||
| 74 | $output->writeln( |
||
| 75 | sprintf('<comment>Adding a %s Yubikey token for %s</comment>', $registrationStatus, $identity->commonName), |
||
| 76 | ); |
||
| 77 | $this->transactionHelper->beginTransaction(); |
||
| 78 | $secondFactorId = Uuid::uuid4()->toString(); |
||
| 79 | |||
| 80 | try { |
||
| 81 | switch ($registrationStatus) { |
||
| 82 | case "unverified": |
||
| 83 | $output->writeln('<comment>Creating an unverified Yubikey token</comment>'); |
||
| 84 | $this->bootstrapService->proveYubikeyPossession($secondFactorId, $identity, $yubikey); |
||
| 85 | break; |
||
| 86 | case "verified": |
||
| 87 | $output->writeln('<comment>Creating an unverified Yubikey token</comment>'); |
||
| 88 | $this->bootstrapService->proveYubikeyPossession($secondFactorId, $identity, $yubikey); |
||
| 89 | if ($mailVerificationRequired) { |
||
| 90 | $output->writeln('<comment>Creating a verified Yubikey token</comment>'); |
||
| 91 | $this->bootstrapService->verifyEmail($identity, 'yubikey'); |
||
| 92 | } |
||
| 93 | break; |
||
| 94 | case "vetted": |
||
| 95 | $output->writeln('<comment>Creating an unverified Yubikey token</comment>'); |
||
| 96 | $this->bootstrapService->proveYubikeyPossession($secondFactorId, $identity, $yubikey); |
||
| 97 | if ($mailVerificationRequired) { |
||
| 98 | $output->writeln('<comment>Creating a verified Yubikey token</comment>'); |
||
| 99 | $this->bootstrapService->verifyEmail($identity, 'yubikey'); |
||
| 100 | } |
||
| 101 | $output->writeln('<comment>Vetting the verified Yubikey token</comment>'); |
||
| 102 | $this->bootstrapService->vetSecondFactor( |
||
| 103 | 'yubikey', |
||
| 104 | $actorId, |
||
| 105 | $identity, |
||
| 106 | $secondFactorId, |
||
| 107 | $yubikey, |
||
| 108 | ); |
||
| 109 | break; |
||
| 110 | } |
||
| 111 | $this->transactionHelper->finishTransaction(); |
||
| 112 | } catch (Exception $e) { |
||
| 113 | $output->writeln( |
||
| 114 | sprintf( |
||
| 115 | '<error>An Error occurred when trying to bootstrap the Yubikey token: "%s"</error>', |
||
| 116 | $e->getMessage(), |
||
| 117 | ), |
||
| 118 | ); |
||
| 119 | $this->transactionHelper->rollback(); |
||
| 120 | return 1; |
||
| 121 | } |
||
| 122 | $output->writeln( |
||
| 123 | sprintf( |
||
| 124 | '<info>Successfully registered a second factor with UUID %s</info>', |
||
| 125 | $secondFactorId, |
||
| 126 | ), |
||
| 127 | ); |
||
| 128 | return 0; |
||
| 129 | } |
||
| 131 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths