Passed
Pull Request — main (#308)
by Paul
18:42 queued 09:10
created

SmsProofPossessionController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
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\SmsSecondFactorService;
27
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SmsSecondFactorServiceInterface;
28
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
29
use Symfony\Component\HttpFoundation\Request;
30
use Symfony\Component\HttpFoundation\Response;
31
use Symfony\Component\Routing\Attribute\Route;
32
33
class SmsProofPossessionController extends AbstractController
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class SmsProofPossessionController
Loading history...
34
{
35
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
36
        private readonly SmsSecondFactorService $smsSecondFactorService,
37
        private readonly ControllerCheckerService $checkerService,
38
    ) {
39
    }
40
41
    #[Route(
42
        path: '/registration/sms/prove-possession',
43
        name: 'ss_registration_sms_prove_possession',
44
        methods: ['GET','POST'],
45
    )]
46
    public function __invoke(Request $request): Response
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __invoke()
Loading history...
47
    {
48
        $this->checkerService->assertSecondFactorEnabled('sms');
49
50
        if (!$this->smsSecondFactorService->hasSmsVerificationState(SmsSecondFactorServiceInterface::REGISTRATION_SECOND_FACTOR_ID)) {
51
            $this->addFlash('notice', 'ss.registration.sms.alert.no_verification_state');
52
53
            return $this->redirectToRoute('ss_registration_sms_send_challenge');
54
        }
55
56
        $command = new VerifySmsChallengeCommand();
57
58
        $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

58
        $command->identity = $this->getUser()->/** @scrutinizer ignore-call */ getIdentity()->id;
Loading history...
59
60
        $form = $this->createForm(VerifySmsChallengeType::class, $command)->handleRequest($request);
61
62
        if ($form->isSubmitted() && $form->isValid()) {
63
            $result = $this->smsSecondFactorService->provePossession($command);
64
65
            if ($result->isSuccessful()) {
66
                $this->smsSecondFactorService->clearSmsVerificationState(SmsSecondFactorServiceInterface::REGISTRATION_SECOND_FACTOR_ID);
67
                $route = $this->checkerService->emailVerificationIsRequired()
68
                    ? 'ss_registration_email_verification_email_sent'
69
                    : 'ss_second_factor_vetting_types';
70
71
                return $this->redirectToRoute($route, ['secondFactorId' => $result->getSecondFactorId()]);
72
            }
73
74
            match (true) {
75
                $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...
76
                $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...
77
                $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...
78
                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...
79
            };
80
        }
81
82
        return $this->render(
83
            'registration/sms/prove_possession.html.twig',
84
            [
85
                'form' => $form->createView(),
86
                'verifyEmail' => $this->checkerService->emailVerificationIsRequired(),
87
            ]
88
        );
89
    }
90
}
91