Passed
Push — master ( 55ada1...4e08ca )
by Giancarlos
02:39
created

XmlUtils   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 37
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractSign() 0 7 1
A extractSignFromDoc() 0 18 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Administrador
5
 * Date: 04/10/2017
6
 * Time: 04:41 PM
7
 */
8
9
namespace Greenter\Report;
10
11
/**
12
 * Class XmlUtils
13
 * @package Greenter\Report
14
 */
15
final class XmlUtils
16
{
17
    /**
18
     * @param string $xml
19
     * @return string
20
     */
21 4
    public static function extractSign($xml)
22
    {
23 4
        $doc = new \DOMDocument();
24 4
        $doc->loadXML($xml);
25
26 4
        return self::extractSignFromDoc($doc);
27
    }
28
29
    /**
30
     * @param \DOMDocument $document
31
     * @return string
32
     */
33 4
    public static function extractSignFromDoc(\DOMDocument $document)
34
    {
35 4
        $xpt = new \DOMXPath($document);
36
37 4
        $exts = $xpt->query('ext:UBLExtensions/ext:UBLExtension', $document->documentElement);
38 4
        if ($exts->length == 0) {
39
            return '';
40
        }
41 4
        $nodeSign = $exts->item($exts->length - 1);
42
43 4
        $hash = $xpt->query('ext:ExtensionContent/ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue', $nodeSign);
44
45 4
        if ($hash->length == 0) {
46
            return '';
47
        }
48
49 4
        return $hash->item(0)->nodeValue;
50
    }
51
}