| Conditions | 9 |
| Paths | 120 |
| Total Lines | 90 |
| 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 |
||
| 61 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 62 | { |
||
| 63 | $this->tokenStorage->setToken( |
||
| 64 | new AnonymousToken('cli.bootstrap-identity-with-sms-token', 'cli', ['ROLE_SS', 'ROLE_RA']) |
||
|
|
|||
| 65 | ); |
||
| 66 | $nameId = new NameId($input->getArgument('name-id')); |
||
| 67 | $institutionText = $input->getArgument('institution'); |
||
| 68 | $institution = new Institution($institutionText); |
||
| 69 | $mailVerificationRequired = $this->requiresMailVerification($institutionText); |
||
| 70 | $commonName = $input->getArgument('common-name'); |
||
| 71 | $email = $input->getArgument('email'); |
||
| 72 | $preferredLocale = $input->getArgument('preferred-locale'); |
||
| 73 | $registrationStatus = $input->getArgument('registration-status'); |
||
| 74 | $phoneNumber = $input->getArgument('phone-number'); |
||
| 75 | $actorId = $input->getArgument('actor-id'); |
||
| 76 | $this->enrichEventMetadata($actorId); |
||
| 77 | $identity = false; |
||
| 78 | $output->writeln(sprintf('<notice>Adding a %s SMS token for %s</notice>', $registrationStatus, $commonName)); |
||
| 79 | if ($this->tokenBootstrapService->hasIdentityWithNameIdAndInstitution($nameId, $institution)) { |
||
| 80 | $output->writeln( |
||
| 81 | sprintf( |
||
| 82 | '<notice>An identity with name ID "%s" from institution "%s" already exists, using that identity</notice>', |
||
| 83 | $nameId->getNameId(), |
||
| 84 | $institution->getInstitution() |
||
| 85 | ) |
||
| 86 | ); |
||
| 87 | $identity = $this->tokenBootstrapService->findOneByNameIdAndInstitution($nameId, $institution); |
||
| 88 | } |
||
| 89 | $this->beginTransaction(); |
||
| 90 | $secondFactorId = Uuid::uuid4()->toString(); |
||
| 91 | if (!$identity) { |
||
| 92 | $output->writeln('<notice>Creating a new identity</notice>'); |
||
| 93 | $identity = $this->createIdentity($institution, $nameId, $commonName, $email, $preferredLocale); |
||
| 94 | } |
||
| 95 | try { |
||
| 96 | switch ($registrationStatus) { |
||
| 97 | case "unverified": |
||
| 98 | $output->writeln('<notice>Creating an unverified SMS token</notice>'); |
||
| 99 | $this->provePossession($secondFactorId, $identity, $phoneNumber); |
||
| 100 | break; |
||
| 101 | case "verified": |
||
| 102 | $output->writeln('<notice>Creating an unverified SMS token</notice>'); |
||
| 103 | $this->provePossession($secondFactorId, $identity, $phoneNumber); |
||
| 104 | $unverifiedSecondFactor = $this->tokenBootstrapService->findUnverifiedToken($identity->id, 'sms'); |
||
| 105 | if ($mailVerificationRequired) { |
||
| 106 | $output->writeln('<notice>Creating a verified SMS token</notice>'); |
||
| 107 | $this->verifyEmail($identity, $unverifiedSecondFactor); |
||
| 108 | } |
||
| 109 | break; |
||
| 110 | case "vetted": |
||
| 111 | $output->writeln('<notice>Creating an unverified SMS token</notice>'); |
||
| 112 | $this->provePossession($secondFactorId, $identity, $phoneNumber); |
||
| 113 | /** @var UnverifiedSecondFactor $unverifiedSecondFactor */ |
||
| 114 | $unverifiedSecondFactor = $this->tokenBootstrapService->findUnverifiedToken($identity->id, 'sms'); |
||
| 115 | if ($mailVerificationRequired) { |
||
| 116 | $output->writeln('<notice>Creating a verified SMS token</notice>'); |
||
| 117 | $this->verifyEmail($identity, $unverifiedSecondFactor); |
||
| 118 | } |
||
| 119 | $verifiedSecondFactor = $this->tokenBootstrapService->findVerifiedToken($identity->id, 'sms'); |
||
| 120 | $output->writeln('<notice>Vetting the verified SMS token</notice>'); |
||
| 121 | $this->vetSecondFactor( |
||
| 122 | 'sms', |
||
| 123 | $actorId, |
||
| 124 | $identity, |
||
| 125 | $secondFactorId, |
||
| 126 | $verifiedSecondFactor, |
||
| 127 | $phoneNumber |
||
| 128 | ); |
||
| 129 | break; |
||
| 130 | } |
||
| 131 | $this->finishTransaction(); |
||
| 132 | } catch (Exception $e) { |
||
| 133 | $output->writeln( |
||
| 134 | sprintf( |
||
| 135 | '<error>An Error occurred when trying to bootstrap the identity: "%s"</error>', |
||
| 136 | $e->getMessage() |
||
| 137 | ) |
||
| 138 | ); |
||
| 139 | $this->rollback(); |
||
| 140 | throw $e; |
||
| 141 | } |
||
| 142 | $output->writeln( |
||
| 143 | sprintf( |
||
| 144 | '<info>Successfully created identity with UUID %s and %s second factor with UUID %s</info>', |
||
| 145 | $identity->id, |
||
| 146 | $registrationStatus, |
||
| 147 | $secondFactorId |
||
| 148 | ) |
||
| 149 | ); |
||
| 150 | } |
||
| 151 | |||
| 191 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: