Passed
Push — feature/build-and-publish-test... ( 5abced...ea0709 )
by
unknown
12:17 queued 03:44
created

Controller::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
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;
22
23
use Psr\Log\LoggerInterface;
24
use Surfnet\StepupMiddlewareClientBundle\Configuration\Dto\InstitutionConfigurationOptions;
25
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity;
26
use Surfnet\StepupSelfService\SelfServiceBundle\Service\InstitutionConfigurationOptionsService;
27
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
28
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
29
use UnexpectedValueException;
30
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
31
32
class Controller extends AbstractController
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Controller
Loading history...
33
{
34
    /**
35
     * Default verify email option as defined by middleware.
36
     */
37
    final public const DEFAULT_VERIFY_EMAIL_OPTION = true;
38
39
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
40
        private readonly LoggerInterface $logger,
41
        private readonly InstitutionConfigurationOptionsService $configurationOptionsService
42
    ) {
43
    }
44
45
    protected function getIdentity(): Identity
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getIdentity()
Loading history...
46
    {
47
        // During authentication, an AuthenticatedIdentity is created, a decorated Identity.
48
        // The app wants to work with the 'regular' Identity DTO from Middleware (client bundle)
49
        // So we extract the entity here
50
51
        return $this->getUser()->getIdentity();
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

51
        return $this->getUser()->/** @scrutinizer ignore-call */ getIdentity();
Loading history...
52
    }
53
54
    protected function assertSecondFactorEnabled(string $type): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function assertSecondFactorEnabled()
Loading history...
55
    {
56
        if (!in_array($type, $this->getParameter('ss.enabled_second_factors'))) {
57
            $this->logger->warning('A controller action was called for a disabled second factor');
58
59
            throw $this->createNotFoundException();
60
        }
61
    }
62
63
    protected function emailVerificationIsRequired(): bool
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function emailVerificationIsRequired()
Loading history...
64
    {
65
        $config = $this->configurationOptionsService
66
            ->getInstitutionConfigurationOptionsFor($this->getIdentity()->institution);
67
68
        if (!$config instanceof InstitutionConfigurationOptions) {
69
            return self::DEFAULT_VERIFY_EMAIL_OPTION;
70
        }
71
72
        return $config->verifyEmail;
73
    }
74
}
75