Passed
Pull Request — master (#64)
by Tim
02:14
created

AbstractFieldIDType   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 64
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 7 1
A getFieldId() 0 3 1
A __construct() 0 14 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\SchemaViolationException;
10
use SimpleSAML\XML\ExtendableElementTrait;
11
use SimpleSAML\XML\SerializableElementInterface;
12
use SimpleSAML\XML\XsNamespace as NS;
13
14
/**
15
 * Abstract class representing a dsig11:FieldIDType
16
 *
17
 * @package simplesaml/xml-security
18
 */
19
abstract class AbstractFieldIDType extends AbstractDsig11Element
20
{
21
    // We use our own getter instead of the trait's one, so we prevent their use by marking them private
22
    use ExtendableElementTrait {
23
        getElements as private;
24
        setElements as private;
25
    }
26
27
    /** @var \SimpleSAML\XML\XsNamespace */
28
    public const XS_ANY_ELT_NAMESPACE = NS::OTHER;
29
30
31
    /**
32
     * Initialize a FieldIDType element.
33
     *
34
     * @param \SimpleSAML\XML\SerializableElementInterface $fieldId
35
     */
36
    public function __construct(
37
        protected Prime|TnB|PnB|GnB|SerializableElementInterface $fieldId,
38
    ) {
39
        if (
40
            !($fieldId instanceof Prime
41
            || $fieldId instanceof TnB
42
            || $fieldId instanceof PnB
43
            || $fieldId instanceof GnB)
44
        ) {
45
            Assert::true(
46
                (($fieldId instanceof Chunk) ? $fieldId->getNamespaceURI() : $fieldId::getNameSpaceURI())
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\XML\dsig11\Chunk 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...
47
                !== C::NS_XDSIG11,
48
                'A <dsig11:FieldIDType> requires either a Prime, TnB, PnB, GnB or an element in namespace ##other',
49
                SchemaViolationException::class,
50
            );
51
        }
52
    }
53
54
55
    /**
56
     * Collect the value of the fieldId-property
57
     *
58
     * @return \SimpleSAML\XMLSecurity\XML\dsig11\Prime
59
     *         \SimpleSAML\XMLSecurity\XML\dsig11\TnB
60
     *         \SimpleSAML\XMLSecurity\XML\dsig11\PnB
61
     *         \SimpleSAML\XMLSecurity\XML\dsig11\GnB
62
     *         \SimpleSAML\XML\SerializableElementInterface
63
     */
64
    public function getFieldId(): Prime|TnB|PnB|GnB|SerializableElementInterface
65
    {
66
        return $this->fieldId;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->fieldId also could return the type SimpleSAML\XMLSecurity\X...Security\XML\dsig11\TnB which is incompatible with the documented return type SimpleSAML\XMLSecurity\XML\dsig11\Prime.
Loading history...
67
    }
68
69
70
    /**
71
     * Convert this FieldIDType element to XML.
72
     *
73
     * @param \DOMElement|null $parent The element we should append this FieldIDType element to.
74
     * @return \DOMElement
75
     */
76
    public function toXML(?DOMElement $parent = null): DOMElement
77
    {
78
        $e = $this->instantiateParentElement($parent);
79
80
        $this->getFieldId()->toXML($e);
81
82
        return $e;
83
    }
84
}
85