Passed
Pull Request — master (#18)
by Tim
02:10
created

DigestValue::validateContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
 * Class representing a ds:DigestValue element.
14
 *
15
 * @package simplesaml/xml-security
16
 */
17
final class DigestValue extends AbstractDsElement
18
{
19
    use XMLStringElementTrait;
20
21
22
    /**
23
     * Validate the content of the element.
24
     *
25
     * @param string $content  The value to go in the XML textContent
26
     * @throws \Exception on failure
27
     * @return void
28
     */
29
    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...
30
    {
31
        Assert::notEmpty($content, 'DigestValue cannot be empty');
32
        Assert::stringPlausibleBase64($content, 'ds:DigestValue is not a valid Base64 encoded string');
33
    }
34
35
36
    /**
37
     * Convert XML into a DigestValue
38
     *
39
     * @param \DOMElement $xml The XML element we should load
40
     * @return self
41
     *
42
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
43
     *   If the qualified name of the supplied element is wrong
44
     */
45
    public static function fromXML(DOMElement $xml): object
46
    {
47
        Assert::same($xml->localName, 'DigestValue', InvalidDOMElementException::class);
48
        Assert::same($xml->namespaceURI, DigestValue::NS, InvalidDOMElementException::class);
49
50
        return new self($xml->textContent);
51
    }
52
}
53