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

AbstractAuthenticationFailure   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 51
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 8 1
A __construct() 0 5 1
A getCode() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\CAS\XML;
6
7
use DOMElement;
8
use SimpleSAML\CAS\Type\CodeValue;
9
use SimpleSAML\XML\TypedTextContentTrait;
10
use SimpleSAML\XMLSchema\Type\StringValue;
11
12
/**
13
 * Class for CAS authenticationFailure
14
 *
15
 * @package simplesamlphp/xml-cas
16
 */
17
abstract class AbstractAuthenticationFailure extends AbstractResponse
18
{
19
    use TypedTextContentTrait;
20
21
22
    /** @var string */
23
    public const TEXTCONTENT_TYPE = StringValue::class;
24
25
    /** @var string */
26
    final public const LOCALNAME = 'authenticationFailure';
27
28
29
    /**
30
     * Create a new instance of AuthenticationFailure
31
     *
32
     * @param \SimpleSAML\XMLSchema\Type\StringValue $content
33
     * @param \SimpleSAML\CAS\Type\CodeValue $code
34
     */
35
    public function __construct(
36
        StringValue $content,
37
        protected CodeValue $code,
38
    ) {
39
        $this->setContent($content);
40
    }
41
42
43
    /**
44
     * Collect the value of the code-property
45
     *
46
     * @return \SimpleSAML\CAS\Type\CodeValue
47
     */
48
    public function getCode(): CodeValue
49
    {
50
        return $this->code;
51
    }
52
53
54
    /**
55
     * Convert this AuthenticationFailure to XML.
56
     *
57
     * @param \DOMElement|null $parent The element we should append to.
58
     * @return \DOMElement This AuthenticatioFailure-element.
59
     */
60
    public function toXML(?DOMElement $parent = null): DOMElement
61
    {
62
        $e = $this->instantiateParentElement($parent);
63
64
        $e->setAttribute('code', $this->getCode()->getValue());
65
        $e->textContent = $this->getContent()->getValue();
66
67
        return $e;
68
    }
69
}
70