GssfStatusController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 26
dl 0
loc 65
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A renderStatusForm() 0 26 1
A __construct() 0 4 1
A status() 0 15 1
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\Gssf;
22
23
use JMS\TranslationBundle\Annotation\Ignore;
24
use Surfnet\StepupBundle\Value\Provider\ViewConfigCollection;
25
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\ViewConfig;
26
use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\StatusGssfType;
27
use Surfnet\StepupSelfService\SelfServiceBundle\Service\ControllerCheckerService;
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
/**
34
 * Controls registration with Generic SAML Stepup Providers (GSSPs), yielding Generic SAML Second Factors (GSSFs).
35
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
36
final class GssfStatusController extends AbstractController
37
{
38
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
39
        private readonly ViewConfigCollection     $viewConfigCollection,
40
        private readonly ControllerCheckerService $checkerService,
41
    ) {
42
    }
43
44
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $request should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $provider should have a doc-comment as per coding-style.
Loading history...
45
     * Render the status form.
46
     *
47
     * This action has two parameters:
48
     *
49
     * - authenticationFailed (default false), will trigger an error message
50
     *   and is used when a SAML failure response was received, for example
51
     *   when the users cancelled the registration
52
     *
53
     * - proofOfPossessionFailed (default false), will trigger an error message
54
     *   when possession was not proven, but the SAML response was successful
55
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
56
    #[Route(
57
        path: '/registration/gssf/{provider}/status',
58
        name: 'ss_registration_gssf_status_report',
59
        defaults: ['authenticationFailed' => false, 'proofOfPossessionFailed'=> false ],
60
        methods: ['GET'],
61
    )]
62
    public function status(Request $request, string $provider): Response
63
    {
64
        $this->checkerService->assertSecondFactorEnabled($provider);
65
66
        return $this->renderStatusForm(
67
            $provider,
68
            [
69
                'authenticationFailed' => (bool) $request->query->get('authenticationFailed'),
70
                'proofOfPossessionFailed' => (bool) $request->query->get('proofOfPossessionFailed'),
71
            ]
72
        );
73
    }
74
75
    private function renderStatusForm(string $provider, array $parameters = []): Response
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function renderStatusForm()
Loading history...
Coding Style introduced by
Private method name "GssfStatusController::renderStatusForm" must be prefixed with an underscore
Loading history...
76
    {
77
        /** @var ViewConfig $secondFactorConfig */
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
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
78
        $secondFactorConfig = $this->viewConfigCollection->getByIdentifier($provider);
79
80
        $form = $this->createForm(
81
            StatusGssfType::class,
82
            null,
83
            [
84
                'provider' => $provider,
85
                /** @Ignore from translation message extraction */
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
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
86
                'label' => $secondFactorConfig->getInitiateButton()
87
            ]
88
        );
89
        $templateParameters = array_merge(
90
            $parameters,
91
            [
92
                'form' => $form->createView(),
93
                'provider' => $provider,
94
                'secondFactorConfig' => $secondFactorConfig,
95
                'verifyEmail' => $this->checkerService->emailVerificationIsRequired(),
96
            ]
97
        );
98
        return $this->render(
99
            'registration/gssf/status.html.twig',
100
            $templateParameters
101
        );
102
    }
103
}
104