Conditions | 8 |
Paths | 27 |
Total Lines | 103 |
Code Lines | 81 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
69 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
70 | { |
||
71 | $registrationStatus = $input->getArgument('registration-status'); |
||
72 | $this->bootstrapService->validRegistrationStatus($registrationStatus); |
||
73 | |||
74 | $nameId = new NameId($input->getArgument('name-id')); |
||
75 | $institutionText = $input->getArgument('institution'); |
||
76 | $institution = new Institution($institutionText); |
||
77 | $mailVerificationRequired = $this->bootstrapService->requiresMailVerification($institutionText); |
||
78 | $tokenType = $input->getArgument('gssp-token-type'); |
||
79 | $tokenIdentifier = $input->getArgument('gssp-token-identifier'); |
||
80 | $actorId = $input->getArgument('actor-id'); |
||
81 | $this->bootstrapService->enrichEventMetadata($actorId); |
||
82 | if (!$this->bootstrapService->identityExists($nameId, $institution)) { |
||
83 | $output->writeln( |
||
84 | sprintf( |
||
85 | '<error>An identity with name ID "%s" from institution "%s" does not exist, create it first.</error>', |
||
86 | $nameId->getNameId(), |
||
87 | $institution->getInstitution(), |
||
88 | ), |
||
89 | ); |
||
90 | |||
91 | return 1; |
||
92 | } |
||
93 | $identity = $this->bootstrapService->getIdentity($nameId, $institution); |
||
94 | $output->writeln( |
||
95 | sprintf( |
||
96 | '<comment>Adding a %s %s GSSP token for %s</comment>', |
||
97 | $registrationStatus, |
||
98 | $tokenType, |
||
99 | $identity->commonName, |
||
100 | ), |
||
101 | ); |
||
102 | $this->transactionHelper->beginTransaction(); |
||
103 | $secondFactorId = Uuid::uuid4()->toString(); |
||
104 | |||
105 | try { |
||
106 | switch ($registrationStatus) { |
||
107 | case "unverified": |
||
108 | $output->writeln(sprintf('<comment>Creating an unverified %s token</comment>', $tokenType)); |
||
109 | $this->bootstrapService->proveGsspPossession( |
||
110 | $secondFactorId, |
||
111 | $identity, |
||
112 | $tokenType, |
||
113 | $tokenIdentifier, |
||
114 | ); |
||
115 | break; |
||
116 | case "verified": |
||
117 | $output->writeln(sprintf('<comment>Creating an unverified %s token</comment>', $tokenType)); |
||
118 | $this->bootstrapService->proveGsspPossession( |
||
119 | $secondFactorId, |
||
120 | $identity, |
||
121 | $tokenType, |
||
122 | $tokenIdentifier, |
||
123 | ); |
||
124 | if ($mailVerificationRequired) { |
||
125 | $output->writeln(sprintf('<comment>Creating an verified %s token</comment>', $tokenType)); |
||
126 | $this->bootstrapService->verifyEmail($identity, $tokenType); |
||
127 | } |
||
128 | break; |
||
129 | case "vetted": |
||
130 | $output->writeln(sprintf('<comment>Creating an unverified %s token</comment>', $tokenType)); |
||
131 | $this->bootstrapService->proveGsspPossession( |
||
132 | $secondFactorId, |
||
133 | $identity, |
||
134 | $tokenType, |
||
135 | $tokenIdentifier, |
||
136 | ); |
||
137 | if ($mailVerificationRequired) { |
||
138 | $output->writeln(sprintf('<comment>Creating an verified %s token</comment>', $tokenType)); |
||
139 | $this->bootstrapService->verifyEmail($identity, $tokenType); |
||
140 | } |
||
141 | $output->writeln(sprintf('<comment>Vetting the verified %s token</comment>', $tokenType)); |
||
142 | $this->bootstrapService->vetSecondFactor( |
||
143 | $tokenType, |
||
144 | $actorId, |
||
145 | $identity, |
||
146 | $secondFactorId, |
||
147 | $tokenIdentifier, |
||
148 | ); |
||
149 | break; |
||
150 | } |
||
151 | $this->transactionHelper->finishTransaction(); |
||
152 | } catch (Exception $e) { |
||
153 | $output->writeln( |
||
154 | sprintf( |
||
155 | '<error>An Error occurred when trying to bootstrap the %s token: "%s"</error>', |
||
156 | $tokenType, |
||
157 | $e->getMessage(), |
||
158 | ), |
||
159 | ); |
||
160 | $this->transactionHelper->rollback(); |
||
161 | return 1; |
||
162 | } |
||
163 | $output->writeln( |
||
164 | sprintf( |
||
165 | '<info>Successfully %s %s second factor with UUID %s</info>', |
||
166 | $registrationStatus, |
||
167 | $tokenType, |
||
168 | $secondFactorId, |
||
169 | ), |
||
170 | ); |
||
171 | return 0; |
||
172 | } |
||
174 |