AbstractKeybase::toXML()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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