Passed
Push — master ( fb3113...2f4a0c )
by Tim
02:23
created

Anonymous::toXML()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsaw;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Attribute as XMLAttribute;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\ExtendableAttributesTrait;
12
use SimpleSAML\XML\XsNamespace as NS;
13
14
/**
15
 * Class defining the Anonymous element
16
 *
17
 * @package simplesamlphp/ws-security
18
 */
19
final class Anonymous extends AbstractAnonymousType
20
{
21
    use ExtendableAttributesTrait;
22
23
    /** The namespace-attribute for the xs:anyAttribute element */
24
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
25
26
27
    /**
28
     * Anonymous constructor
29
     *
30
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
31
     */
32
    final public function __construct(
33
        AnonymousEnum $value,
34
        array $namespacedAttributes = [],
35
    ) {
36
        parent::__construct($value);
37
38
        $this->setAttributesNS($namespacedAttributes);
39
    }
40
41
42
    /**
43
     * Create an instance of this object from its XML representation.
44
     *
45
     * @param \DOMElement $xml
46
     * @return static
47
     *
48
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
49
     *   if the qualified name of the supplied element is wrong
50
     */
51
    public static function fromXML(DOMElement $xml): static
52
    {
53
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
54
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
55
56
        try {
57
            $anonymous = AnonymousEnum::from($xml->textContent);
58
        } catch (ValueError) {
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\wsaw\ValueError was not found. Did you mean ValueError? If so, make sure to prefix the type with \.
Loading history...
59
            throw new SchemaViolationException(sprintf('Unknown value \'%s\' for Anonymous element.', $xml->textContent));
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XM...chemaViolationException 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...
60
        }
61
62
        return new static($anonymous, self::getAttributesNSFromXML($xml));
63
    }
64
65
66
    /**
67
     * Convert this Anonymous to XML.
68
     *
69
     * @param \DOMElement|null $parent The element we should append this class to.
70
     * @return \DOMElement The XML element after adding the data corresponding to this Anonymous.
71
     */
72
    public function toXML(DOMElement $parent = null): DOMElement
73
    {
74
        $e = parent::toXML($parent);
75
76
        foreach ($this->getAttributesNS() as $attr) {
77
            $attr->toXML($e);
78
        }
79
80
        return $e;
81
    }
82
}
83