Passed
Pull Request — main (#308)
by Paul
12:52 queued 05:50
created

GssfStatusController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A renderStatusForm() 0 26 1
A __construct() 0 6 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 Psr\Log\LoggerInterface;
25
use Surfnet\SamlBundle\Http\PostBinding;
26
use Surfnet\SamlBundle\Http\RedirectBinding;
27
use Surfnet\SamlBundle\Http\XMLResponse;
28
use Surfnet\SamlBundle\SAML2\Attribute\AttributeDictionary;
29
use Surfnet\SamlBundle\SAML2\AuthnRequestFactory;
30
use Surfnet\StepupBundle\Value\Provider\ViewConfigCollection;
31
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\MetadataFactoryCollection;
32
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\Provider;
33
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\ProviderRepository;
34
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\ViewConfig;
35
use Surfnet\StepupSelfService\SelfServiceBundle\Controller\Controller;
36
use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\StatusGssfType;
37
use Surfnet\StepupSelfService\SelfServiceBundle\Service\GssfService;
0 ignored issues
show
Bug introduced by
The type Surfnet\StepupSelfServic...dle\Service\GssfService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
use Surfnet\StepupSelfService\SelfServiceBundle\Service\GsspUserAttributeService;
0 ignored issues
show
Bug introduced by
The type Surfnet\StepupSelfServic...sspUserAttributeService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
use Surfnet\StepupSelfService\SelfServiceBundle\Service\InstitutionConfigurationOptionsService;
40
use Symfony\Component\HttpFoundation\Request;
41
use Symfony\Component\HttpFoundation\Response;
42
use Symfony\Component\Routing\Attribute\Route;
43
44
/**
45
 * Controls registration with Generic SAML Stepup Providers (GSSPs), yielding Generic SAML Second Factors (GSSFs).
46
 */
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...
47
final class GssfStatusController extends Controller
48
{
49
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
50
        LoggerInterface           $logger,
51
        InstitutionConfigurationOptionsService     $configurationOptionsService,
52
        private readonly ViewConfigCollection      $viewConfigCollection
53
    ) {
54
        parent::__construct($logger, $configurationOptionsService);
55
    }
56
57
    /**
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...
58
     * Render the status form.
59
     *
60
     * This action has two parameters:
61
     *
62
     * - authenticationFailed (default false), will trigger an error message
63
     *   and is used when a SAML failure response was received, for example
64
     *   when the users cancelled the registration
65
     *
66
     * - proofOfPossessionFailed (default false), will trigger an error message
67
     *   when possession was not proven, but the SAML response was successful
68
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
69
    #[Route(
70
        path: '/registration/gssf/{provider}/status',
71
        name: 'ss_registration_gssf_status_report',
72
        defaults: ['authenticationFailed' => false, 'proofOfPossessionFailed'=> false ],
73
        methods: ['GET'],
74
    )]
75
    public function status(Request $request, string $provider): Response
76
    {
77
        $this->assertSecondFactorEnabled($provider);
78
79
        return $this->renderStatusForm(
80
            $provider,
81
            [
82
                'authenticationFailed' => (bool) $request->query->get('authenticationFailed'),
83
                'proofOfPossessionFailed' => (bool) $request->query->get('proofOfPossessionFailed'),
84
            ]
85
        );
86
    }
87
88
    private function renderStatusForm(string $provider, array $parameters = []): Response
0 ignored issues
show
Coding Style introduced by
Private method name "GssfStatusController::renderStatusForm" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function renderStatusForm()
Loading history...
89
    {
90
        /** @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...
91
        $secondFactorConfig = $this->viewConfigCollection->getByIdentifier($provider);
92
93
        $form = $this->createForm(
94
            StatusGssfType::class,
95
            null,
96
            [
97
                'provider' => $provider,
98
                /** @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...
99
                'label' => $secondFactorConfig->getInitiateButton()
100
            ]
101
        );
102
        $templateParameters = array_merge(
103
            $parameters,
104
            [
105
                'form' => $form->createView(),
106
                'provider' => $provider,
107
                'secondFactorConfig' => $secondFactorConfig,
108
                'verifyEmail' => $this->emailVerificationIsRequired(),
109
            ]
110
        );
111
        return $this->render(
112
            'registration/gssf/status.html.twig',
113
            $templateParameters
114
        );
115
    }
116
}
117