Passed
Pull Request — master (#225)
by Jaime Pérez
02:23
created

AbstractReference::setURI()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2\XML\xenc;
6
7
use DOMElement;
8
use Webmozart\Assert\Assert;
9
10
/**
11
 * Abstract class representing references. No custom elements are allowed.
12
 *
13
 * @package simplesamlphp/saml2
14
 */
15
abstract class AbstractReference extends AbstractXencElement
16
{
17
    /** @var string */
18
    protected $uri;
19
20
21
    /**
22
     * AbstractReference constructor.
23
     *
24
     * @param string $uri
25
     */
26
    public function __construct(string $uri)
27
    {
28
        $this->setURI($uri);
29
    }
30
31
32
    /**
33
     * Get the value of the URI attribute of this reference.
34
     *
35
     * @return string
36
     */
37
    public function getURI(): string
38
    {
39
        return $this->uri;
40
    }
41
42
43
    /**
44
     * @param string $uri
45
     */
46
    protected function setURI(string $uri): void
47
    {
48
        Assert::notEmpty($uri, 'The URI attribute of a reference cannot be empty.');
49
        $this->uri = $uri;
50
    }
51
52
53
    /**
54
     * @inheritDoc
55
     */
56
    public static function fromXML(DOMElement $xml): object
57
    {
58
        Assert::same($xml->localName, static::getClassName(static::class));
59
        Assert::same($xml->namespaceURI, static::NS);
60
61
        return new static(self::getAttribute($xml, 'URI'));
62
    }
63
64
65
    /**
66
     * @inheritDoc
67
     */
68
    public function toXML(DOMElement $parent = null): DOMElement
69
    {
70
        $e = $this->instantiateParentElement($parent);
71
        $e->setAttribute('URI', $this->uri);
72
        return $e;
73
    }
74
}
75