Completed
Pull Request — master (#12)
by Auke
34:04
created

Proxy   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 63.64%

Importance

Changes 5
Bugs 1 Features 3
Metric Value
wmc 17
c 5
b 1
f 3
lcom 1
cbo 2
dl 0
loc 76
ccs 28
cts 44
cp 0.6364
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 3 1
A __get() 0 11 3
B __call() 0 21 7
A find() 0 8 2
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
1
<?php
2
/*
3
    TODO: implement simplexml access methods to the proxy
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
4
    probably needs to extend ArrayObject in some way to do this properly
5
 */
6
namespace arc\xml;
7
8
class Proxy extends \ArrayObject {
9
10
    use \arc\traits\Proxy {
11
        \arc\traits\Proxy::__construct as private ProxyConstruct;
12
        \arc\traits\Proxy::__call as private ProxyCall;
13
    }
14
15
    private $parser = null;
16
17 3
    public function __construct( $node, $parser) {
18 3
        $this->ProxyConstruct( $node );
19 3
        $this->parser = $parser;
20 3
    }
21
22 1
    public function __toString() {
23 1
        return $this->target->asXML();
24
    }
25
26 2
    public function __get( $name) {
27 2
        if ($name == 'nodeValue') {
28 2
            return $this->target.'';
29
        }
30 1
        $value = $this->target->{$name};
31 1
        if (is_object( $value )) {
32 1
            return new static( $value, $this->parser );
33
        } else {
34
            return $value;
35
        }
36
    }
37
    
38 1
    public function __call( $name, $args ) {
39 1
        if ( !method_exists($this->target, $name) ) {
40 1
            $dom = dom_import_simplexml($this->target);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
41 1
            $result = call_user_func_array( [ $dom, $name], $args );
42 1
            if ( isset($result) && is_object($result) ) {
43
                if ( $result instanceof \DOMNode ) {
44
                    return new static( $result, $this->parser );
45
                }
46
                if ( $result instanceof \DOMNodeList ) {
47
                    $resultArray = [];
48
                    for ( $i=0, $l=$result->length; $i<$l; $i ++ ) {
49
                        $resultArray[$i] = new static( simplexml_import_dom($result->item($i)), $this->parser );
50
                    }
51
                    return $resultArray;
52
                }
53
            }
54 1
            return $result;
55
        } else {
56 1
            return $this->ProxyCall($name, $args);
57
        }
58
    }
59
60 1
    public function find( $query) {
61 1
        $xpath = \arc\xml::css2Xpath( $query );
62 1
        $temp = $this->target->xpath( $xpath );
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
63 1
        foreach ($temp as $key => $value) {
64 1
            $temp[ $key ] = new static( $value, $this->parser );
65 1
        }
66 1
        return $temp;
67
    }
68
    
69 1
    public function offsetGet( $offset )
70
    {
71 1
        return (string) $this->target[$offset];
72
    }
73
    
74
    public function offsetSet( $offset, $value )
75
    {
76
        $this->target[$offset] = $value;
77
    }
78
    
79
    public function offsetUnset( $offset )
80
    {
81
        unset( $this->target[$offset] );
82
    }
83
}
84