Passed
Pull Request — main (#540)
by
unknown
22:35 queued 17:16
created

InstitutionConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
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
 */
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...
78
class InstitutionConfiguration extends EventSourcedAggregateRoot implements InstitutionConfigurationInterface
79
{
80
    private InstitutionConfigurationId $institutionConfigurationId;
81
82
    private Institution $institution;
83
84
    private ?RaLocationList $raLocations = null;
85
86
    private UseRaLocationsOption $useRaLocationsOption;
87
88
    private ShowRaaContactInformationOption $showRaaContactInformationOption;
89
90
    private VerifyEmailOption $verifyEmailOption;
91
92
    private NumberOfTokensPerIdentityOption $numberOfTokensPerIdentityOption;
93
94
    private SelfVetOption $selfVetOption;
95
96
    private ?SsoOn2faOption $ssoOn2faOption = null;
97
98
    private ?SsoRegistrationBypassOption $ssoRegistrationBypassOption = null;
99
100
    private ?SelfAssertedTokensOption $selfAssertedTokensOption = null;
101
102
    private ?InstitutionAuthorizationOption $useRaOption = null;
103
104
    private ?InstitutionAuthorizationOption $useRaaOption = null;
105
106
    private ?InstitutionAuthorizationOption $selectRaaOption = null;
107
108
    private ?AllowedSecondFactorList $allowedSecondFactorList = null;
109
110
    private ?bool $isMarkedAsDestroyed = null;
111
112
    public static function create(
113
        InstitutionConfigurationId $institutionConfigurationId,
114
        Institution $institution,
115
    ): self {
116
        $institutionConfiguration = new self;
117
        $institutionConfiguration->apply(
118
            new NewInstitutionConfigurationCreatedEvent(
119
                $institutionConfigurationId,
120
                $institution,
121
                UseRaLocationsOption::getDefault(),
122
                ShowRaaContactInformationOption::getDefault(),
123
                VerifyEmailOption::getDefault(),
124
                NumberOfTokensPerIdentityOption::getDefault(),
125
                SsoOn2faOption::getDefault(),
126
                SsoRegistrationBypassOption::getDefault(),
127
                SelfVetOption::getDefault(),
128
                SelfAssertedTokensOption::getDefault(),
129
            ),
130
        );
131
        $institutionConfiguration->apply(
132
            new AllowedSecondFactorListUpdatedEvent(
133
                $institutionConfigurationId,
134
                $institution,
135
                AllowedSecondFactorList::blank(),
136
            ),
137
        );
138
        $institutionConfiguration->apply(
139
            new UseRaOptionChangedEvent(
140
                $institutionConfigurationId,
141
                $institution,
142
                InstitutionAuthorizationOption::getDefault(InstitutionRole::useRa()),
143
            ),
144
        );
145
        $institutionConfiguration->apply(
146
            new UseRaaOptionChangedEvent(
147
                $institutionConfigurationId,
148
                $institution,
149
                InstitutionAuthorizationOption::getDefault(InstitutionRole::useRaa()),
150
            ),
151
        );
152
        $institutionConfiguration->apply(
153
            new SelectRaaOptionChangedEvent(
154
                $institutionConfigurationId,
155
                $institution,
156
                InstitutionAuthorizationOption::getDefault(InstitutionRole::selectRaa()),
157
            ),
158
        );
159
160
        return $institutionConfiguration;
161
    }
162
163
    public function rebuild(): self
164
    {
165
        // We can only rebuild a destroyed InstitutionConfiguration, all other cases are not valid
166
        if ($this->isMarkedAsDestroyed !== true) {
167
            throw new DomainException('Cannot rebuild InstitutionConfiguration as it has not been destroyed');
168
        }
169
170
        $this->apply(
171
            new NewInstitutionConfigurationCreatedEvent(
0 ignored issues
show
Bug introduced by
The call to Surfnet\Stepup\Configura...tedEvent::__construct() has too few arguments starting with selfAssertedTokensOption. ( Ignorable by Annotation )

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

171
            /** @scrutinizer ignore-call */ 
172
            new NewInstitutionConfigurationCreatedEvent(

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
172
                $this->institutionConfigurationId,
173
                $this->institution,
174
                UseRaLocationsOption::getDefault(),
175
                ShowRaaContactInformationOption::getDefault(),
176
                VerifyEmailOption::getDefault(),
177
                NumberOfTokensPerIdentityOption::getDefault(),
178
                SsoOn2faOption::getDefault(),
179
                SelfVetOption::getDefault(),
180
                SelfAssertedTokensOption::getDefault(),
181
            ),
182
        );
183
        $this->apply(
184
            new AllowedSecondFactorListUpdatedEvent(
185
                $this->institutionConfigurationId,
186
                $this->institution,
187
                AllowedSecondFactorList::blank(),
188
            ),
189
        );
190
        $this->apply(
191
            new UseRaOptionChangedEvent(
192
                $this->institutionConfigurationId,
193
                $this->institution,
194
                InstitutionAuthorizationOption::getDefault(InstitutionRole::useRa()),
195
            ),
196
        );
197
        $this->apply(
198
            new UseRaaOptionChangedEvent(
199
                $this->institutionConfigurationId,
200
                $this->institution,
201
                InstitutionAuthorizationOption::getDefault(InstitutionRole::useRaa()),
202
            ),
203
        );
204
        $this->apply(
205
            new SelectRaaOptionChangedEvent(
206
                $this->institutionConfigurationId,
207
                $this->institution,
208
                InstitutionAuthorizationOption::getDefault(InstitutionRole::selectRaa()),
209
            ),
210
        );
211
212
        return $this;
213
    }
214
215
    final public function __construct()
216
    {
217
    }
218
219
    public function configureUseRaLocationsOption(UseRaLocationsOption $useRaLocationsOption): void
220
    {
221
        if ($this->useRaLocationsOption->equals($useRaLocationsOption)) {
222
            return;
223
        }
224
225
        $this->apply(
226
            new UseRaLocationsOptionChangedEvent(
227
                $this->institutionConfigurationId,
228
                $this->institution,
229
                $useRaLocationsOption,
230
            ),
231
        );
232
    }
233
234
    public function configureShowRaaContactInformationOption(
235
        ShowRaaContactInformationOption $showRaaContactInformationOption,
236
    ): void {
237
        if ($this->showRaaContactInformationOption->equals($showRaaContactInformationOption)) {
238
            return;
239
        }
240
241
        $this->apply(
242
            new ShowRaaContactInformationOptionChangedEvent(
243
                $this->institutionConfigurationId,
244
                $this->institution,
245
                $showRaaContactInformationOption,
246
            ),
247
        );
248
    }
249
250
    public function configureVerifyEmailOption(VerifyEmailOption $verifyEmailOption): void
251
    {
252
        if ($this->verifyEmailOption->equals($verifyEmailOption)) {
253
            return;
254
        }
255
256
        $this->apply(
257
            new VerifyEmailOptionChangedEvent(
258
                $this->institutionConfigurationId,
259
                $this->institution,
260
                $verifyEmailOption,
261
            ),
262
        );
263
    }
264
265
    public function configureNumberOfTokensPerIdentityOption(
266
        NumberOfTokensPerIdentityOption $numberOfTokensPerIdentityOption,
267
    ): void {
268
        if ($this->numberOfTokensPerIdentityOption->equals($numberOfTokensPerIdentityOption)) {
269
            return;
270
        }
271
272
        $this->apply(
273
            new NumberOfTokensPerIdentityOptionChangedEvent(
274
                $this->institutionConfigurationId,
275
                $this->institution,
276
                $numberOfTokensPerIdentityOption,
277
            ),
278
        );
279
    }
280
281
    public function configureSelfVetOption(SelfVetOption $selfVetOption): void
282
    {
283
        if ($this->selfVetOption->equals($selfVetOption)) {
284
            return;
285
        }
286
287
        $this->apply(
288
            new SelfVetOptionChangedEvent(
289
                $this->institutionConfigurationId,
290
                $this->institution,
291
                $selfVetOption,
292
            ),
293
        );
294
    }
295
296
    public function configureSelfAssertedTokensOption(SelfAssertedTokensOption $selfAssertedTokensOption): void
297
    {
298
        if ($this->selfAssertedTokensOption instanceof \Surfnet\Stepup\Configuration\Value\SelfAssertedTokensOption &&
299
            $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...
300
        ) {
301
            return;
302
        }
303
304
        $this->apply(
305
            new SelfAssertedTokensOptionChangedEvent(
306
                $this->institutionConfigurationId,
307
                $this->institution,
308
                $selfAssertedTokensOption,
309
            ),
310
        );
311
    }
312
313
    public function configureSsoOn2faOption(SsoOn2faOption $ssoOn2faOption): void
314
    {
315
        if ($this->ssoOn2faOption instanceof \Surfnet\Stepup\Configuration\Value\SsoOn2faOption && $this->ssoOn2faOption->equals($ssoOn2faOption)) {
316
            return;
317
        }
318
319
        $this->apply(
320
            new SsoOn2faOptionChangedEvent(
321
                $this->institutionConfigurationId,
322
                $this->institution,
323
                $ssoOn2faOption,
324
            ),
325
        );
326
    }
327
328
    public function configureSsoRegistrationBypassOption(SsoRegistrationBypassOption $ssoRegistrationBypassOption)
329
    {
330
        if ($this->ssoRegistrationBypassOption->equals($ssoRegistrationBypassOption)) {
0 ignored issues
show
Bug introduced by
The method equals() 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

330
        if ($this->ssoRegistrationBypassOption->/** @scrutinizer ignore-call */ equals($ssoRegistrationBypassOption)) {

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...
331
            return;
332
        }
333
334
        $this->apply(
335
            new SsoRegistrationBypassOptionChangedEvent(
336
                $this->institutionConfigurationId,
337
                $this->institution,
338
                $ssoRegistrationBypassOption
339
            )
340
        );
341
    }
342
343
    public function updateUseRaOption(InstitutionAuthorizationOption $useRaOption): void
344
    {
345
        if ($this->useRaOption instanceof \Surfnet\Stepup\Configuration\Value\InstitutionAuthorizationOption
346
            && $this->useRaOption->equals($useRaOption)
347
        ) {
348
            return;
349
        }
350
351
        $this->apply(
352
            new UseRaOptionChangedEvent(
353
                $this->institutionConfigurationId,
354
                $this->institution,
355
                $useRaOption,
356
            ),
357
        );
358
    }
359
360
    public function updateUseRaaOption(InstitutionAuthorizationOption $useRaaOption): void
361
    {
362
        if ($this->useRaaOption instanceof \Surfnet\Stepup\Configuration\Value\InstitutionAuthorizationOption
363
            && $this->useRaaOption->equals($useRaaOption)
364
        ) {
365
            return;
366
        }
367
368
        $this->apply(
369
            new UseRaaOptionChangedEvent(
370
                $this->institutionConfigurationId,
371
                $this->institution,
372
                $useRaaOption,
373
            ),
374
        );
375
    }
376
377
    public function updateSelectRaaOption(InstitutionAuthorizationOption $selectRaaOption): void
378
    {
379
        if ($this->selectRaaOption instanceof \Surfnet\Stepup\Configuration\Value\InstitutionAuthorizationOption
380
            && $this->selectRaaOption->equals($selectRaaOption)
381
        ) {
382
            return;
383
        }
384
385
        $this->apply(
386
            new SelectRaaOptionChangedEvent(
387
                $this->institutionConfigurationId,
388
                $this->institution,
389
                $selectRaaOption,
390
            ),
391
        );
392
    }
393
394
    public function updateAllowedSecondFactorList(AllowedSecondFactorList $allowedSecondFactorList): void
395
    {
396
        // AllowedSecondFactorList can be null for InstitutionConfigurations for which this functionality did not exist
397
        if ($this->allowedSecondFactorList instanceof \Surfnet\Stepup\Configuration\Value\AllowedSecondFactorList
398
            && $this->allowedSecondFactorList->equals($allowedSecondFactorList)
399
        ) {
400
            return;
401
        }
402
403
        $this->apply(
404
            new AllowedSecondFactorListUpdatedEvent(
405
                $this->institutionConfigurationId,
406
                $this->institution,
407
                $allowedSecondFactorList,
408
            ),
409
        );
410
    }
411
412
    /**
413
     * @param RaLocationId $raLocationId
0 ignored issues
show
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
414
     * @param RaLocationName $raLocationName
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
415
     * @param Location $location
0 ignored issues
show
Coding Style introduced by
Expected 11 spaces after parameter type; 1 found
Loading history...
416
     * @param ContactInformation $contactInformation
417
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
418
    public function addRaLocation(
419
        RaLocationId $raLocationId,
420
        RaLocationName $raLocationName,
421
        Location $location,
422
        ContactInformation $contactInformation,
423
    ): void {
424
        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

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

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