applySsoOn2faOptionChangedEvent()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 16
rs 9.9332
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Copyright 2022 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
Missing @link tag in file comment
Loading history...
20
21
namespace Surfnet\StepupMiddleware\GatewayBundle\Projector;
22
23
use Surfnet\Stepup\Configuration\Event\SsoRegistrationBypassOptionChangedEvent;
24
use Surfnet\Stepup\Configuration\Value\SsoOn2faOption;
0 ignored issues
show
Bug introduced by
The type Surfnet\Stepup\Configuration\Value\SsoOn2faOption 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...
25
use Surfnet\Stepup\Configuration\Value\SsoRegistrationBypassOption;
0 ignored issues
show
Bug introduced by
The type Surfnet\Stepup\Configura...egistrationBypassOption 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...
26
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent;
27
use Surfnet\Stepup\Projector\Projector;
28
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent;
29
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent;
30
use Surfnet\Stepup\Configuration\Event\SsoOn2faOptionChangedEvent;
31
use Surfnet\StepupMiddleware\GatewayBundle\Entity\InstitutionConfiguration;
32
use Surfnet\StepupMiddleware\GatewayBundle\Repository\InstitutionConfigurationRepository;
33
34
class InstitutionConfigurationProjector extends Projector
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class InstitutionConfigurationProjector
Loading history...
35
{
36
    public function __construct(private readonly InstitutionConfigurationRepository $repository)
37
    {
38
    }
39
40
    public function applyNewInstitutionConfigurationCreatedEvent(NewInstitutionConfigurationCreatedEvent $event): void
41
    {
42
        $institutionConfiguration = new InstitutionConfiguration(
43
            (string)$event->institution,
44
            $event->ssoOn2faOption->isEnabled(),
45
            $event->ssoRegistrationBypassOption->isEnabled(),
46
        );
47
48
        $this->repository->save($institutionConfiguration);
49
    }
50
51
    public function applySsoOn2faOptionChangedEvent(SsoOn2faOptionChangedEvent $event): void
52
    {
53
        $institutionConfiguration = $this->repository->findByInstitution((string)$event->institution);
54
        if ($institutionConfiguration instanceof InstitutionConfiguration) {
55
            $institutionConfiguration->ssoOn2faEnabled = $event->ssoOn2faOption->isEnabled();
56
            $this->repository->save($institutionConfiguration);
57
            return;
58
        }
59
        // It can happen that the event changed for an institution that already exists, but is not yet projected to
60
        // this projection. In that case we can create it.
61
        $institutionConfiguration = new InstitutionConfiguration(
62
            (string)$event->institution,
63
            $event->ssoOn2faOption->isEnabled(),
64
            SsoRegistrationBypassOption::getDefault()->isEnabled(),
65
        );
66
        $this->repository->save($institutionConfiguration);
67
    }
68
69
    public function applySsoRegistrationBypassOptionChangedEvent(SsoRegistrationBypassOptionChangedEvent $event): void
70
    {
71
        $institutionConfiguration = $this->repository->findByInstitution((string)$event->institution);
72
        if ($institutionConfiguration instanceof InstitutionConfiguration) {
73
            $institutionConfiguration->ssoRegistrationBypass = $event->ssoRegistrationBypassOption->isEnabled();
74
            $this->repository->save($institutionConfiguration);
75
            return;
76
        }
77
        // It can happen that the event changed for an institution that already exists, but is not yet projected to
78
        // this projection. In that case we can create it.
79
        $institutionConfiguration = new InstitutionConfiguration(
80
            (string)$event->institution,
81
            SsoOn2faOption::getDefault()->isEnabled(),
82
            $event->ssoRegistrationBypassOption->isEnabled(),
83
        );
84
        $this->repository->save($institutionConfiguration);
85
    }
86
87
    public function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurationRemovedEvent $event): void
88
    {
89
        $this->repository->removeFor((string)$event->institution);
90
    }
91
92
    protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void
93
    {
94
        // do nothing, no sensitive data in this projection
95
    }
96
}
97