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

Xml   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 46
Duplicated Lines 26.09 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 10
c 2
b 1
f 0
lcom 1
cbo 1
dl 12
loc 46
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A loadData() 0 6 1
A readPath() 12 15 3
A getArray() 0 4 1
A __toString() 0 4 1
A __isset() 0 4 2
A __get() 0 4 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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