Completed
Push — master ( b2aa64...db9a1b )
by Alexey
05:01
created

Xml::readPath()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 12
Ratio 80 %
Metric Value
dl 12
loc 15
rs 9.4285
cc 3
eloc 11
nc 4
nop 1
1
<?php
2
3
/**
4
 * Reader xml
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Migrations\Reader;
13
14
class Xml extends \Migrations\Reader
15
{
16
    public function loadData($source = '')
17
    {
18
        $this->source = $source;
19
        $this->data = new \SimpleXMLElement(file_get_contents($source));
20
        return true;
21
    }
22
23
    public function readPath($path = '/')
24
    {
25 View Code Duplication
        foreach ($this->data->attributes() as $code => $item) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
            $reader = new Xml();
27
            $reader->source = $this->source;
28
            $reader->data = $item;
29
            yield $code => $reader;
30
        }
31 View Code Duplication
        foreach ($this->data as $code => $item) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
            $reader = new Xml();
33
            $reader->source = $this->source;
34
            $reader->data = $item;
35
            yield $code => $reader;
36
        }
37
    }
38
39
    public function getArray()
40
    {
41
        return json_decode(json_encode($this->data), true);
42
    }
43
44
    public function __toString()
45
    {
46
        return (string) $this->data;
47
    }
48
49
    public function __isset($name)
50
    {
51
        return isset($this->data->$name) || isset($this->data[$name]);
52
    }
53
54
    public function __get($name)
55
    {
56
        return ($this->data->$name) ? (string) ($this->data->$name) : (string) $this->data[$name];
57
    }
58
59
}
60