AbstractDisplayNameType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
dl 0
loc 60
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 6 1
A toXML() 0 10 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\auth;
6
7
use DOMElement;
8
use SimpleSAML\WSSecurity\Assert\Assert;
9
use SimpleSAML\XML\ExtendableAttributesTrait;
10
use SimpleSAML\XML\TypedTextContentTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Type\StringValue;
13
use SimpleSAML\XMLSchema\XML\Constants\NS;
14
15
/**
16
 * Class representing WS-authorization DisplayNameType.
17
 *
18
 * @package simplesamlphp/ws-security
19
 */
20
abstract class AbstractDisplayNameType extends AbstractAuthElement
21
{
22
    use ExtendableAttributesTrait;
23
    use TypedTextContentTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\TypedTextContentTrait requires some properties which are not provided by SimpleSAML\WSSecurity\XM...AbstractDisplayNameType: $localName, $namespaceURI
Loading history...
24
25
26
    /** @var string */
27
    public const TEXTCONTENT_TYPE = StringValue::class;
28
29
    /** The namespace-attribute for the xs:anyAttribute element */
30
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
31
32
33
    /**
34
     * AbstractDisplayNameType constructor.
35
     *
36
     * @param \SimpleSAML\XMLSchema\Type\StringValue $value The value string.
37
     * @param list<\SimpleSAML\XML\Attribute> $namespacedAttributes
0 ignored issues
show
Bug introduced by
The type SimpleSAML\WSSecurity\XML\auth\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(StringValue $value, array $namespacedAttributes = [])
40
    {
41
        $this->setContent($value);
42
        $this->setAttributesNS($namespacedAttributes);
43
    }
44
45
46
    /**
47
     * Convert XML into a class instance
48
     *
49
     * @param \DOMElement $xml The XML element we should load
50
     * @return static
51
     *
52
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
53
     *   If the qualified name of the supplied element is wrong
54
     */
55
    public static function fromXML(DOMElement $xml): static
56
    {
57
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
58
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
59
60
        return new static(StringValue::fromString($xml->textContent), self::getAttributesNSFromXML($xml));
61
    }
62
63
64
    /**
65
     * Convert this element to XML.
66
     *
67
     * @param \DOMElement|null $parent The element we should append this element to.
68
     * @return \DOMElement
69
     */
70
    public function toXML(?DOMElement $parent = null): DOMElement
71
    {
72
        $e = $this->instantiateParentElement($parent);
73
        $e->textContent = $this->getContent()->getValue();
74
75
        foreach ($this->getAttributesNS() as $attr) {
76
            $attr->toXML($e);
77
        }
78
79
        return $e;
80
    }
81
}
82