Completed
Push — master ( be5edc...ec287b )
by Jaime Pérez
02:56
created

DigestMethod::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SAML2\XML\alg;
4
5
/**
6
 * Class for handling the alg:DigestMethod element.
7
 *
8
 * @link http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-metadata-algsupport.pdf
9
 * @author Jaime Pérez Crespo, UNINETT AS <[email protected]>
10
 * @package simplesamlphp/saml2
11
 */
12
class DigestMethod
13
{
14
    /**
15
     * An URI identifying an algorithm supported for digest operations.
16
     *
17
     * @var string
18
     */
19
    public $Algorithm;
20
21
22
    /**
23
     * Create/parse an alg:DigestMethod element.
24
     *
25
     * @param \DOMElement|null $xml The XML element we should load or null to create a new one from scratch.
26
     *
27
     * @throws \Exception
28
     */
29
    public function __construct(\DOMElement $xml = null)
30
    {
31
        if ($xml === null) {
32
            return;
33
        }
34
35
        if (!$xml->hasAttribute('Algorithm')) {
36
            throw new \Exception('Missing required attribute "Algorithm" in alg:DigestMethod element.');
37
        }
38
        $this->Algorithm = $xml->getAttribute('Algorithm');
39
    }
40
41
42
    /**
43
     * Convert this element to XML.
44
     *
45
     * @param \DOMElement $parent The element we should append to.
46
     * @return \DOMElement
47
     */
48 View Code Duplication
    public function toXML(\DOMElement $parent)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        assert('is_string($this->Algorithm)');
51
52
        $doc = $parent->ownerDocument;
53
        $e = $doc->createElementNS(Common::NS, 'alg:DigestMethod');
54
        $parent->appendChild($e);
55
        $e->setAttribute('Algorithm', $this->Algorithm);
56
57
        return $e;
58
    }
59
}
60