Completed
Push — master ( d36330...3c9b9d )
by Lars
01:55
created

AbstractSimpleXmlDomNode   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 61
loc 61
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B __get() 23 23 6
A __invoke() 4 4 1
A __toString() 11 11 2
find() 1 1 ?

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
declare(strict_types=1);
4
5
namespace voku\helper;
6
7 View Code Duplication
abstract class AbstractSimpleXmlDomNode extends \ArrayObject
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
8
{
9
    /** @noinspection MagicMethodsValidityInspection */
10
11
    /**
12
     * @param string $name
13
     *
14
     * @return array|null
15
     */
16
    public function __get($name)
17
    {
18
        // init
19
        $name = \strtolower($name);
20
21
        if ($this->count() > 0) {
22
            $return = [];
23
24
            foreach ($this as $node) {
25
                if ($node instanceof SimpleXmlDomInterface) {
26
                    $return[] = $node->{$name};
27
                }
28
            }
29
30
            return $return;
31
        }
32
33
        if ($name === 'plaintext' || $name === 'outertext') {
34
            return [];
35
        }
36
37
        return null;
38
    }
39
40
    /**
41
     * @param string   $selector
42
     * @param int|null $idx
43
     *
44
     * @return SimpleXmlDomNodeInterface|SimpleXmlDomNodeInterface[]|null
45
     */
46
    public function __invoke($selector, $idx = null)
47
    {
48
        return $this->find($selector, $idx);
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function __toString()
55
    {
56
        // init
57
        $html = '';
58
59
        foreach ($this as $node) {
60
            $html .= $node->outertext;
61
        }
62
63
        return $html;
64
    }
65
66
    abstract public function find(string $selector, $idx = null);
67
}
68