| Conditions | 8 |
| Paths | 31 |
| Total Lines | 85 |
| Lines | 11 |
| Ratio | 12.94 % |
| 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 |
||
| 54 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 55 | { |
||
| 56 | $this->tokenStorage->setToken( |
||
| 57 | new AnonymousToken('cli.bootstrap-identity-with-sms-token', 'cli', ['ROLE_SS', 'ROLE_RA']) |
||
|
|
|||
| 58 | ); |
||
| 59 | $nameId = new NameId($input->getArgument('name-id')); |
||
| 60 | $institutionText = $input->getArgument('institution'); |
||
| 61 | $institution = new Institution($institutionText); |
||
| 62 | $mailVerificationRequired = $this->requiresMailVerification($institutionText); |
||
| 63 | $registrationStatus = $input->getArgument('registration-status'); |
||
| 64 | $phoneNumber = $input->getArgument('phone-number'); |
||
| 65 | $actorId = $input->getArgument('actor-id'); |
||
| 66 | $this->enrichEventMetadata($actorId); |
||
| 67 | View Code Duplication | if (!$this->tokenBootstrapService->hasIdentityWithNameIdAndInstitution($nameId, $institution)) { |
|
| 68 | $output->writeln( |
||
| 69 | sprintf( |
||
| 70 | '<error>An identity with name ID "%s" from institution "%s" does not exist, create it first.</error>', |
||
| 71 | $nameId->getNameId(), |
||
| 72 | $institution->getInstitution() |
||
| 73 | ) |
||
| 74 | ); |
||
| 75 | |||
| 76 | return; |
||
| 77 | } |
||
| 78 | $identity = $this->tokenBootstrapService->findOneByNameIdAndInstitution($nameId, $institution); |
||
| 79 | $output->writeln(sprintf('<comment>Adding a %s SMS token for %s</comment>', $registrationStatus, $identity->commonName)); |
||
| 80 | $this->beginTransaction(); |
||
| 81 | $secondFactorId = Uuid::uuid4()->toString(); |
||
| 82 | |||
| 83 | try { |
||
| 84 | switch ($registrationStatus) { |
||
| 85 | case "unverified": |
||
| 86 | $output->writeln('<comment>Creating an unverified SMS token</comment>'); |
||
| 87 | $this->provePossession($secondFactorId, $identity, $phoneNumber); |
||
| 88 | break; |
||
| 89 | case "verified": |
||
| 90 | $output->writeln('<comment>Creating an unverified SMS token</comment>'); |
||
| 91 | $this->provePossession($secondFactorId, $identity, $phoneNumber); |
||
| 92 | $unverifiedSecondFactor = $this->tokenBootstrapService->findUnverifiedToken($identity->id, 'sms'); |
||
| 93 | if ($mailVerificationRequired) { |
||
| 94 | $output->writeln('<comment>Creating a verified SMS token</comment>'); |
||
| 95 | $this->verifyEmail($identity, $unverifiedSecondFactor); |
||
| 96 | } |
||
| 97 | break; |
||
| 98 | case "vetted": |
||
| 99 | $output->writeln('<comment>Creating an unverified SMS token</comment>'); |
||
| 100 | $this->provePossession($secondFactorId, $identity, $phoneNumber); |
||
| 101 | /** @var UnverifiedSecondFactor $unverifiedSecondFactor */ |
||
| 102 | $unverifiedSecondFactor = $this->tokenBootstrapService->findUnverifiedToken($identity->id, 'sms'); |
||
| 103 | if ($mailVerificationRequired) { |
||
| 104 | $output->writeln('<comment>Creating a verified SMS token</comment>'); |
||
| 105 | $this->verifyEmail($identity, $unverifiedSecondFactor); |
||
| 106 | } |
||
| 107 | $verifiedSecondFactor = $this->tokenBootstrapService->findVerifiedToken($identity->id, 'sms'); |
||
| 108 | $output->writeln('<comment>Vetting the verified SMS token</comment>'); |
||
| 109 | $this->vetSecondFactor( |
||
| 110 | 'sms', |
||
| 111 | $actorId, |
||
| 112 | $identity, |
||
| 113 | $secondFactorId, |
||
| 114 | $verifiedSecondFactor, |
||
| 115 | $phoneNumber |
||
| 116 | ); |
||
| 117 | break; |
||
| 118 | } |
||
| 119 | $this->finishTransaction(); |
||
| 120 | } catch (Exception $e) { |
||
| 121 | $output->writeln( |
||
| 122 | sprintf( |
||
| 123 | '<error>An Error occurred when trying to bootstrap the identity: "%s"</error>', |
||
| 124 | $e->getMessage() |
||
| 125 | ) |
||
| 126 | ); |
||
| 127 | $this->rollback(); |
||
| 128 | throw $e; |
||
| 129 | } |
||
| 130 | $output->writeln( |
||
| 131 | sprintf( |
||
| 132 | '<info>Successfully created identity with UUID %s and %s second factor with UUID %s</info>', |
||
| 133 | $identity->id, |
||
| 134 | $registrationStatus, |
||
| 135 | $secondFactorId |
||
| 136 | ) |
||
| 137 | ); |
||
| 138 | } |
||
| 139 | |||
| 159 |
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: