Code Duplication    Length = 61-61 lines in 2 locations

src/voku/helper/AbstractSimpleHtmlDomNode.php 1 location

@@ 7-67 (lines=61) @@
4
5
namespace voku\helper;
6
7
abstract class AbstractSimpleHtmlDomNode extends \ArrayObject
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 SimpleHtmlDomInterface) {
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 SimpleHtmlDomNodeInterface|SimpleHtmlDomNodeInterface[]|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

src/voku/helper/AbstractSimpleXmlDomNode.php 1 location

@@ 7-67 (lines=61) @@
4
5
namespace voku\helper;
6
7
abstract class AbstractSimpleXmlDomNode extends \ArrayObject
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