SubjectConfirmationData::getNotOnOrAfterString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 0
crap 2.0625
1
<?php
2
3
/*
4
 * This file is part of the LightSAML-Core package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace LightSaml\Model\Assertion;
13
14
use LightSaml\Helper;
15
use LightSaml\Model\Context\DeserializationContext;
16
use LightSaml\Model\Context\SerializationContext;
17
use LightSaml\Model\AbstractSamlModel;
18
use LightSaml\SamlConstants;
19
20
class SubjectConfirmationData extends AbstractSamlModel
21
{
22
    /** @var int|null */
23
    protected $notBefore;
24
25
    /** @var int|null */
26
    protected $notOnOrAfter;
27
28
    /** @var string|null */
29
    protected $address;
30
31
    /** @var string|null */
32
    protected $inResponseTo;
33
34
    /** @var string|null */
35
    protected $recipient;
36
37
    /**
38
     * @param null|string $address
39
     *
40
     * @return SubjectConfirmationData
41
     */
42 2
    public function setAddress($address)
43
    {
44 2
        $this->address = (string) $address;
45
46 2
        return $this;
47
    }
48
49
    /**
50
     * @return null|string
51
     */
52 4
    public function getAddress()
53
    {
54 4
        return $this->address;
55
    }
56
57
    /**
58
     * @param null|string $inResponseTo
59
     *
60
     * @return SubjectConfirmationData
61
     */
62 9
    public function setInResponseTo($inResponseTo)
63
    {
64 9
        $this->inResponseTo = (string) $inResponseTo;
65
66 9
        return $this;
67
    }
68
69
    /**
70
     * @return null|string
71
     */
72 8
    public function getInResponseTo()
73
    {
74 8
        return $this->inResponseTo;
75
    }
76
77
    /**
78
     * @param int|string|\DateTime $notBefore
79
     *
80
     * @return SubjectConfirmationData
81
     */
82 2
    public function setNotBefore($notBefore)
83
    {
84 2
        $this->notBefore = Helper::getTimestampFromValue($notBefore);
85
86 2
        return $this;
87
    }
88
89
    /**
90
     * @return int|null
91
     */
92 5
    public function getNotBeforeTimestamp()
93
    {
94 5
        return $this->notBefore;
95
    }
96
97
    /**
98
     * @return string|null
99
     */
100 4
    public function getNotBeforeString()
101
    {
102 4
        if ($this->notBefore) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->notBefore of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
103
            return Helper::time2string($this->notBefore);
104
        }
105
106 4
        return;
107
    }
108
109
    /**
110
     * @return \DateTime|null
111
     */
112
    public function getNotBeforeDateTime()
113
    {
114
        if ($this->notBefore) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->notBefore of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
115
            return new \DateTime('@'.$this->notBefore);
116
        }
117
118
        return;
119
    }
120
121
    /**
122
     * @param int|string|\DateTime $notOnOrAfter
123
     *
124
     * @return SubjectConfirmationData
125
     */
126 11
    public function setNotOnOrAfter($notOnOrAfter)
127
    {
128 11
        $this->notOnOrAfter = Helper::getTimestampFromValue($notOnOrAfter);
129
130 11
        return $this;
131
    }
132
133
    /**
134
     * @return int|null
135
     */
136 4
    public function getNotOnOrAfterTimestamp()
137
    {
138 4
        return $this->notOnOrAfter;
139
    }
140
141
    /**
142
     * @return string|null
143
     */
144 5
    public function getNotOnOrAfterString()
145
    {
146 5
        if ($this->notOnOrAfter) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->notOnOrAfter of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
147 5
            return Helper::time2string($this->notOnOrAfter);
148
        }
149
150
        return;
151
    }
152
153
    /**
154
     * @return \DateTime|null
155
     */
156 3
    public function getNotOnOrAfterDateTime()
157
    {
158 3
        if ($this->notOnOrAfter) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->notOnOrAfter of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
159 2
            return new \DateTime('@'.$this->notOnOrAfter);
160
        }
161
162 1
        return;
163
    }
164
165
    /**
166
     * @param null|string $recipient
167
     *
168
     * @return SubjectConfirmationData
169
     */
170 10
    public function setRecipient($recipient)
171
    {
172 10
        $this->recipient = (string) $recipient;
173
174 10
        return $this;
175
    }
176
177
    /**
178
     * @return null|string
179
     */
180 11
    public function getRecipient()
181
    {
182 11
        return $this->recipient;
183
    }
184
185
    /**
186
     * @param \DOMNode             $parent
187
     * @param SerializationContext $context
188
     *
189
     * @return void
190
     */
191 4
    public function serialize(\DOMNode $parent, SerializationContext $context)
192
    {
193 4
        $result = $this->createElement('SubjectConfirmationData', SamlConstants::NS_ASSERTION, $parent, $context);
194
195 4
        $this->attributesToXml(
196 4
            array('InResponseTo', 'NotBefore', 'NotOnOrAfter', 'Address', 'Recipient'),
197 4
            $result
198
        );
199 4
    }
200
201
    /**
202
     * @param \DOMNode               $node
203
     * @param DeserializationContext $context
204
     */
205 3 View Code Duplication
    public function deserialize(\DOMNode $node, DeserializationContext $context)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
206
    {
207 3
        $this->checkXmlNodeName($node, 'SubjectConfirmationData', SamlConstants::NS_ASSERTION);
208
209 3
        $this->attributesFromXml($node, array(
0 ignored issues
show
Compatibility introduced by
$node of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
210 3
            'InResponseTo', 'NotBefore', 'NotOnOrAfter', 'Address', 'Recipient',
211
        ));
212 3
    }
213
}
214