VettingTypeService   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 45
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A vettingTypeHint() 0 14 4
A __construct() 0 7 1
A vettingTypes() 0 18 3
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\Service;
22
23
use Psr\Log\LoggerInterface;
24
use Surfnet\StepupMiddlewareClientBundle\Exception\NotFoundException;
25
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity;
26
use Surfnet\StepupMiddlewareClientBundle\Identity\Service\VettingTypeHintService;
27
use Surfnet\StepupSelfService\SelfServiceBundle\Value\VettingType\OnPremise;
28
use Surfnet\StepupSelfService\SelfServiceBundle\Value\VettingType\SelfAssertedToken;
29
use Surfnet\StepupSelfService\SelfServiceBundle\Value\VettingType\SelfVet;
30
use Surfnet\StepupSelfService\SelfServiceBundle\Value\VettingType\VettingTypeCollection;
31
32
readonly class VettingTypeService
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class VettingTypeService
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 SelfVetMarshaller $selfVetMarshaller,
36
        private SelfAssertedTokensMarshaller $selfAssertedTokensMarshaller,
37
        private ActivationFlowService $activationFlowService,
38
        private VettingTypeHintService $vettingTypeHintService,
39
        private LoggerInterface $logger
40
    ) {
41
    }
42
43
    public function vettingTypes(Identity $identity, string $secondFactorId): VettingTypeCollection
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function vettingTypes()
Loading history...
44
    {
45
        $collection = new VettingTypeCollection();
46
        $this->logger->info('Adding "OnPremise" vetting type to VettingTypeCollection');
47
        $collection->add(new OnPremise());
48
        if ($this->selfAssertedTokensMarshaller->isAllowed($identity, $secondFactorId)) {
49
            $this->logger->info('Adding "SelfAssertedToken" vetting type to VettingTypeCollection');
50
            $collection->add(new SelfAssertedToken());
51
        }
52
        if ($this->selfVetMarshaller->isAllowed($identity, $secondFactorId)) {
53
            $this->logger->info('Adding "SelfVet" vetting type to VettingTypeCollection');
54
            $collection->add(new SelfVet());
55
        }
56
        $preference = $this->activationFlowService->getPreference();
57
        $this->logger->info(sprintf('Expressing "%s" vetting type as preferred activation flow', $preference));
58
        $collection->expressVettingPreference($preference);
59
60
        return $collection;
61
    }
62
63
    public function vettingTypeHint(string $institution, string $locale): ?string
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function vettingTypeHint()
Loading history...
64
    {
65
        try {
66
            $hint = $this->vettingTypeHintService->findOne($institution);
67
            if ($hint->hints !== []) {
68
                $hintText = array_filter($hint->hints, fn($hintEntry): bool => $hintEntry['locale'] === $locale);
69
                if ($hintText !== []) {
70
                    return reset($hintText)['hint'];
71
                }
72
            }
73
        } catch (NotFoundException) {
74
            // Do nothing for now
75
        }
76
        return null;
77
    }
78
}
79