Completed
Push — feature/upgrade-remote-vetting ( 883904 )
by
unknown
65:35
created

IdentityData::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright 2020 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
 */
18
19
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Encryption;
20
21
use Surfnet\StepupBundle\DateTime\DateTime;
22
use Surfnet\StepupSelfService\SelfServiceBundle\Assert;
23
use Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Value\AttributeCollectionInterface;
24
25
class IdentityData
26
{
27
    /**
28
     * @var AttributeCollectionInterface
29
     */
30
    private $attributeCollectionAggregate;
31
32
    /**
33
     * @var string
34
     */
35
    private $nameId;
36
37
    /**
38
     * @var string
39
     */
40
    private $applicationVersion;
41
42
    /**
43
     * @var string
44
     */
45
    private $remarks;
46
47
    /**
48
     * @var string
49
     */
50
    private $institution;
51
52
    /**
53
     * @var string
54
     */
55
    private $remoteVettingSource;
56
57
    /**
58
     * @param AttributeCollectionInterface $attributeCollectionAggregate
59
     * @param string $nameId
60
     * @param string $applicationVersion
61
     * @param string $remarks
62
     */
63
    public function __construct(
64
        AttributeCollectionInterface $attributeCollectionAggregate,
65
        $nameId,
66
        $applicationVersion,
67
        $remarks,
68
        $institution,
69
        $remoteVettingSource
70
    ) {
71
        Assert::string($nameId, 'The name id must have a string value');
72
        Assert::string($applicationVersion, 'The application version must have a string value');
73
        Assert::string($remarks, 'The remarks must have a string value');
74
        Assert::string($institution, 'The SHO of the institution must have a string value');
75
        Assert::string($remoteVettingSource, 'The remote vetting source must have a string value');
76
77
        $this->attributeCollectionAggregate = $attributeCollectionAggregate;
78
        $this->nameId = $nameId;
79
        $this->applicationVersion = $applicationVersion;
80
        $this->remarks = $remarks;
81
        $this->institution = $institution;
82
        $this->remoteVettingSource = $remoteVettingSource;
83
    }
84
85
    public function serialize()
86
    {
87
        return json_encode(
88
            [
89
                'attribute-data' => $this->attributeCollectionAggregate->getAttributes(),
90
                'remarks' => $this->remarks,
91
                'name-id' => $this->nameId,
92
                'institution' => $this->institution,
93
                'remote-vetting-source' => $this->remoteVettingSource,
94
                'application-version' => $this->applicationVersion,
95
                'time' => DateTime::now()->format('c'),
96
            ]
97
        );
98
    }
99
}
100