Passed
Pull Request — master (#358)
by Tim
02:17
created

Artifact   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromXML() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Base64ElementTrait;
10
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11
use SimpleSAML\XML\Exception\SchemaViolationException;
12
13
/**
14
 * Class for SAML artifacts.
15
 *
16
 * @package simplesamlphp/saml2
17
 */
18
final class Artifact extends AbstractSamlpElement
19
{
20
    use Base64ElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\Base64ElementTrait requires some properties which are not provided by SimpleSAML\SAML2\XML\samlp\Artifact: $localName, $namespaceURI
Loading history...
21
22
    /**
23
     * Initialize an artifact.
24
     *
25
     * @param string $content
26
     */
27
    public function __construct(
28
        string $content,
29
    ) {
30
        $this->setContent($content);
31
    }
32
33
34
    /**
35
     * Convert XML into an Artifact
36
     *
37
     * @param \DOMElement $xml The XML element we should load
38
     * @return static
39
     *
40
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
41
     *   If the qualified name of the supplied element is wrong
42
     */
43
    public static function fromXML(DOMElement $xml): static
44
    {
45
        Assert::same($xml->localName, 'Artifact', InvalidDOMElementException::class);
46
        Assert::same($xml->namespaceURI, Artifact::NS, InvalidDOMElementException::class);
47
48
        return new static($xml->textContent);
49
    }
50
}
51