deserialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2018 SURFnet bv
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
 */
18
19
namespace Surfnet\Stepup\Identity\Event;
20
21
use Surfnet\Stepup\Identity\AuditLog\Metadata;
22
use Surfnet\Stepup\Identity\Value\ContactInformation;
23
use Surfnet\Stepup\Identity\Value\IdentityId;
24
use Surfnet\Stepup\Identity\Value\Institution;
25
use Surfnet\Stepup\Identity\Value\Location;
26
use Surfnet\Stepup\Identity\Value\NameId;
27
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface;
28
29
class RegistrationAuthorityInformationAmendedForInstitutionEvent extends IdentityEvent implements
30
    RightToObtainDataInterface
31
{
32
    /**
33
     * @var string[]
34
     */
35
    private array $allowlist = [
36
        'identity_id',
37
        'institution',
38
        'name_id',
39
        'location',
40
        'contact_information',
41
        'ra_institution',
42
    ];
43
44
    /**
45
     * @param IdentityId $identityId
46
     * @param Institution $institution
47
     * @param NameId $nameId
48
     * @param Location $location
49
     * @param ContactInformation $contactInformation
50
     * @param Institution $raInstitution
51
     */
52
    public function __construct(
53
        IdentityId $identityId,
54
        Institution $institution,
55
        public NameId $nameId,
56
        public Location $location,
57
        public ContactInformation $contactInformation,
58
        public Institution $raInstitution,
59
    ) {
60
        parent::__construct($identityId, $institution);
61
    }
62
63
    public function getAuditLogMetadata(): Metadata
64
    {
65
        $metadata = new Metadata();
66
        $metadata->identityId = $this->identityId;
67
        $metadata->identityInstitution = $this->identityInstitution;
68
69
        return $metadata;
70
    }
71
72
    public static function deserialize(array $data): self
73
    {
74
        return new self(
75
            new IdentityId($data['identity_id']),
76
            new Institution($data['institution']),
77
            new NameId($data['name_id']),
78
            new Location($data['location']),
79
            new ContactInformation($data['contact_information']),
80
            new Institution($data['ra_institution']),
81
        );
82
    }
83
84
    public function serialize(): array
85
    {
86
        return [
87
            'identity_id' => (string)$this->identityId,
88
            'institution' => (string)$this->identityInstitution,
89
            'name_id' => (string)$this->nameId,
90
            'location' => (string)$this->location,
91
            'contact_information' => (string)$this->contactInformation,
92
            'ra_institution' => (string)$this->raInstitution,
93
        ];
94
    }
95
96
    public function obtainUserData(): array
97
    {
98
        return $this->serialize();
99
    }
100
101
    /**
102
     * @return string[]
103
     */
104
    public function getAllowlist(): array
105
    {
106
        return $this->allowlist;
107
    }
108
}
109