SmsProofPossessionController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 29
dl 0
loc 54
rs 10
c 2
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 0 46 6
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * Copyright 2023 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\Sms;
22
23
use Surfnet\StepupSelfService\SelfServiceBundle\Command\VerifySmsChallengeCommand;
24
use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\VerifySmsChallengeType;
25
use Surfnet\StepupSelfService\SelfServiceBundle\Service\ControllerCheckerService;
26
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SmsSecondFactorServiceInterface;
27
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
28
use Symfony\Component\HttpFoundation\Request;
29
use Symfony\Component\HttpFoundation\Response;
30
use Symfony\Component\Routing\Attribute\Route;
31
32
class SmsProofPossessionController extends AbstractController
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class SmsProofPossessionController
Loading history...
33
{
34
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
35
        private readonly SmsSecondFactorServiceInterface $smsSecondFactorService,
36
        private readonly ControllerCheckerService $checkerService,
37
    ) {
38
    }
39
40
    #[Route(
41
        path: '/registration/sms/prove-possession',
42
        name: 'ss_registration_sms_prove_possession',
43
        methods: ['GET','POST'],
44
    )]
45
    public function __invoke(Request $request): Response
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __invoke()
Loading history...
46
    {
47
        $this->checkerService->assertSecondFactorEnabled('sms');
48
49
        if (!$this->smsSecondFactorService->hasSmsVerificationState(SmsSecondFactorServiceInterface::REGISTRATION_SECOND_FACTOR_ID)) {
50
            $this->addFlash('notice', 'ss.registration.sms.alert.no_verification_state');
51
52
            return $this->redirectToRoute('ss_registration_sms_send_challenge');
53
        }
54
55
        $command = new VerifySmsChallengeCommand();
56
57
        $command->identity = $this->getUser()->getIdentity()->id;
0 ignored issues
show
Bug introduced by
The method getIdentity() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as Surfnet\StepupSelfServic...n\AuthenticatedIdentity. ( Ignorable by Annotation )

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

57
        $command->identity = $this->getUser()->/** @scrutinizer ignore-call */ getIdentity()->id;
Loading history...
58
59
        $form = $this->createForm(VerifySmsChallengeType::class, $command)->handleRequest($request);
60
61
        if ($form->isSubmitted() && $form->isValid()) {
62
            $result = $this->smsSecondFactorService->provePossession($command);
63
64
            if ($result->isSuccessful()) {
65
                $this->smsSecondFactorService->clearSmsVerificationState(SmsSecondFactorServiceInterface::REGISTRATION_SECOND_FACTOR_ID);
66
                $route = $this->checkerService->emailVerificationIsRequired()
67
                    ? 'ss_registration_email_verification_email_sent'
68
                    : 'ss_second_factor_vetting_types';
69
70
                return $this->redirectToRoute($route, ['secondFactorId' => $result->getSecondFactorId()]);
71
            }
72
73
            match (true) {
74
                $result->wasIncorrectChallengeResponseGiven() => $this->addFlash('error', 'ss.prove_phone_possession.incorrect_challenge_response'),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->addFlash('error',...ct_challenge_response') targeting Symfony\Bundle\Framework...tController::addFlash() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
75
                $result->hasChallengeExpired() => $this->addFlash('error', 'ss.prove_phone_possession.challenge_expired'),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->addFlash('error',...ion.challenge_expired') targeting Symfony\Bundle\Framework...tController::addFlash() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
76
                $result->wereTooManyAttemptsMade() => $this->addFlash('error', 'ss.prove_phone_possession.too_many_attempts'),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->addFlash('error',...ion.too_many_attempts') targeting Symfony\Bundle\Framework...tController::addFlash() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
77
                default => $this->addFlash('error', 'ss.prove_phone_possession.proof_of_possession_failed'),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->addFlash('error',..._of_possession_failed') targeting Symfony\Bundle\Framework...tController::addFlash() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
78
            };
79
        }
80
81
        return $this->render(
82
            'registration/sms/prove_possession.html.twig',
83
            [
84
                'form' => $form->createView(),
85
                'verifyEmail' => $this->checkerService->emailVerificationIsRequired(),
86
            ]
87
        );
88
    }
89
}
90