AbstractRetryAfterType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 1
b 0
f 0
dl 0
loc 67
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A fromXML() 0 6 1
A toXML() 0 10 2
A getValue() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsa_200408;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\Exception\SchemaViolationException;
11
use SimpleSAML\XML\ExtendableAttributesTrait;
12
use SimpleSAML\XML\XsNamespace as NS;
13
14
use function intval;
15
use function strval;
16
17
/**
18
 * Class representing WS-addressing RetryAfterType.
19
 *
20
 * You can extend the class without extending the constructor. Then you can use the methods available and the
21
 * class will generate an element with the same name as the extending class (e.g. \SimpleSAML\WSSecurity\wsa\Address).
22
 *
23
 * @package simplesamlphp/ws-security
24
 */
25
abstract class AbstractRetryAfterType extends AbstractWsaElement
26
{
27
    use ExtendableAttributesTrait;
28
29
    /** The namespace-attribute for the xs:anyAttribute element */
30
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
31
32
33
    /**
34
     * AbstractRetryAfterType constructor.
35
     *
36
     * @param int $value The long.
37
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\wsa_200408\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
     */
39
    final public function __construct(
40
        protected int $value,
41
        array $namespacedAttributes = [],
42
    ) {
43
        Assert::natural($value, SchemaViolationException::class); // Allows 0 as allowed by xs:nonNegativeInteger
44
45
        $this->setAttributesNS($namespacedAttributes);
46
    }
47
48
49
    /**
50
     * Retrieve the value of the value-attribute
51
     */
52
    public function getValue(): int
53
    {
54
        return $this->value;
55
    }
56
57
58
    /**
59
     * Convert XML into a class instance
60
     *
61
     * @param \DOMElement $xml The XML element we should load
62
     * @return static
63
     *
64
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
65
     *   If the qualified name of the supplied element is wrong
66
     */
67
    public static function fromXML(DOMElement $xml): static
68
    {
69
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
70
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
71
72
        return new static(intval($xml->textContent), self::getAttributesNSFromXML($xml));
73
    }
74
75
76
    /**
77
     * Convert this element to XML.
78
     *
79
     * @param \DOMElement|null $parent The element we should append this element to.
80
     * @return \DOMElement
81
     */
82
    public function toXML(?DOMElement $parent = null): DOMElement
83
    {
84
        $e = $this->instantiateParentElement($parent);
85
        $e->textContent = strval($this->getValue());
86
87
        foreach ($this->getAttributesNS() as $attr) {
88
            $attr->toXML($e);
89
        }
90
91
        return $e;
92
    }
93
}
94