AbstractDisplayValueType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toXML() 0 10 2
A fromXML() 0 6 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\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\ExtendableAttributesTrait;
11
use SimpleSAML\XML\StringElementTrait;
12
use SimpleSAML\XML\XsNamespace as NS;
13
14
/**
15
 * Class representing WS-authorization DisplayValueType.
16
 *
17
 * @package simplesamlphp/ws-security
18
 */
19
abstract class AbstractDisplayValueType extends AbstractAuthElement
20
{
21
    use ExtendableAttributesTrait;
22
    use StringElementTrait;
23
24
    /** The namespace-attribute for the xs:anyAttribute element */
25
    public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
26
27
28
    /**
29
     * AbstractDisplayValueType constructor.
30
     *
31
     * @param string $value The value string.
32
     * @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...
33
     */
34
    final public function __construct(string $value, array $namespacedAttributes = [])
35
    {
36
        $this->setContent($value);
37
        $this->setAttributesNS($namespacedAttributes);
38
    }
39
40
41
    /**
42
     * Convert XML into a class instance
43
     *
44
     * @param \DOMElement $xml The XML element we should load
45
     * @return static
46
     *
47
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
48
     *   If the qualified name of the supplied element is wrong
49
     */
50
    public static function fromXML(DOMElement $xml): static
51
    {
52
        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

52
        Assert::/** @scrutinizer ignore-call */ 
53
                same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
Loading history...
53
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
54
55
        return new static($xml->textContent, self::getAttributesNSFromXML($xml));
56
    }
57
58
59
    /**
60
     * Convert this element to XML.
61
     *
62
     * @param \DOMElement|null $parent The element we should append this element to.
63
     * @return \DOMElement
64
     */
65
    public function toXML(?DOMElement $parent = null): DOMElement
66
    {
67
        $e = $this->instantiateParentElement($parent);
68
        $e->textContent = $this->getContent();
69
70
        foreach ($this->getAttributesNS() as $attr) {
71
            $attr->toXML($e);
72
        }
73
74
        return $e;
75
    }
76
}
77