Completed
Pull Request — develop (#22)
by A.
05:52
created

Consent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 11
rs 9.4286
c 2
b 0
f 1
cc 1
eloc 9
nc 1
nop 4
1
<?php
2
3
/**
4
 * Copyright 2015 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 OpenConext\Profile\Value;
20
21
use DateTime;
22
use DateTimeImmutable;
23
use OpenConext\Profile\Assert;
24
use OpenConext\Profile\Exception\InvalidArgumentException;
25
use OpenConext\Profile\Value\Consent\ServiceProvider;
26
use Surfnet\SamlBundle\SAML2\Attribute\AttributeSet;
27
28
final class Consent
29
{
30
    /**
31
     * @var ServiceProvider
32
     */
33
    private $serviceProvider;
34
35
    /**
36
     * @var DateTimeImmutable
37
     */
38
    private $consentGivenOn;
39
40
    /**
41
     * @var DateTimeImmutable
42
     */
43
    private $lastUsedOn;
44
45
    /**
46
     * @var ConsentType
47
     */
48
    private $consentType;
49
50
    /**
51
     * @var null|AttributeSet
52
     */
53
    private $attributes;
54
55
    /**
56
     * @param ServiceProvider $serviceProvider
57
     * @param DateTimeImmutable $consentGivenOn
58
     * @param DateTimeImmutable $lastUsedOn
59
     * @param ConsentType $consentType
60
     */
61
    public function __construct(
62
        ServiceProvider $serviceProvider,
63
        DateTimeImmutable $consentGivenOn,
64
        DateTimeImmutable $lastUsedOn,
65
        ConsentType $consentType
66
    ) {
67
        $this->serviceProvider = $serviceProvider;
68
        $this->consentGivenOn  = $consentGivenOn;
69
        $this->lastUsedOn      = $lastUsedOn;
70
        $this->consentType     = $consentType;
71
    }
72
73
    /**
74
     * @param AttributeSet $attributeSet
75
     * @return Consent
76
     */
77
    public function givenFor(AttributeSet $attributeSet)
78
    {
79
        $newConsent = clone $this;
80
        $newConsent->attributes = $attributeSet;
81
82
        return $newConsent;
83
    }
84
85
    /**
86
     * @return ServiceProvider
87
     */
88
    public function getServiceProvider()
89
    {
90
        return $this->serviceProvider;
91
    }
92
93
    /**
94
     * @return DateTimeImmutable
95
     */
96
    public function getConsentGivenOn()
97
    {
98
        return $this->consentGivenOn;
99
    }
100
101
    /**
102
     * @return DateTimeImmutable
103
     */
104
    public function getLastUsedOn()
105
    {
106
        return $this->lastUsedOn;
107
    }
108
109
    /**
110
     * @return ConsentType
111
     */
112
    public function getConsentType()
113
    {
114
        return $this->consentType;
115
    }
116
117
    /**
118
     * @return null|AttributeSet
119
     */
120
    public function getAttributes()
121
    {
122
        return $this->attributes;
123
    }
124
}
125