AuthenticationFailure   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 14
dl 0
loc 74
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCode() 0 3 1
A fromXML() 0 8 1
A toXML() 0 8 1
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\CAS\XML;
6
7
use DOMElement;
8
use SimpleSAML\CAS\Assert\Assert;
9
use SimpleSAML\CAS\Type\CodeValue;
10
use SimpleSAML\XML\TypedTextContentTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Type\StringValue;
13
14
use function strval;
15
16
/**
17
 * Class for CAS authenticationFailure
18
 *
19
 * @package simplesamlphp/cas
20
 */
21
final class AuthenticationFailure extends AbstractResponse
22
{
23
    use TypedTextContentTrait;
24
25
26
    /** @var string */
27
    public const TEXTCONTENT_TYPE = StringValue::class;
28
29
    /** @var string */
30
    final public const LOCALNAME = 'authenticationFailure';
31
32
33
    /**
34
     * Create a new instance of AuthenticationFailure
35
     *
36
     * @param \SimpleSAML\XMLSchema\Type\StringValue $content
37
     * @param \SimpleSAML\CAS\Type\CodeValue $code
38
     */
39
    final public function __construct(
40
        StringValue $content,
41
        protected CodeValue $code,
42
    ) {
43
        $this->setContent($content);
44
    }
45
46
47
    /**
48
     * Collect the value of the code-property
49
     *
50
     * @return \SimpleSAML\CAS\Type\CodeValue
51
     */
52
    public function getCode(): CodeValue
53
    {
54
        return $this->code;
55
    }
56
57
58
    /**
59
     * Initialize an AuthenticationFailure element.
60
     *
61
     * @param \DOMElement $xml The XML element we should load.
62
     * @return static
63
     *
64
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
65
     *   if the qualified name of the supplied element is wrong
66
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
67
     *   if the supplied element is missing any of the mandatory attributes
68
     */
69
    public static function fromXML(DOMElement $xml): static
70
    {
71
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
72
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
73
74
        return new static(
75
            StringValue::fromString($xml->textContent),
76
            self::getAttribute($xml, 'code', CodeValue::class),
77
        );
78
    }
79
80
81
    /**
82
     * Convert this AuthenticationFailure to XML.
83
     *
84
     * @param \DOMElement|null $parent The element we should append to.
85
     * @return \DOMElement This AuthenticatioFailure-element.
86
     */
87
    public function toXML(?DOMElement $parent = null): DOMElement
88
    {
89
        $e = $this->instantiateParentElement($parent);
90
91
        $e->setAttribute('code', strval($this->getCode()));
92
        $e->textContent = strval($this->getContent());
93
94
        return $e;
95
    }
96
}
97