Result::parseResultNode()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.5386
c 0
b 0
f 0
cc 7
nc 7
nop 1
1
<?php
2
3
/**
4
 * This file is part of the php-epp2 library.
5
 *
6
 * (c) Gunter Grodotzki <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE file
9
 * that was distributed with this source code.
10
 */
11
12
namespace AfriCC\EPP\Frame\Response;
13
14
use AfriCC\EPP\DOM\DOMTools;
15
use DOMElement;
16
17
class Result
18
{
19
    protected $code;
20
21
    protected $msg;
22
23
    protected $msgLang = 'en';
24
25
    protected $values = [];
26
27
    protected $extValues = [];
28
29
    public function __construct(DOMElement $node)
30
    {
31
        if ($node->hasAttribute('code')) {
32
            $this->code = (int) $node->getAttribute('code');
33
        }
34
35
        $this->parseResultNode($node);
36
    }
37
38
    public function success()
39
    {
40
        if ($this->code() >= 1000 && $this->code() < 2000) {
41
            return true;
42
        }
43
44
        return false;
45
    }
46
47
    public function code()
48
    {
49
        return $this->code;
50
    }
51
52
    public function message()
53
    {
54
        return $this->msg;
55
    }
56
57
    public function messageLanguage()
58
    {
59
        return $this->msgLang;
60
    }
61
62
    public function values()
63
    {
64
        return $this->values;
65
    }
66
67
    public function extValues()
68
    {
69
        return $this->extValues;
70
    }
71
72
    protected function parseResultNode($node)
73
    {
74
        foreach ($node->childNodes as $each) {
75
            if ($each->nodeType !== XML_ELEMENT_NODE) {
76
                continue;
77
            }
78
79
            switch ($each->localName) {
80
                case 'msg':
81
                    $this->msg = $each->nodeValue;
82
                    if ($each->hasAttribute('lang')) {
83
                        $this->msgLang = $each->getAttribute('lang');
84
                    }
85
                    break;
86
87
                case 'value':
88
                    $this->values = array_merge_recursive($this->values, DOMTools::nodeToArray($each));
89
                    break;
90
91
                case 'extValue':
92
                    $this->extValues = array_merge_recursive($this->extValues, DOMTools::nodeToArray($each));
93
                    break;
94
95
                default:
96
                    break;
97
            }
98
        }
99
    }
100
}
101