AbstractAttributedLongType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 6 1
A toXML() 0 10 2
A __construct() 0 4 1
A validateContent() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsa_200508;
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\StringElementTrait;
13
use SimpleSAML\XML\XsNamespace as NS;
14
15
/**
16
 * Class representing WS-addressing AttributedLongType.
17
 *
18
 * You can extend the class without extending the constructor. Then you can use the methods available and the
19
 * class will generate an element with the same name as the extending class (e.g. \SimpleSAML\WSSecurity\wsa\Address).
20
 *
21
 * @package simplesamlphp/ws-security
22
 */
23
abstract class AbstractAttributedLongType extends AbstractWsaElement
24
{
25
    use ExtendableAttributesTrait;
26
    use StringElementTrait;
27
28
    /** The namespace-attribute for the xs:anyAttribute element */
29
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
30
31
32
    /**
33
     * AbstractAttributedLongType constructor.
34
     *
35
     * @param string $value The long.
36
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\wsa_200508\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...
37
     */
38
    final public function __construct(string $value, array $namespacedAttributes = [])
39
    {
40
        $this->setContent($value);
41
        $this->setAttributesNS($namespacedAttributes);
42
    }
43
44
45
    /**
46
     * Validate the content of the element.
47
     *
48
     * @param string $content  The value to go in the XML textContent
49
     * @throws \SimpleSAML\XML\Exception\SchemaViolationException on failure
50
     * @return void
51
     */
52
    protected function validateContent(string $content): void
53
    {
54
        $content = intval($content);
55
        Assert::natural($content, SchemaViolationException::class);
56
        Assert::range($content, 0, 18446744073709551615, SchemaViolationException::class);
57
    }
58
59
60
    /**
61
     * Convert XML into a class instance
62
     *
63
     * @param \DOMElement $xml The XML element we should load
64
     * @return static
65
     *
66
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
67
     *   If the qualified name of the supplied element is wrong
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::NS, InvalidDOMElementException::class);
73
74
        return new static($xml->textContent, self::getAttributesNSFromXML($xml));
75
    }
76
77
78
    /**
79
     * Convert this element to XML.
80
     *
81
     * @param \DOMElement|null $parent The element we should append this element to.
82
     * @return \DOMElement
83
     */
84
    public function toXML(?DOMElement $parent = null): DOMElement
85
    {
86
        $e = $this->instantiateParentElement($parent);
87
        $e->textContent = $this->getContent();
88
89
        foreach ($this->getAttributesNS() as $attr) {
90
            $attr->toXML($e);
91
        }
92
93
        return $e;
94
    }
95
}
96