Passed
Pull Request — master (#18)
by Tim
08:00 queued 05:44
created

X509Certificate   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 34
rs 10
c 3
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 6 1
A validateContent() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\ds;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\XMLStringElementTrait;
11
12
13
/**
14
 * Class representing a ds:X509Certificate element.
15
 *
16
 * @package simplesamlphp/xml-security
17
 */
18
final class X509Certificate extends AbstractDsElement
19
{
20
    use XMLStringElementTrait;
21
22
23
    /**
24
     * Validate the content of the element.
25
     *
26
     * @param string $content  The value to go in the XML textContent
27
     * @throws \Exception on failure
28
     * @return void
29
     */
30
    private function validateContent(string $content): void
0 ignored issues
show
Unused Code introduced by
The method validateContent() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
31
    {
32
        Assert::notEmpty($content, 'ds:X509Certificate cannot be empty');
33
        Assert::stringPlausibleBase64($content, 'ds:X509Certificate is not a valid Base64 encoded string');
34
    }
35
36
37
    /**
38
     * Convert XML into a X509Certificate
39
     *
40
     * @param \DOMElement $xml The XML element we should load
41
     * @return self
42
     *
43
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
44
     *   If the qualified name of the supplied element is wrong
45
     */
46
    public static function fromXML(DOMElement $xml): object
47
    {
48
        Assert::same($xml->localName, 'X509Certificate', InvalidDOMElementException::class);
49
        Assert::same($xml->namespaceURI, X509Certificate::NS, InvalidDOMElementException::class);
50
51
        return new self($xml->textContent);
52
    }
53
}
54