Completed
Push — master ( f72cfb...4ef12f )
by Tim
21s queued 18s
created

AbstractKeybase   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 88
rs 10
c 1
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSelector() 0 3 1
A getName() 0 3 1
A isEmptyElement() 0 3 1
A getField() 0 3 1
A toXML() 0 12 2
A __construct() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSchema\XML\xs;
6
7
use DOMElement;
8
use SimpleSAML\XML\Assert\Assert;
9
use SimpleSAML\XMLSchema\Exception\MissingElementException;
10
use SimpleSAML\XMLSchema\Type\Builtin\{IDValue, NCNameValue};
11
12
use function strval;
13
14
/**
15
 * Abstract class representing the keybase-type.
16
 *
17
 * @package simplesamlphp/xml-common
18
 */
19
abstract class AbstractKeybase extends AbstractAnnotated
20
{
21
    /**
22
     * Keybase constructor
23
     *
24
     * @param \SimpleSAML\XMLSchema\Type\Builtin\NCNameValue $name
25
     * @param \SimpleSAML\XMLSchema\XML\xs\Selector $selector
26
     * @param array<\SimpleSAML\XMLSchema\XML\xs\Field> $field
27
     * @param \SimpleSAML\XMLSchema\XML\xs\Annotation|null $annotation
28
     * @param \SimpleSAML\XMLSchema\Type\Builtin\IDValue|null $id
29
     * @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
30
     */
31
    public function __construct(
32
        protected NCNameValue $name,
33
        protected Selector $selector,
34
        protected array $field = [],
35
        protected ?Annotation $annotation = null,
36
        protected ?IDValue $id = null,
37
        array $namespacedAttributes = [],
38
    ) {
39
        Assert::allIsInstanceOf($field, Field::class, MissingElementException::class);
40
41
        parent::__construct($annotation, $id, $namespacedAttributes);
42
    }
43
44
45
    /**
46
     * Collect the value of the name-property
47
     *
48
     * @return \SimpleSAML\XMLSchema\Type\Builtin\NCNameValue
49
     */
50
    public function getName(): NCNameValue
51
    {
52
        return $this->name;
53
    }
54
55
56
    /**
57
     * Collect the value of the selector-property
58
     *
59
     * @return \SimpleSAML\XMLSchema\XML\xs\Selector
60
     */
61
    public function getSelector(): Selector
62
    {
63
        return $this->selector;
64
    }
65
66
67
    /**
68
     * Collect the value of the field-property
69
     *
70
     * @return array<\SimpleSAML\XMLSchema\XML\xs\Field>
71
     */
72
    public function getField(): array
73
    {
74
        return $this->field;
75
    }
76
77
78
    /**
79
     * Test if an object, at the state it's in, would produce an empty XML-element
80
     *
81
     * @return bool
82
     */
83
    public function isEmptyElement(): bool
84
    {
85
        return false;
86
    }
87
88
89
    /**
90
     * Add this Keybase to an XML element.
91
     *
92
     * @param \DOMElement|null $parent The element we should append this Keybase to.
93
     * @return \DOMElement
94
     */
95
    public function toXML(?DOMElement $parent = null): DOMElement
96
    {
97
        $e = parent::toXML($parent);
98
        $e->setAttribute('name', strval($this->getName()));
99
100
        $this->getSelector()->toXML($e);
101
102
        foreach ($this->getField() as $field) {
103
            $field->toXML($e);
104
        }
105
106
        return $e;
107
    }
108
}
109