Completed
Push — master ( 0e6fd9...6daf8e )
by Günter
9s
created

Response   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 20
lcom 1
cbo 3
dl 0
loc 71
rs 10
c 2
b 0
f 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A results() 0 10 2
A success() 0 9 3
A code() 0 4 1
A message() 0 4 1
A clientTransactionId() 0 9 2
A serverTransactionId() 0 9 2
B data() 0 17 9
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;
13
14
use AfriCC\EPP\AbstractFrame;
15
use AfriCC\EPP\DOM\DOMTools;
16
use AfriCC\EPP\Frame\Response\Result;
17
use DOMNodeList;
18
19
/**
20
 * @see http://tools.ietf.org/html/rfc5730#section-2.6
21
 */
22
class Response extends AbstractFrame
23
{
24
    public function results()
25
    {
26
        $results = [];
27
        $nodes = $this->get('//epp:epp/epp:response/epp:result');
28
        foreach ($nodes as $node) {
0 ignored issues
show
Bug introduced by
The expression $nodes of type false|string|object<DOMNodeList> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
29
            $results[] = new Result($node);
30
        }
31
32
        return $results;
33
    }
34
35
    public function success()
36
    {
37
        $code = $this->code();
38
        if ($code >= 1000 && $code < 2000) {
39
            return true;
40
        }
41
42
        return false;
43
    }
44
45
    public function code()
46
    {
47
        return (int) $this->get('//epp:epp/epp:response/epp:result/@code');
48
    }
49
50
    public function message()
51
    {
52
        return (string) $this->get('//epp:epp/epp:response/epp:result/epp:msg/text()');
53
    }
54
55
    public function clientTransactionId()
56
    {
57
        $value = $this->get('//epp:epp/epp:response/epp:trID/epp:clTRID/text()');
58
        if ($value === false) {
59
            return;
60
        }
61
62
        return (string) $value;
63
    }
64
65
    public function serverTransactionId()
66
    {
67
        $value = $this->get('//epp:epp/epp:response/epp:trID/epp:svTRID/text()');
68
        if ($value === false) {
69
            return;
70
        }
71
72
        return (string) $value;
73
    }
74
75
    public function data()
76
    {
77
        $nodes = $this->get('//epp:epp/epp:response/epp:resData');
78
        if ($nodes === false || !($nodes instanceof DOMNodeList) || $nodes->length === 0 || !$nodes->item(0)->hasChildNodes()) {
79
            $data = [];
80
        } else {
81
            $data = DOMTools::nodeToArray($nodes->item(0));
0 ignored issues
show
Compatibility introduced by
$nodes->item(0) of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
82
        }
83
84
        // check for extension data
85
        $nodes = $this->get('//epp:epp/epp:response/epp:extension');
86
        if ($nodes !== false && $nodes instanceof DOMNodeList && $nodes->length > 0 && $nodes->item(0)->hasChildNodes()) {
87
            $data = array_merge_recursive($data, DOMTools::nodeToArray($nodes->item(0)));
0 ignored issues
show
Compatibility introduced by
$nodes->item(0) of type object<DOMNode> is not a sub-type of object<DOMElement>. It seems like you assume a child class of the class DOMNode to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
88
        }
89
90
        return $data;
91
    }
92
}
93