__construct()   A
last analyzed

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
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\CAS\XML\cas;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\CAS\Exception\ProtocolViolationException;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\StringElementTrait;
12
13
/**
14
 * Class for CAS longTermAuthenticationRequestTokenUsed
15
 *
16
 * @package simplesamlphp/cas
17
 */
18
final class LongTermAuthenticationRequestTokenUsed extends AbstractCasElement
19
{
20
    use StringElementTrait;
21
22
    /** @var string */
23
    final public const LOCALNAME = 'longTermAuthenticationRequestTokenUsed';
24
25
26
    /**
27
     * @param string $content
28
     */
29
    final public function __construct(string $content)
30
    {
31
        $this->setContent($content);
32
    }
33
34
35
    /**
36
     * Validate the content of the element.
37
     *
38
     * @param string $content  The value to go in the XML textContent
39
     * @throws \Exception on failure
40
     * @return void
41
     */
42
    protected function validateContent(string $content): void
43
    {
44
        Assert::notWhitespaceOnly($content);
45
        Assert::oneOf(
46
            $content,
47
            ['true', 'false', '0', '1'],
48
            'The value of ' . static::getNamespacePrefix() . ':' . static::getLocalName() . ' must be boolean.',
49
            ProtocolViolationException::class,
50
        );
51
    }
52
53
54
    /**
55
     * Convert XML into a cas:longTermAuthenticationRequestTokenUsed
56
     *
57
     * @param \DOMElement $xml The XML element we should load
58
     * @return static
59
     *
60
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
61
     *   If the qualified name of the supplied element is wrong
62
     */
63
    public static function fromXML(DOMElement $xml): static
64
    {
65
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
66
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
67
68
        return new static($xml->textContent);
69
    }
70
}
71