applyUseRaOptionChangedEvent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2016 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\Stepup\Configuration;
20
21
use Broadway\EventSourcing\EventSourcedAggregateRoot;
22
use Surfnet\Stepup\Configuration\Api\InstitutionConfiguration as InstitutionConfigurationInterface;
23
use Surfnet\Stepup\Configuration\Entity\RaLocation;
24
use Surfnet\Stepup\Configuration\Event\AllowedSecondFactorListUpdatedEvent;
25
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent;
26
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent;
27
use Surfnet\Stepup\Configuration\Event\NumberOfTokensPerIdentityOptionChangedEvent;
28
use Surfnet\Stepup\Configuration\Event\RaLocationAddedEvent;
29
use Surfnet\Stepup\Configuration\Event\RaLocationContactInformationChangedEvent;
30
use Surfnet\Stepup\Configuration\Event\RaLocationRelocatedEvent;
31
use Surfnet\Stepup\Configuration\Event\RaLocationRemovedEvent;
32
use Surfnet\Stepup\Configuration\Event\RaLocationRenamedEvent;
33
use Surfnet\Stepup\Configuration\Event\SelectRaaOptionChangedEvent;
34
use Surfnet\Stepup\Configuration\Event\SelfAssertedTokensOptionChangedEvent;
35
use Surfnet\Stepup\Configuration\Event\SelfVetOptionChangedEvent;
36
use Surfnet\Stepup\Configuration\Event\ShowRaaContactInformationOptionChangedEvent;
37
use Surfnet\Stepup\Configuration\Event\SsoOn2faOptionChangedEvent;
38
use Surfnet\Stepup\Configuration\Event\SsoRegistrationBypassOptionChangedEvent;
39
use Surfnet\Stepup\Configuration\Event\UseRaaOptionChangedEvent;
40
use Surfnet\Stepup\Configuration\Event\UseRaLocationsOptionChangedEvent;
41
use Surfnet\Stepup\Configuration\Event\UseRaOptionChangedEvent;
42
use Surfnet\Stepup\Configuration\Event\VerifyEmailOptionChangedEvent;
43
use Surfnet\Stepup\Configuration\Value\AllowedSecondFactorList;
44
use Surfnet\Stepup\Configuration\Value\ContactInformation;
45
use Surfnet\Stepup\Configuration\Value\Institution;
46
use Surfnet\Stepup\Configuration\Value\InstitutionAuthorizationOption;
47
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId;
48
use Surfnet\Stepup\Configuration\Value\InstitutionRole;
49
use Surfnet\Stepup\Configuration\Value\Location;
50
use Surfnet\Stepup\Configuration\Value\NumberOfTokensPerIdentityOption;
51
use Surfnet\Stepup\Configuration\Value\RaLocationId;
52
use Surfnet\Stepup\Configuration\Value\RaLocationList;
53
use Surfnet\Stepup\Configuration\Value\RaLocationName;
54
use Surfnet\Stepup\Configuration\Value\SelfAssertedTokensOption;
0 ignored issues
show
Bug introduced by
The type Surfnet\Stepup\Configura...elfAssertedTokensOption 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...
55
use Surfnet\Stepup\Configuration\Value\SelfVetOption;
0 ignored issues
show
Bug introduced by
The type Surfnet\Stepup\Configuration\Value\SelfVetOption 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...
56
use Surfnet\Stepup\Configuration\Value\ShowRaaContactInformationOption;
57
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...
58
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...
59
use Surfnet\Stepup\Configuration\Value\UseRaLocationsOption;
60
use Surfnet\Stepup\Configuration\Value\VerifyEmailOption;
61
use Surfnet\Stepup\Exception\DomainException;
62
63
/**
64
 * InstitutionConfiguration aggregate root
65
 *
66
 * Some things to know about this aggregate:
67
 *
68
 * 1. The aggregate is instantiated by InstitutionConfigurationCommandHandler by calling the
69
 *    handleReconfigureInstitutionConfigurationOptionsCommand method. It does so, not by using the projections to build
70
 *    the aggregate but by playing the events onto the aggregate.
71
 * 2. If one of the configuration options should be nullable, take a look at the applyUseRaOptionChangedEvent doc block
72
 *
73
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects) Events and value objects
0 ignored issues
show
Coding Style introduced by
Tag value for @SuppressWarnings(PHPMD.CouplingBetweenObjects) tag indented incorrectly; expected 3 spaces but found 1
Loading history...
74
 * @SuppressWarnings(PHPMD.TooManyMethods) AggregateRoot
0 ignored issues
show
Coding Style introduced by
Tag value for @SuppressWarnings(PHPMD.TooManyMethods) tag indented incorrectly; expected 11 spaces but found 1
Loading history...
75
 * @SuppressWarnings(PHPMD.TooManyPublicMethods) AggregateRoot
0 ignored issues
show
Coding Style introduced by
Tag value for @SuppressWarnings(PHPMD.TooManyPublicMethods) tag indented incorrectly; expected 5 spaces but found 1
Loading history...
76
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) AggregateRoot
77
 * @SuppressWarnings(PHPMD.TooManyFields) AggregateRoot
0 ignored issues
show
Coding Style introduced by
Tag value for @SuppressWarnings(PHPMD.TooManyFields) tag indented incorrectly; expected 12 spaces but found 1
Loading history...
78
 */
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...
79
class InstitutionConfiguration extends EventSourcedAggregateRoot implements InstitutionConfigurationInterface
80
{
81
    private InstitutionConfigurationId $institutionConfigurationId;
82
83
    private Institution $institution;
84
85
    private ?RaLocationList $raLocations = null;
86
87
    private UseRaLocationsOption $useRaLocationsOption;
88
89
    private ShowRaaContactInformationOption $showRaaContactInformationOption;
90
91
    private VerifyEmailOption $verifyEmailOption;
92
93
    private NumberOfTokensPerIdentityOption $numberOfTokensPerIdentityOption;
94
95
    private SelfVetOption $selfVetOption;
96
97
    private ?SsoOn2faOption $ssoOn2faOption = null;
98
99
    private ?SsoRegistrationBypassOption $ssoRegistrationBypassOption = null;
100
101
    private ?SelfAssertedTokensOption $selfAssertedTokensOption = null;
102
103
    private ?InstitutionAuthorizationOption $useRaOption = null;
104
105
    private ?InstitutionAuthorizationOption $useRaaOption = null;
106
107
    private ?InstitutionAuthorizationOption $selectRaaOption = null;
108
109
    private ?AllowedSecondFactorList $allowedSecondFactorList = null;
110
111
    private ?bool $isMarkedAsDestroyed = null;
112
113
    public static function create(
114
        InstitutionConfigurationId $institutionConfigurationId,
115
        Institution $institution,
116
    ): self {
117
        $institutionConfiguration = new self;
118
        $institutionConfiguration->apply(
119
            new NewInstitutionConfigurationCreatedEvent(
120
                $institutionConfigurationId,
121
                $institution,
122
                UseRaLocationsOption::getDefault(),
123
                ShowRaaContactInformationOption::getDefault(),
124
                VerifyEmailOption::getDefault(),
125
                NumberOfTokensPerIdentityOption::getDefault(),
126
                SsoOn2faOption::getDefault(),
127
                SsoRegistrationBypassOption::getDefault(),
128
                SelfVetOption::getDefault(),
129
                SelfAssertedTokensOption::getDefault(),
130
            ),
131
        );
132
        $institutionConfiguration->apply(
133
            new AllowedSecondFactorListUpdatedEvent(
134
                $institutionConfigurationId,
135
                $institution,
136
                AllowedSecondFactorList::blank(),
137
            ),
138
        );
139
        $institutionConfiguration->apply(
140
            new UseRaOptionChangedEvent(
141
                $institutionConfigurationId,
142
                $institution,
143
                InstitutionAuthorizationOption::getDefault(InstitutionRole::useRa()),
144
            ),
145
        );
146
        $institutionConfiguration->apply(
147
            new UseRaaOptionChangedEvent(
148
                $institutionConfigurationId,
149
                $institution,
150
                InstitutionAuthorizationOption::getDefault(InstitutionRole::useRaa()),
151
            ),
152
        );
153
        $institutionConfiguration->apply(
154
            new SelectRaaOptionChangedEvent(
155
                $institutionConfigurationId,
156
                $institution,
157
                InstitutionAuthorizationOption::getDefault(InstitutionRole::selectRaa()),
158
            ),
159
        );
160
161
        return $institutionConfiguration;
162
    }
163
164
    public function rebuild(): self
165
    {
166
        // We can only rebuild a destroyed InstitutionConfiguration, all other cases are not valid
167
        if ($this->isMarkedAsDestroyed !== true) {
168
            throw new DomainException('Cannot rebuild InstitutionConfiguration as it has not been destroyed');
169
        }
170
171
        $this->apply(
172
            new NewInstitutionConfigurationCreatedEvent(
173
                $this->institutionConfigurationId,
174
                $this->institution,
175
                UseRaLocationsOption::getDefault(),
176
                ShowRaaContactInformationOption::getDefault(),
177
                VerifyEmailOption::getDefault(),
178
                NumberOfTokensPerIdentityOption::getDefault(),
179
                SsoOn2faOption::getDefault(),
180
                SsoRegistrationBypassOption::getDefault(),
181
                SelfVetOption::getDefault(),
182
                SelfAssertedTokensOption::getDefault(),
183
            ),
184
        );
185
        $this->apply(
186
            new AllowedSecondFactorListUpdatedEvent(
187
                $this->institutionConfigurationId,
188
                $this->institution,
189
                AllowedSecondFactorList::blank(),
190
            ),
191
        );
192
        $this->apply(
193
            new UseRaOptionChangedEvent(
194
                $this->institutionConfigurationId,
195
                $this->institution,
196
                InstitutionAuthorizationOption::getDefault(InstitutionRole::useRa()),
197
            ),
198
        );
199
        $this->apply(
200
            new UseRaaOptionChangedEvent(
201
                $this->institutionConfigurationId,
202
                $this->institution,
203
                InstitutionAuthorizationOption::getDefault(InstitutionRole::useRaa()),
204
            ),
205
        );
206
        $this->apply(
207
            new SelectRaaOptionChangedEvent(
208
                $this->institutionConfigurationId,
209
                $this->institution,
210
                InstitutionAuthorizationOption::getDefault(InstitutionRole::selectRaa()),
211
            ),
212
        );
213
214
        return $this;
215
    }
216
217
    final public function __construct()
218
    {
219
    }
220
221
    public function configureUseRaLocationsOption(UseRaLocationsOption $useRaLocationsOption): void
222
    {
223
        if ($this->useRaLocationsOption->equals($useRaLocationsOption)) {
224
            return;
225
        }
226
227
        $this->apply(
228
            new UseRaLocationsOptionChangedEvent(
229
                $this->institutionConfigurationId,
230
                $this->institution,
231
                $useRaLocationsOption,
232
            ),
233
        );
234
    }
235
236
    public function configureShowRaaContactInformationOption(
237
        ShowRaaContactInformationOption $showRaaContactInformationOption,
238
    ): void {
239
        if ($this->showRaaContactInformationOption->equals($showRaaContactInformationOption)) {
240
            return;
241
        }
242
243
        $this->apply(
244
            new ShowRaaContactInformationOptionChangedEvent(
245
                $this->institutionConfigurationId,
246
                $this->institution,
247
                $showRaaContactInformationOption,
248
            ),
249
        );
250
    }
251
252
    public function configureVerifyEmailOption(VerifyEmailOption $verifyEmailOption): void
253
    {
254
        if ($this->verifyEmailOption->equals($verifyEmailOption)) {
255
            return;
256
        }
257
258
        $this->apply(
259
            new VerifyEmailOptionChangedEvent(
260
                $this->institutionConfigurationId,
261
                $this->institution,
262
                $verifyEmailOption,
263
            ),
264
        );
265
    }
266
267
    public function configureNumberOfTokensPerIdentityOption(
268
        NumberOfTokensPerIdentityOption $numberOfTokensPerIdentityOption,
269
    ): void {
270
        if ($this->numberOfTokensPerIdentityOption->equals($numberOfTokensPerIdentityOption)) {
271
            return;
272
        }
273
274
        $this->apply(
275
            new NumberOfTokensPerIdentityOptionChangedEvent(
276
                $this->institutionConfigurationId,
277
                $this->institution,
278
                $numberOfTokensPerIdentityOption,
279
            ),
280
        );
281
    }
282
283
    public function configureSelfVetOption(SelfVetOption $selfVetOption): void
284
    {
285
        if ($this->selfVetOption->equals($selfVetOption)) {
286
            return;
287
        }
288
289
        $this->apply(
290
            new SelfVetOptionChangedEvent(
291
                $this->institutionConfigurationId,
292
                $this->institution,
293
                $selfVetOption,
294
            ),
295
        );
296
    }
297
298
    public function configureSelfAssertedTokensOption(SelfAssertedTokensOption $selfAssertedTokensOption): void
299
    {
300
        if ($this->selfAssertedTokensOption instanceof \Surfnet\Stepup\Configuration\Value\SelfAssertedTokensOption &&
301
            $this->selfAssertedTokensOption->equals($selfAssertedTokensOption)
0 ignored issues
show
Coding Style introduced by
Each line in a multi-line IF statement must begin with a boolean operator
Loading history...
302
        ) {
303
            return;
304
        }
305
306
        $this->apply(
307
            new SelfAssertedTokensOptionChangedEvent(
308
                $this->institutionConfigurationId,
309
                $this->institution,
310
                $selfAssertedTokensOption,
311
            ),
312
        );
313
    }
314
315
    public function configureSsoOn2faOption(SsoOn2faOption $ssoOn2faOption): void
316
    {
317
        if ($this->ssoOn2faOption instanceof \Surfnet\Stepup\Configuration\Value\SsoOn2faOption && $this->ssoOn2faOption->equals($ssoOn2faOption)) {
318
            return;
319
        }
320
321
        $this->apply(
322
            new SsoOn2faOptionChangedEvent(
323
                $this->institutionConfigurationId,
324
                $this->institution,
325
                $ssoOn2faOption,
326
            ),
327
        );
328
    }
329
330
    public function configureSsoRegistrationBypassOption(SsoRegistrationBypassOption $ssoRegistrationBypassOption): void
331
    {
332
        if ($this->ssoRegistrationBypassOption instanceof SsoRegistrationBypassOption
333
            && $this->ssoRegistrationBypassOption->equals($ssoRegistrationBypassOption)) {
0 ignored issues
show
Coding Style introduced by
Closing parenthesis of a multi-line IF statement must be on a new line
Loading history...
334
            return;
335
        }
336
337
        $this->apply(
338
            new SsoRegistrationBypassOptionChangedEvent(
339
                $this->institutionConfigurationId,
340
                $this->institution,
341
                $ssoRegistrationBypassOption
342
            )
343
        );
344
    }
345
346
    public function updateUseRaOption(InstitutionAuthorizationOption $useRaOption): void
347
    {
348
        if ($this->useRaOption instanceof \Surfnet\Stepup\Configuration\Value\InstitutionAuthorizationOption
349
            && $this->useRaOption->equals($useRaOption)
350
        ) {
351
            return;
352
        }
353
354
        $this->apply(
355
            new UseRaOptionChangedEvent(
356
                $this->institutionConfigurationId,
357
                $this->institution,
358
                $useRaOption,
359
            ),
360
        );
361
    }
362
363
    public function updateUseRaaOption(InstitutionAuthorizationOption $useRaaOption): void
364
    {
365
        if ($this->useRaaOption instanceof \Surfnet\Stepup\Configuration\Value\InstitutionAuthorizationOption
366
            && $this->useRaaOption->equals($useRaaOption)
367
        ) {
368
            return;
369
        }
370
371
        $this->apply(
372
            new UseRaaOptionChangedEvent(
373
                $this->institutionConfigurationId,
374
                $this->institution,
375
                $useRaaOption,
376
            ),
377
        );
378
    }
379
380
    public function updateSelectRaaOption(InstitutionAuthorizationOption $selectRaaOption): void
381
    {
382
        if ($this->selectRaaOption instanceof \Surfnet\Stepup\Configuration\Value\InstitutionAuthorizationOption
383
            && $this->selectRaaOption->equals($selectRaaOption)
384
        ) {
385
            return;
386
        }
387
388
        $this->apply(
389
            new SelectRaaOptionChangedEvent(
390
                $this->institutionConfigurationId,
391
                $this->institution,
392
                $selectRaaOption,
393
            ),
394
        );
395
    }
396
397
    public function updateAllowedSecondFactorList(AllowedSecondFactorList $allowedSecondFactorList): void
398
    {
399
        // AllowedSecondFactorList can be null for InstitutionConfigurations for which this functionality did not exist
400
        if ($this->allowedSecondFactorList instanceof \Surfnet\Stepup\Configuration\Value\AllowedSecondFactorList
401
            && $this->allowedSecondFactorList->equals($allowedSecondFactorList)
402
        ) {
403
            return;
404
        }
405
406
        $this->apply(
407
            new AllowedSecondFactorListUpdatedEvent(
408
                $this->institutionConfigurationId,
409
                $this->institution,
410
                $allowedSecondFactorList,
411
            ),
412
        );
413
    }
414
415
    /**
416
     * @param RaLocationId $raLocationId
0 ignored issues
show
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
417
     * @param RaLocationName $raLocationName
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
418
     * @param Location $location
0 ignored issues
show
Coding Style introduced by
Expected 11 spaces after parameter type; 1 found
Loading history...
419
     * @param ContactInformation $contactInformation
420
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
421
    public function addRaLocation(
422
        RaLocationId $raLocationId,
423
        RaLocationName $raLocationName,
424
        Location $location,
425
        ContactInformation $contactInformation,
426
    ): void {
427
        if ($this->raLocations->containsWithId($raLocationId)) {
0 ignored issues
show
Bug introduced by
The method containsWithId() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

427
        if ($this->raLocations->/** @scrutinizer ignore-call */ containsWithId($raLocationId)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
428
            throw new DomainException(
429
                sprintf(
430
                    'Cannot add RaLocation with RaLocationId "%s" to RaLocations of InstitutionConfiguration "%s":'
431
                    . ' it is already present',
432
                    $raLocationId,
433
                    $this->getAggregateRootId(),
434
                ),
435
            );
436
        }
437
438
        $this->apply(
439
            new RaLocationAddedEvent(
440
                $this->institutionConfigurationId,
441
                $this->institution,
442
                $raLocationId,
443
                $raLocationName,
444
                $location,
445
                $contactInformation,
446
            ),
447
        );
448
    }
449
450
    /**
451
     * @param RaLocationId $raLocationId
0 ignored issues
show
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
452
     * @param RaLocationName $raLocationName
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
453
     * @param Location $location
0 ignored issues
show
Coding Style introduced by
Expected 11 spaces after parameter type; 1 found
Loading history...
454
     * @param ContactInformation $contactInformation
455
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
456
    public function changeRaLocation(
457
        RaLocationId $raLocationId,
458
        RaLocationName $raLocationName,
459
        Location $location,
460
        ContactInformation $contactInformation,
461
    ): void {
462
        if (!$this->raLocations->containsWithId($raLocationId)) {
463
            throw new DomainException(
464
                sprintf(
465
                    'Cannot change RaLocation with RaLocationId "%s" in RaLocations of InstitutionConfiguration "%s":'
466
                    . ' it is not present',
467
                    $raLocationId,
468
                    $this->getAggregateRootId(),
469
                ),
470
            );
471
        }
472
473
        $raLocation = $this->raLocations->getById($raLocationId);
474
475
        if (!$raLocation->getName()->equals($raLocationName)) {
476
            $this->apply(
477
                new RaLocationRenamedEvent($this->institutionConfigurationId, $raLocationId, $raLocationName),
478
            );
479
        }
480
        if (!$raLocation->getLocation()->equals($location)) {
481
            $this->apply(
482
                new RaLocationRelocatedEvent($this->institutionConfigurationId, $raLocationId, $location),
483
            );
484
        }
485
        if (!$raLocation->getContactInformation()->equals($contactInformation)) {
486
            $this->apply(
487
                new RaLocationContactInformationChangedEvent(
488
                    $this->institutionConfigurationId,
489
                    $raLocationId,
490
                    $contactInformation,
491
                ),
492
            );
493
        }
494
    }
495
496
    /**
497
     * @param RaLocationId $raLocationId
498
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
499
    public function removeRaLocation(RaLocationId $raLocationId): void
500
    {
501
        if (!$this->raLocations->containsWithId($raLocationId)) {
502
            throw new DomainException(
503
                sprintf(
504
                    'Cannot remove RaLocation with RaLocationId "%s" in RaLocations of InstitutionConfiguration "%s":'
505
                    . ' it is not present',
506
                    $raLocationId,
507
                    $this->getAggregateRootId(),
508
                ),
509
            );
510
        }
511
512
        $this->apply(new RaLocationRemovedEvent($this->institutionConfigurationId, $raLocationId));
513
    }
514
515
    /**
516
     * @return void
517
     */
518
    public function destroy(): void
519
    {
520
        $this->apply(new InstitutionConfigurationRemovedEvent($this->institutionConfigurationId, $this->institution));
521
    }
522
523
    public function getAggregateRootId(): string
524
    {
525
        return $this->institutionConfigurationId;
526
    }
527
528
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $institution should have a doc-comment as per coding-style.
Loading history...
529
     * Check if role from institution is allowed to accredit roles
530
     *
531
     */
0 ignored issues
show
Coding Style introduced by
Additional blank lines found at end of doc comment
Loading history...
Coding Style introduced by
Missing @return tag in function comment
Loading history...
532
    public function isInstitutionAllowedToAccreditRoles(Institution $institution): bool
533
    {
534
        // This method is needed to support the situation pre FGA. In that situation the SelectRaaOptionChanged wasn't
535
        // fired and that would result in a situation were $this->selectRaaOption is null. If that occurs we should check
536
        // if the institution of the identity is the institution to validate.
537
        if ($this->selectRaaOption == null) {
538
            return $this->institution->equals($institution);
539
        }
540
        return $this->selectRaaOption->hasInstitution($institution, $this->institution);
541
    }
542
543
    protected function applyNewInstitutionConfigurationCreatedEvent(NewInstitutionConfigurationCreatedEvent $event): void
544
    {
545
        $this->institutionConfigurationId = $event->institutionConfigurationId;
546
        $this->institution = $event->institution;
547
        $this->useRaLocationsOption = $event->useRaLocationsOption;
548
        $this->showRaaContactInformationOption = $event->showRaaContactInformationOption;
549
        $this->verifyEmailOption = $event->verifyEmailOption;
550
        $this->selfVetOption = $event->selfVetOption;
551
        $this->ssoOn2faOption = $event->ssoOn2faOption;
552
        $this->ssoRegistrationBypassOption = $event->ssoRegistrationBypassOption;
553
        $this->selfAssertedTokensOption = $event->selfAssertedTokensOption;
554
        $this->numberOfTokensPerIdentityOption = $event->numberOfTokensPerIdentityOption;
555
        $this->raLocations = new RaLocationList([]);
556
        $this->isMarkedAsDestroyed = false;
557
    }
558
559
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $event should have a doc-comment as per coding-style.
Loading history...
560
     * Apply the UseRaOptionChangedEvent
561
     *
562
     * To ensure the aggregate is correctly populated with the FGA options we ensure the UseRaOptionChangedEvent
563
     * can be applied on the aggregate. Refraining from doing this would result in the $this->useRaOption field only
564
     * being applied when applyNewInstitutionConfigurationCreatedEvent is called. And this might not be the case if
565
     * the fields where null'ed (removed from configuration).
566
     *
567
     * This also applies for applyUseRaaOptionChangedEvent & applySelectRaaOptionChangedEvent
568
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
569
    protected function applyUseRaOptionChangedEvent(UseRaOptionChangedEvent $event): void
570
    {
571
        $this->useRaOption = $event->useRaOption;
572
    }
573
574
    protected function applyUseRaaOptionChangedEvent(UseRaaOptionChangedEvent $event): void
575
    {
576
        $this->useRaaOption = $event->useRaaOption;
577
    }
578
579
    protected function applySelectRaaOptionChangedEvent(SelectRaaOptionChangedEvent $event): void
580
    {
581
        $this->selectRaaOption = $event->selectRaaOption;
582
    }
583
584
    protected function applyUseRaLocationsOptionChangedEvent(UseRaLocationsOptionChangedEvent $event): void
585
    {
586
        $this->useRaLocationsOption = $event->useRaLocationsOption;
587
    }
588
589
    protected function applyShowRaaContactInformationOptionChangedEvent(
590
        ShowRaaContactInformationOptionChangedEvent $event,
591
    ): void {
592
        $this->showRaaContactInformationOption = $event->showRaaContactInformationOption;
593
    }
594
595
    protected function applyVerifyEmailOptionChangedEvent(
596
        VerifyEmailOptionChangedEvent $event,
597
    ): void {
598
        $this->verifyEmailOption = $event->verifyEmailOption;
599
    }
600
601
    protected function applySelfVetOptionChangedEvent(
602
        SelfVetOptionChangedEvent $event,
603
    ): void {
604
        $this->selfVetOption = $event->selfVetOption;
605
    }
606
607
    protected function applySelfAssertedTokensOptionChangedEvent(
608
        SelfAssertedTokensOptionChangedEvent $event,
609
    ): void {
610
        $this->selfAssertedTokensOption = $event->selfAssertedTokensOption;
611
    }
612
613
    protected function applySsoOn2faOptionChangedEvent(
614
        SsoOn2faOptionChangedEvent $event,
615
    ): void {
616
        $this->ssoOn2faOption = $event->ssoOn2faOption;
617
    }
618
619
    protected function applySsoRegistrationBypassOptionChangedEvent(
620
        SsoRegistrationBypassOptionChangedEvent $event,
621
    ): void {
622
        $this->ssoRegistrationBypassOption = $event->ssoRegistrationBypassOption;
623
    }
624
625
    protected function applyNumberOfTokensPerIdentityOptionChangedEvent(
626
        NumberOfTokensPerIdentityOptionChangedEvent $event,
627
    ): void {
628
        $this->numberOfTokensPerIdentityOption = $event->numberOfTokensPerIdentityOption;
629
    }
630
631
    protected function applyAllowedSecondFactorListUpdatedEvent(AllowedSecondFactorListUpdatedEvent $event): void
632
    {
633
        $this->allowedSecondFactorList = $event->allowedSecondFactorList;
634
    }
635
636
    protected function applyRaLocationAddedEvent(RaLocationAddedEvent $event): void
637
    {
638
        $this->raLocations->add(
639
            RaLocation::create(
640
                $event->raLocationId,
641
                $event->raLocationName,
642
                $event->location,
643
                $event->contactInformation,
644
            ),
645
        );
646
    }
647
648
    protected function applyRaLocationRenamedEvent(RaLocationRenamedEvent $event): void
649
    {
650
        $raLocation = $this->raLocations->getById($event->raLocationId);
651
        $raLocation->rename($event->raLocationName);
652
    }
653
654
    protected function applyRaLocationRelocatedEvent(RaLocationRelocatedEvent $event): void
655
    {
656
        $raLocation = $this->raLocations->getById($event->raLocationId);
657
        $raLocation->relocate($event->location);
658
    }
659
660
    protected function applyRaLocationContactInformationChangedEvent(RaLocationContactInformationChangedEvent $event): void
661
    {
662
        $raLocation = $this->raLocations->getById($event->raLocationId);
663
        $raLocation->changeContactInformation($event->contactInformation);
664
    }
665
666
    protected function applyRaLocationRemovedEvent(RaLocationRemovedEvent $event): void
667
    {
668
        $this->raLocations->removeWithId($event->raLocationId);
669
    }
670
671
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $event should have a doc-comment as per coding-style.
Loading history...
672
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
673
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
674
    protected function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurationRemovedEvent $event): void
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

674
    protected function applyInstitutionConfigurationRemovedEvent(/** @scrutinizer ignore-unused */ InstitutionConfigurationRemovedEvent $event): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
675
    {
676
        // reset all configuration to defaults. This way, should it be rebuild, it seems like it is new again
677
        $this->raLocations = new RaLocationList([]);
678
        $this->useRaLocationsOption = UseRaLocationsOption::getDefault();
679
        $this->showRaaContactInformationOption = ShowRaaContactInformationOption::getDefault();
680
        $this->verifyEmailOption = VerifyEmailOption::getDefault();
681
        $this->numberOfTokensPerIdentityOption = NumberOfTokensPerIdentityOption::getDefault();
682
        $this->allowedSecondFactorList = AllowedSecondFactorList::blank();
683
        $this->useRaOption = InstitutionAuthorizationOption::getDefault(InstitutionRole::useRa());
684
        $this->useRaaOption = InstitutionAuthorizationOption::getDefault(InstitutionRole::useRaa());
685
        $this->selectRaaOption = InstitutionAuthorizationOption::getDefault(InstitutionRole::selectRaa());
686
687
        $this->isMarkedAsDestroyed = true;
688
    }
689
}
690