Code Duplication    Length = 65-65 lines in 2 locations

src/voku/helper/AbstractSimpleHtmlDomNode.php 1 location

@@ 10-74 (lines=65) @@
7
/**
8
 * {@inheritDoc}
9
 */
10
abstract class AbstractSimpleHtmlDomNode extends \ArrayObject
11
{
12
    /** @noinspection MagicMethodsValidityInspection */
13
14
    /**
15
     * @param string $name
16
     *
17
     * @return array|int|null
18
     */
19
    public function __get($name)
20
    {
21
        // init
22
        $name = \strtolower($name);
23
24
        if ($name === 'length') {
25
            return $this->count();
26
        }
27
28
        if ($this->count() > 0) {
29
            $return = [];
30
31
            foreach ($this as $node) {
32
                if ($node instanceof SimpleHtmlDomInterface) {
33
                    $return[] = $node->{$name};
34
                }
35
            }
36
37
            return $return;
38
        }
39
40
        if ($name === 'plaintext' || $name === 'outertext') {
41
            return [];
42
        }
43
44
        return null;
45
    }
46
47
    /**
48
     * @param string   $selector
49
     * @param int|null $idx
50
     *
51
     * @return SimpleHtmlDomNodeInterface|SimpleHtmlDomNodeInterface[]|null
52
     */
53
    public function __invoke($selector, $idx = null)
54
    {
55
        return $this->find($selector, $idx);
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function __toString()
62
    {
63
        // init
64
        $html = '';
65
66
        foreach ($this as $node) {
67
            $html .= $node->outertext;
68
        }
69
70
        return $html;
71
    }
72
73
    abstract public function find(string $selector, $idx = null);
74
}
75

src/voku/helper/AbstractSimpleXmlDomNode.php 1 location

@@ 10-74 (lines=65) @@
7
/**
8
 * {@inheritDoc}
9
 */
10
abstract class AbstractSimpleXmlDomNode extends \ArrayObject
11
{
12
    /** @noinspection MagicMethodsValidityInspection */
13
14
    /**
15
     * @param string $name
16
     *
17
     * @return array|int|null
18
     */
19
    public function __get($name)
20
    {
21
        // init
22
        $name = \strtolower($name);
23
24
        if ($name === 'length') {
25
            return $this->count();
26
        }
27
28
        if ($this->count() > 0) {
29
            $return = [];
30
31
            foreach ($this as $node) {
32
                if ($node instanceof SimpleXmlDomInterface) {
33
                    $return[] = $node->{$name};
34
                }
35
            }
36
37
            return $return;
38
        }
39
40
        if ($name === 'plaintext' || $name === 'outertext') {
41
            return [];
42
        }
43
44
        return null;
45
    }
46
47
    /**
48
     * @param string   $selector
49
     * @param int|null $idx
50
     *
51
     * @return SimpleXmlDomNodeInterface|SimpleXmlDomNodeInterface[]|null
52
     */
53
    public function __invoke($selector, $idx = null)
54
    {
55
        return $this->find($selector, $idx);
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function __toString()
62
    {
63
        // init
64
        $html = '';
65
66
        foreach ($this as $node) {
67
            $html .= $node->outertext;
68
        }
69
70
        return $html;
71
    }
72
73
    abstract public function find(string $selector, $idx = null);
74
}
75