| Conditions | 8 |
| Paths | 27 |
| Total Lines | 82 |
| 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(#[Argument(description: 'The NameID of the identity to create', name: 'name-id')] |
||
| 42 | string $nameId, #[Argument(description: 'The institution of the identity to create', name: 'institution')] |
||
| 43 | string $institution, #[Argument(description: 'The phone number of the user should be formatted like "+31 (0) 612345678"', name: 'phone-number')] |
||
| 44 | string $phoneNumber, #[Argument(description: 'Valid arguments: unverified, verified, vetted', name: 'registration-status')] |
||
| 45 | string $registrationStatus, #[Argument(description: 'The id of the vetting actor', name: 'actor-id')] |
||
| 46 | string $actorId, OutputInterface $output): int |
||
| 47 | { |
||
| 48 | $this->bootstrapService->validRegistrationStatus($registrationStatus); |
||
| 49 | |||
| 50 | $nameId = new NameId($nameId); |
||
| 51 | $institutionText = $institution; |
||
| 52 | $institution = new Institution($institutionText); |
||
| 53 | $mailVerificationRequired = $this->bootstrapService->requiresMailVerification($institutionText); |
||
| 54 | |||
| 55 | $this->bootstrapService->enrichEventMetadata($actorId); |
||
| 56 | if (!$this->bootstrapService->identityExists($nameId, $institution)) { |
||
| 57 | $output->writeln( |
||
| 58 | sprintf( |
||
| 59 | '<error>An identity with name ID "%s" from institution "%s" does not exist, create it first.</error>', |
||
| 60 | $nameId->getNameId(), |
||
| 61 | $institution->getInstitution(), |
||
| 62 | ), |
||
| 63 | ); |
||
| 64 | |||
| 65 | return 1; |
||
| 66 | } |
||
| 67 | $identity = $this->bootstrapService->getIdentity($nameId, $institution); |
||
| 68 | $output->writeln( |
||
| 69 | sprintf('<comment>Adding a %s SMS token for %s</comment>', $registrationStatus, $identity->commonName), |
||
| 70 | ); |
||
| 71 | $this->transactionHelper->beginTransaction(); |
||
| 72 | $secondFactorId = Uuid::uuid4()->toString(); |
||
| 73 | |||
| 74 | try { |
||
| 75 | switch ($registrationStatus) { |
||
| 76 | case "unverified": |
||
| 77 | $output->writeln('<comment>Creating an unverified SMS token</comment>'); |
||
| 78 | $this->bootstrapService->provePhonePossession($secondFactorId, $identity, $phoneNumber); |
||
| 79 | break; |
||
| 80 | case "verified": |
||
| 81 | $output->writeln('<comment>Creating an unverified SMS token</comment>'); |
||
| 82 | $this->bootstrapService->provePhonePossession($secondFactorId, $identity, $phoneNumber); |
||
| 83 | if ($mailVerificationRequired) { |
||
| 84 | $output->writeln('<comment>Creating a verified SMS token</comment>'); |
||
| 85 | $this->bootstrapService->verifyEmail($identity, 'sms'); |
||
| 86 | } |
||
| 87 | break; |
||
| 88 | case "vetted": |
||
| 89 | $output->writeln('<comment>Creating an unverified SMS token</comment>'); |
||
| 90 | $this->bootstrapService->provePhonePossession($secondFactorId, $identity, $phoneNumber); |
||
| 91 | if ($mailVerificationRequired) { |
||
| 92 | $output->writeln('<comment>Creating a verified SMS token</comment>'); |
||
| 93 | $this->bootstrapService->verifyEmail($identity, 'sms'); |
||
| 94 | } |
||
| 95 | $output->writeln('<comment>Vetting the verified SMS token</comment>'); |
||
| 96 | $this->bootstrapService->vetSecondFactor( |
||
| 97 | 'sms', |
||
| 98 | $actorId, |
||
| 99 | $identity, |
||
| 100 | $secondFactorId, |
||
| 101 | $phoneNumber, |
||
| 102 | ); |
||
| 103 | break; |
||
| 104 | } |
||
| 105 | $this->transactionHelper->finishTransaction(); |
||
| 106 | } catch (Exception $e) { |
||
| 107 | $output->writeln( |
||
| 108 | sprintf( |
||
| 109 | '<error>An Error occurred when trying to bootstrap the SMS token: "%s"</error>', |
||
| 110 | $e->getMessage(), |
||
| 111 | ), |
||
| 112 | ); |
||
| 113 | $this->transactionHelper->rollback(); |
||
| 114 | return 1; |
||
| 115 | } |
||
| 116 | $output->writeln( |
||
| 117 | sprintf( |
||
| 118 | '<info>Successfully registered a SMS token with UUID %s</info>', |
||
| 119 | $secondFactorId, |
||
| 120 | ), |
||
| 121 | ); |
||
| 122 | return 0; |
||
| 123 | } |
||
| 125 |
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