Passed
Pull Request — master (#24)
by Tim
01:55
created

AbstractAttributes::getAuthenticationDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\CAS\XML;
6
7
use DOMElement;
8
use SimpleSAML\CAS\Constants as C;
9
use SimpleSAML\XML\ExtendableElementTrait;
10
use SimpleSAML\XMLSchema\XML\Constants\NS;
11
12
/**
13
 * Class for CAS attributes
14
 *
15
 * @package simplesamlphp/xml-cas
16
 */
17
abstract class AbstractAttributes extends AbstractCasElement
18
{
19
    use ExtendableElementTrait;
20
21
22
    /** @var string */
23
    final public const LOCALNAME = 'attributes';
24
25
    /** The namespace-attribute for the xs:any element */
26
    final public const XS_ANY_ELT_NAMESPACE = NS::ANY;
27
28
    /** The exclusions for the xs:any element */
29
    final public const XS_ANY_ELT_EXCLUSIONS = [
30
        [C::NS_CAS, 'authenticationDate'],
31
        [C::NS_CAS, 'longTermAuthenticationRequestTokenUsed'],
32
        [C::NS_CAS, 'isFromNewLogin'],
33
    ];
34
35
36
    /**
37
     * Initialize a cas:attributes element
38
     *
39
     * @param \SimpleSAML\CAS\XML\AuthenticationDate $authenticationDate
40
     * @param \SimpleSAML\CAS\XML\LongTermAuthenticationRequestTokenUsed $longTermAuthenticationRequestTokenUsed
41
     * @param \SimpleSAML\CAS\XML\IsFromNewLogin $isFromNewLogin
42
     * @param list<\SimpleSAML\XML\SerializableElementInterface> $elts
43
     */
44
    public function __construct(
45
        protected AuthenticationDate $authenticationDate,
46
        protected LongTermAuthenticationRequestTokenUsed $longTermAuthenticationRequestTokenUsed,
47
        protected IsFromNewLogin $isFromNewLogin,
48
        array $elts = [],
49
    ) {
50
        $this->setElements($elts);
51
    }
52
53
54
    /**
55
     * @return \SimpleSAML\CAS\XML\AuthenticationDate
56
     */
57
    public function getAuthenticationDate(): AuthenticationDate
58
    {
59
        return $this->authenticationDate;
60
    }
61
62
63
    /**
64
     * @return \SimpleSAML\CAS\XML\LongTermAuthenticationRequestTokenUsed
65
     */
66
    public function getLongTermAuthenticationRequestTokenUsed(): LongTermAuthenticationRequestTokenUsed
67
    {
68
        return $this->longTermAuthenticationRequestTokenUsed;
69
    }
70
71
72
    /**
73
     * @return \SimpleSAML\CAS\XML\IsFromNewLogin
74
     */
75
    public function getIsFromNewLogin(): IsFromNewLogin
76
    {
77
        return $this->isFromNewLogin;
78
    }
79
80
81
    /**
82
     * Convert this Attributes to XML.
83
     *
84
     * @param \DOMElement|null $parent The element we should append this Attributes to.
85
     * @return \DOMElement
86
     */
87
    public function toXML(?DOMElement $parent = null): DOMElement
88
    {
89
        $e = $this->instantiateParentElement($parent);
90
91
        $this->getAuthenticationDate()->toXML($e);
92
        $this->getLongTermAuthenticationRequestTokenUsed()->toXML($e);
93
        $this->getIsFromNewLogin()->toXML($e);
94
95
        foreach ($this->elements as $elt) {
96
            if (!$elt->isEmptyElement()) {
97
                $elt->toXML($e);
98
            }
99
        }
100
101
        return $e;
102
    }
103
}
104