Completed
Push — master ( 99f7bd...3359a6 )
by Robbert
02:10
created

Proxy::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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 {
9
10
    use \arc\traits\Proxy {
11
        \arc\traits\Proxy::__construct as private ProxyConstruct;
12
    }
13
14
    private $parser = null;
15
16 2
    public function __construct( $node, $parser) {
17 2
        $this->ProxyConstruct( $node );
18 2
        $this->parser = $parser;
19 2
    }
20
21 1
    public function __toString() {
22 1
        return $this->target->asXML();
23
    }
24
25 2
    public function __get( $name) {
26 2
        if ($name == 'nodeValue') {
27 2
            return $this->target.'';
28
        }
29 1
        $value = $this->target->{$name};
30 1
        if (is_object( $value )) {
31 1
            return new Proxy( $value, $this->parser );
32
        } else {
33
            return $value;
34
        }
35
    }
36
37 1
    public function find( $query) {
38 1
        $xpath = \arc\xml::css2Xpath( $query );
39 1
        $temp = $this->target->xpath( $xpath );
40 1
        foreach ($temp as $key => $value) {
41 1
            $temp[ $key ] = new Proxy( $value, $this->parser );
42 1
        }
43 1
        return $temp;
44
    }
45
}
46