| Conditions | 9 |
| Paths | 120 |
| Total Lines | 100 |
| 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 | $identity = false; |
||
| 76 | $output->writeln(sprintf('<notice>Adding a %s SMS token for %s</notice>', $registrationStatus, $commonName)); |
||
| 77 | |||
| 78 | if ($this->identityRepository->hasIdentityWithNameIdAndInstitution($nameId, $institution)) { |
||
| 79 | $output->writeln( |
||
| 80 | sprintf( |
||
| 81 | '<notice>An identity with name ID "%s" from institution "%s" already exists, using that identity</notice>', |
||
| 82 | $nameId->getNameId(), |
||
| 83 | $institution->getInstitution() |
||
| 84 | ) |
||
| 85 | ); |
||
| 86 | $identity = $this->identityRepository->findOneByNameIdAndInstitution($nameId, $institution); |
||
| 87 | } |
||
| 88 | |||
| 89 | $this->beginTransaction(); |
||
| 90 | $secondFactorId = Uuid::uuid4()->toString(); |
||
| 91 | |||
| 92 | if (!$identity) { |
||
| 93 | $output->writeln('<notice>Creating a new identity</notice>'); |
||
| 94 | $identity = $this->createIdentity($institution, $nameId, $commonName, $email, $preferredLocale); |
||
| 95 | } |
||
| 96 | |||
| 97 | try { |
||
| 98 | switch ($registrationStatus) { |
||
| 99 | case "unverified": |
||
| 100 | $output->writeln('<notice>Creating an unverified SMS token</notice>'); |
||
| 101 | $this->provePossession($secondFactorId, $identity, $phoneNumber); |
||
| 102 | break; |
||
| 103 | case "verified": |
||
| 104 | $output->writeln('<notice>Creating an unverified SMS token</notice>'); |
||
| 105 | $this->provePossession($secondFactorId, $identity, $phoneNumber); |
||
| 106 | /** @var UnverifiedSecondFactor $unverifiedSecondFactor */ |
||
| 107 | $unverifiedSecondFactor = $this->unverifiedSecondFactorRepository->findOneBy( |
||
| 108 | ['identityId' => $identity->id, 'type' => 'sms'] |
||
| 109 | ); |
||
| 110 | if ($mailVerificationRequired) { |
||
| 111 | $output->writeln('<notice>Creating a verified SMS token</notice>'); |
||
| 112 | $this->verifyEmail($identity, $unverifiedSecondFactor); |
||
| 113 | } |
||
| 114 | break; |
||
| 115 | case "vetted": |
||
| 116 | $output->writeln('<notice>Creating an unverified SMS token</notice>'); |
||
| 117 | $this->provePossession($secondFactorId, $identity, $phoneNumber); |
||
| 118 | /** @var UnverifiedSecondFactor $unverifiedSecondFactor */ |
||
| 119 | $unverifiedSecondFactor = $this->unverifiedSecondFactorRepository->findOneBy( |
||
| 120 | ['identityId' => $identity->id, 'type' => 'sms'] |
||
| 121 | ); |
||
| 122 | if ($mailVerificationRequired) { |
||
| 123 | $output->writeln('<notice>Creating a verified SMS token</notice>'); |
||
| 124 | $this->verifyEmail($identity, $unverifiedSecondFactor); |
||
| 125 | } |
||
| 126 | /** @var VerifiedSecondFactor $verifiedSecondFactor */ |
||
| 127 | $verifiedSecondFactor = $this->verifiedSecondFactorRepository->findOneBy( |
||
| 128 | ['identityId' => $identity->id, 'type' => 'sms'] |
||
| 129 | ); |
||
| 130 | $output->writeln('<notice>Vetting the verified SMS token</notice>'); |
||
| 131 | $this->vetSecondFactor( |
||
| 132 | 'sms', |
||
| 133 | 'db9b8bdf-720c-44ba-a4c4-154953e45f14', |
||
| 134 | $identity, |
||
| 135 | $secondFactorId, |
||
| 136 | $verifiedSecondFactor, |
||
| 137 | $phoneNumber |
||
| 138 | ); |
||
| 139 | break; |
||
| 140 | } |
||
| 141 | $this->finishTransaction(); |
||
| 142 | } catch (Exception $e) { |
||
| 143 | $output->writeln( |
||
| 144 | sprintf( |
||
| 145 | '<error>An Error occurred when trying to bootstrap the identity: "%s"</error>', |
||
| 146 | $e->getMessage() |
||
| 147 | ) |
||
| 148 | ); |
||
| 149 | $this->rollback(); |
||
| 150 | throw $e; |
||
| 151 | } |
||
| 152 | $output->writeln( |
||
| 153 | sprintf( |
||
| 154 | '<info>Successfully created identity with UUID %s and %s second factor with UUID %s</info>', |
||
| 155 | $identity->id, |
||
| 156 | $registrationStatus, |
||
| 157 | $secondFactorId |
||
| 158 | ) |
||
| 159 | ); |
||
| 160 | } |
||
| 161 | |||
| 201 |
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: