AbstractStatusType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 17
dl 0
loc 76
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCode() 0 3 1
A toXML() 0 8 1
A __construct() 0 4 1
A fromXML() 0 16 1
A getReason() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wst_200512;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\MissingElementException;
11
use SimpleSAML\XML\Exception\TooManyElementsException;
12
13
/**
14
 * Class defining the StatusType element
15
 *
16
 * @package simplesamlphp/ws-security
17
 */
18
abstract class AbstractStatusType extends AbstractWstElement
19
{
20
    /**
21
     * AbstractStatusType constructor
22
     *
23
     * @param \SimpleSAML\WSSecurity\XML\wst_200512\Code $code
24
     * @param \SimpleSAML\WSSecurity\XML\wst_200512\Reason|null $reason
25
     */
26
    final public function __construct(
27
        protected Code $code,
28
        protected ?Reason $reason = null,
29
    ) {
30
    }
31
32
33
    /**
34
     * @return \SimpleSAML\WSSecurity\XML\wst_200512\Code
35
     */
36
    public function getCode(): Code
37
    {
38
        return $this->code;
39
    }
40
41
42
    /**
43
     * @return \SimpleSAML\WSSecurity\XML\wst_200512\Reason|null
44
     */
45
    public function getReason(): ?Reason
46
    {
47
        return $this->reason;
48
    }
49
50
51
    /**
52
     * Create an instance of this object from its XML representation.
53
     *
54
     * @param \DOMElement $xml
55
     * @return static
56
     *
57
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
58
     *   if the qualified name of the supplied element is wrong
59
     */
60
    public static function fromXML(DOMElement $xml): static
61
    {
62
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
0 ignored issues
show
Bug introduced by
The method same() does not exist on SimpleSAML\WSSecurity\Assert\Assert. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
        Assert::/** @scrutinizer ignore-call */ 
63
                same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
Loading history...
63
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
64
65
        $code = Code::getChildrenOfClass($xml);
66
        Assert::minCount($code, 1, MissingElementException::class);
0 ignored issues
show
Bug introduced by
The method minCount() does not exist on SimpleSAML\WSSecurity\Assert\Assert. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        Assert::/** @scrutinizer ignore-call */ 
67
                minCount($code, 1, MissingElementException::class);
Loading history...
67
        Assert::maxCount($code, 1, TooManyElementsException::class);
0 ignored issues
show
Bug introduced by
The method maxCount() does not exist on SimpleSAML\WSSecurity\Assert\Assert. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
        Assert::/** @scrutinizer ignore-call */ 
68
                maxCount($code, 1, TooManyElementsException::class);
Loading history...
68
69
        $reason = Reason::getChildrenOfClass($xml);
70
        Assert::maxCount($reason, 1, TooManyElementsException::class);
71
72
73
        return new static(
74
            array_pop($code),
75
            array_pop($reason),
76
        );
77
    }
78
79
80
    /**
81
     * Add this UseKeyType to an XML element.
82
     *
83
     * @param \DOMElement|null $parent The element we should append this username token to.
84
     * @return \DOMElement
85
     */
86
    public function toXML(?DOMElement $parent = null): DOMElement
87
    {
88
        $e = parent::instantiateParentElement($parent);
89
90
        $this->getCode()->toXML($e);
91
        $this->getReason()?->toXML($e);
92
93
        return $e;
94
    }
95
}
96