Completed
Push — master ( c719ff...c812d0 )
by Auke
101:35 queued 98:19
created

Proxy::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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 2
17 2
    public function __construct( $node, $parser) {
18 2
        $this->ProxyConstruct( $node );
19 2
        $this->parser = $parser;
20
    }
21 1
22 1
    public function __toString() {
23
        return $this->target->asXML();
24
    }
25 2
26 2
    public function __get( $name) {
27 2
        if ($name == 'nodeValue') {
28
            return $this->target.'';
29 1
        }
30 1
        $value = $this->target->{$name};
31 1
        if (is_object( $value )) {
32
            return new static( $value, $this->parser );
33
        } else {
34
            return $value;
35
        }
36
    }
37 1
    
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
            if ( isset($result) && is_object($result) ) {
43 1
                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
            return $result;
55
        } else {
56
            return $this->ProxyCall($name, $args);
57
        }
58
    }
59
60
    public function find( $query) {
61
        $xpath = \arc\xml::css2Xpath( $query );
62
        $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
        foreach ($temp as $key => $value) {
64
            $temp[ $key ] = new static( $value, $this->parser );
65
        }
66
        return $temp;
67
    }
68
    
69
    public function offsetGet( $offset )
70
    {
71
        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