Passed
Pull Request — main (#308)
by Paul
16:16 queued 09:55
created

YubikeyController::provePossessionAction()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 42
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 7
eloc 27
nc 6
nop 1
dl 0
loc 42
rs 8.5546
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2014 SURFnet bv
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
20
21
namespace Surfnet\StepupSelfService\SelfServiceBundle\Controller\Registration;
22
23
use Symfony\Bridge\Twig\Attribute\Template;
24
use Surfnet\StepupSelfService\SelfServiceBundle\Command\VerifyYubikeyOtpCommand;
25
use Surfnet\StepupSelfService\SelfServiceBundle\Controller\Controller;
26
use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\ProveYubikeyPossessionType;
27
use Surfnet\StepupSelfService\SelfServiceBundle\Service\YubikeySecondFactorService;
28
use Symfony\Component\Form\FormError;
29
use Symfony\Component\HttpFoundation\Request;
30
use Symfony\Component\Routing\Attribute\Route;
31
32
class YubikeyController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class YubikeyController
Loading history...
33
{
34
    #[Template('registration/yubikey/prove_possession.html.twig')]
35
    #[Route(
36
        path: '/registration/yubikey/prove-possession',
37
        name: 'ss_registration_yubikey_prove_possession',
38
        methods: ['GET','POST'],
39
    )]
40
    public function provePossession(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|array
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function provePossession()
Loading history...
41
    {
42
        $this->assertSecondFactorEnabled('yubikey');
43
44
        $identity = $this->getIdentity();
45
46
        $command = new VerifyYubikeyOtpCommand();
47
        $command->identity = $identity->id;
48
        $command->institution = $identity->institution;
49
50
        $form = $this->createForm(ProveYubikeyPossessionType::class, $command)->handleRequest($request);
51
52
        if ($form->isSubmitted() && $form->isValid()) {
53
            /** @var YubikeySecondFactorService $service */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
54
            $service = $this->get('surfnet_stepup_self_service_self_service.service.yubikey_second_factor');
0 ignored issues
show
Bug introduced by
The method get() does not exist on Surfnet\StepupSelfServic...ation\YubikeyController. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
            /** @scrutinizer ignore-call */ 
55
            $service = $this->get('surfnet_stepup_self_service_self_service.service.yubikey_second_factor');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
            $result = $service->provePossession($command);
56
57
            if ($result->isSuccessful()) {
58
                if ($this->emailVerificationIsRequired()) {
59
                    return $this->redirectToRoute(
60
                        'ss_registration_email_verification_email_sent',
61
                        ['secondFactorId' => $result->getSecondFactorId()]
62
                    );
63
                } else {
64
                    return $this->redirectToRoute(
65
                        'ss_second_factor_vetting_types',
66
                        ['secondFactorId' => $result->getSecondFactorId()]
67
                    );
68
                }
69
            } elseif ($result->isOtpInvalid()) {
70
                $this->addFlash('error', 'ss.verify_yubikey_command.otp.otp_invalid');
71
            } elseif ($result->didOtpVerificationFail()) {
72
                $this->addFlash('error', 'ss.verify_yubikey_command.otp.verification_error');
73
            } else {
74
                $this->addFlash('error', 'ss.prove_yubikey_possession.proof_of_possession_failed');
75
            }
76
        }
77
78
        // OTP field is rendered empty in the template.
79
        return [
80
            'form' => $form->createView(),
81
            'verifyEmail' => $this->emailVerificationIsRequired(),
82
        ];
83
    }
84
}
85