Code Duplication    Length = 15-17 lines in 4 locations

src/Surfnet/StepupMiddleware/CommandHandlingBundle/Identity/CommandHandler/IdentityCommandHandler.php 4 locations

@@ 163-177 (lines=15) @@
160
        $this->eventSourcedRepository->save($identity);
161
    }
162
163
    public function handleProveYubikeyPossessionCommand(ProveYubikeyPossessionCommand $command)
164
    {
165
        /** @var IdentityApi $identity */
166
        $identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId));
167
168
        $this->assertSecondFactorIsAllowedFor(new SecondFactorType('yubikey'), $identity->getInstitution());
169
170
        $identity->provePossessionOfYubikey(
171
            new SecondFactorId($command->secondFactorId),
172
            new YubikeyPublicId($command->yubikeyPublicId),
173
            $this->configurableSettings->createNewEmailVerificationWindow()
174
        );
175
176
        $this->eventSourcedRepository->save($identity);
177
    }
178
179
    /**
180
     * @param ProvePhonePossessionCommand $command
@@ 182-196 (lines=15) @@
179
    /**
180
     * @param ProvePhonePossessionCommand $command
181
     */
182
    public function handleProvePhonePossessionCommand(ProvePhonePossessionCommand $command)
183
    {
184
        /** @var IdentityApi $identity */
185
        $identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId));
186
187
        $this->assertSecondFactorIsAllowedFor(new SecondFactorType('sms'), $identity->getInstitution());
188
189
        $identity->provePossessionOfPhone(
190
            new SecondFactorId($command->secondFactorId),
191
            new PhoneNumber($command->phoneNumber),
192
            $this->configurableSettings->createNewEmailVerificationWindow()
193
        );
194
195
        $this->eventSourcedRepository->save($identity);
196
    }
197
198
    /**
199
     * @param ProveGssfPossessionCommand $command
@@ 201-217 (lines=17) @@
198
    /**
199
     * @param ProveGssfPossessionCommand $command
200
     */
201
    public function handleProveGssfPossessionCommand(ProveGssfPossessionCommand $command)
202
    {
203
        /** @var IdentityApi $identity */
204
        $identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId));
205
206
        // Assume tiqr is being used as it is the only GSSF currently supported
207
        $this->assertSecondFactorIsAllowedFor(new SecondFactorType('tiqr'), $identity->getInstitution());
208
209
        $identity->provePossessionOfGssf(
210
            new SecondFactorId($command->secondFactorId),
211
            new StepupProvider($command->stepupProvider),
212
            new GssfId($command->gssfId),
213
            $this->configurableSettings->createNewEmailVerificationWindow()
214
        );
215
216
        $this->eventSourcedRepository->save($identity);
217
    }
218
219
    public function handleProveU2fDevicePossessionCommand(ProveU2fDevicePossessionCommand $command)
220
    {
@@ 219-233 (lines=15) @@
216
        $this->eventSourcedRepository->save($identity);
217
    }
218
219
    public function handleProveU2fDevicePossessionCommand(ProveU2fDevicePossessionCommand $command)
220
    {
221
        /** @var IdentityApi $identity */
222
        $identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId));
223
224
        $this->assertSecondFactorIsAllowedFor(new SecondFactorType('u2f'), $identity->getInstitution());
225
226
        $identity->provePossessionOfU2fDevice(
227
            new SecondFactorId($command->secondFactorId),
228
            new U2fKeyHandle($command->keyHandle),
229
            $this->configurableSettings->createNewEmailVerificationWindow()
230
        );
231
232
        $this->eventSourcedRepository->save($identity);
233
    }
234
235
    /**
236
     * @param VerifyEmailCommand $command