CipherReference   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 10 2
A fromXML() 0 9 1
A __construct() 0 7 1
A getURI() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\xenc;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Constants as C;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\Exception\SchemaViolationException;
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
use SimpleSAML\XMLSecurity\XML\xenc\Transforms;
15
16
/**
17
 * Class representing a CipherReference.
18
 *
19
 * @package simplesamlphp/xml-security
20
 */
21
final class CipherReference extends AbstractXencElement implements SchemaValidatableElementInterface
22
{
23
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\XML\xenc\CipherReference: $message, $line
Loading history...
24
25
    /**
26
     * AbstractReference constructor.
27
     *
28
     * @param string $uri
29
     * @param \SimpleSAML\XMLSecurity\XML\xenc\Transforms[] $transforms
30
     */
31
    final public function __construct(
32
        protected string $uri,
33
        protected array $transforms = [],
34
    ) {
35
        Assert::validURI($uri, SchemaViolationException::class); // Covers the empty string
36
        Assert::maxCount($transforms, C::UNBOUNDED_LIMIT);
37
        Assert::allIsInstanceOf($transforms, Transforms::class, SchemaViolationException::class);
38
    }
39
40
41
    /**
42
     * Get the value of the URI attribute of this reference.
43
     *
44
     * @return string
45
     */
46
    public function getURI(): string
47
    {
48
        return $this->uri;
49
    }
50
51
52
    /**
53
     * @inheritDoc
54
     *
55
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
56
     *   if the qualified name of the supplied element is wrong
57
     * @throws \SimpleSAML\XML\Exception\MissingAttributeException
58
     *   if the supplied element is missing one of the mandatory attributes
59
     */
60
    public static function fromXML(DOMElement $xml): static
61
    {
62
        Assert::same($xml->localName, static::getClassName(static::class), InvalidDOMElementException::class);
63
        Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
64
65
        $URI = self::getAttribute($xml, 'URI');
66
        $transforms = Transforms::getChildrenOfClass($xml);
67
68
        return new static($URI, $transforms);
69
    }
70
71
72
    /**
73
     * @inheritDoc
74
     */
75
    public function toXML(?DOMElement $parent = null): DOMElement
76
    {
77
        $e = $this->instantiateParentElement($parent);
78
        $e->setAttribute('URI', $this->getUri());
79
80
        foreach ($this->transforms as $transforms) {
81
            $transforms->toXML($e);
82
        }
83
84
        return $e;
85
    }
86
}
87