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

AbstractImport   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 69
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getLocation() 0 3 1
A getNamespace() 0 3 1
A __construct() 0 9 1
A isEmptyElement() 0 4 1
A toXML() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\wsdl;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\SchemaViolationException;
10
11
/**
12
 * Abstract class representing the tImport type.
13
 *
14
 * @package simplesamlphp/ws-security
15
 */
16
abstract class AbstractImport extends AbstractExtensibleAttributesDocumented
17
{
18
    /**
19
     * Initialize a wsdl:tImport
20
     *
21
     * @param string $namespace
22
     * @param string $location
23
     * @param array<\SimpleSAML\XML\Attribute> $attributes
24
     */
25
    public function __construct(
26
        protected string $namespace,
27
        protected string $location,
28
        array $attributes = [],
29
    ) {
30
        Assert::validURI($namespace, SchemaViolationException::class);
31
        Assert::validURI($location, SchemaViolationException::class);
32
33
        parent::__construct($attributes);
34
    }
35
36
37
    /**
38
     * Collect the value of the namespace-property.
39
     *
40
     * @return string
41
     */
42
    public function getNamespace(): string
43
    {
44
        return $this->namespace;
45
    }
46
47
48
    /**
49
     * Collect the value of the location-property.
50
     *
51
     * @return string
52
     */
53
    public function getLocation(): string
54
    {
55
        return $this->location;
56
    }
57
58
59
    /**
60
     * Test if an object, at the state it's in, would produce an empty XML-element
61
     *
62
     * @return bool
63
     */
64
    public function isEmptyElement(): bool
65
    {
66
        // Upstream abstract elements can be empty, but this one cannot
67
        return false;
68
    }
69
70
71
    /**
72
     * Convert this tImport to XML.
73
     *
74
     * @param \DOMElement|null $parent The element we are converting to XML.
75
     * @return \DOMElement The XML element after adding the data corresponding to this tImport.
76
     */
77
    public function toXML(DOMElement $parent = null): DOMElement
78
    {
79
        $e = parent::toXML($parent);
80
81
        $e->setAttribute('namespace', $this->getNamespace());
82
        $e->setAttribute('location', $this->getLocation());
83
84
        return $e;
85
    }
86
}
87