• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

voku / simple_html_dom / 24291591710

11 Apr 2026 09:05PM UTC coverage: 69.094%. Remained the same
24291591710

push

github

web-flow
Merge pull request #118 from devteam-emroc/master

Symfony 8.0 support

1243 of 1799 relevant lines covered (69.09%)

248.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/voku/helper/AbstractSimpleXmlDom.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace voku\helper;
6

7
abstract class AbstractSimpleXmlDom
8
{
9
    /**
10
     * @var array
11
     */
12
    protected static $functionAliases = [
13
        'children'     => 'childNodes',
14
        'first_child'  => 'firstChild',
15
        'last_child'   => 'lastChild',
16
        'next_sibling' => 'nextSibling',
17
        'prev_sibling' => 'previousSibling',
18
        'parent'       => 'parentNode',
19
    ];
20

21
    /**
22
     * @var \DOMElement|\DOMNode|null
23
     */
24
    protected $node;
25

26
    /**
27
     * @param string $name
28
     * @param array  $arguments
29
     *
30
     * @throws \BadMethodCallException
31
     *
32
     * @return SimpleXmlDomInterface|string|null
33
     */
34
    public function __call($name, $arguments)
35
    {
36
        $name = \strtolower($name);
×
37

38
        if (isset(self::$functionAliases[$name])) {
×
39
            return \call_user_func_array([$this, self::$functionAliases[$name]], $arguments);
×
40
        }
41

42
        throw new \BadMethodCallException('Method does not exist');
×
43
    }
44

45
    /**
46
     * @param string $name
47
     *
48
     * @return array|string|null
49
     */
50
    public function __get($name)
51
    {
52
        $nameOrig = $name;
×
53
        $name = \strtolower($name);
×
54

55
        switch ($name) {
56
            case 'xml':
×
57
                return $this->xml();
×
58
            case 'plaintext':
×
59
                return $this->text();
×
60
            case 'tag':
×
61
                return $this->node->nodeName ?? '';
×
62
            case 'attr':
×
63
                return $this->getAllAttributes();
×
64
            default:
65
                if ($this->node && \property_exists($this->node, $nameOrig)) {
×
66
                    return $this->node->{$nameOrig};
×
67
                }
68

69
                return $this->getAttribute($name);
×
70
        }
71
    }
72

73
    /**
74
     * @param string $selector
75
     * @param int|null    $idx
76
     *
77
     * @return SimpleXmlDomInterface|SimpleXmlDomInterface[]|SimpleXmlDomNodeInterface<SimpleXmlDomInterface>
78
     */
79
    public function __invoke($selector, $idx = null)
80
    {
81
        return $this->find($selector, $idx);
×
82
    }
83

84
    /**
85
     * @param string $name
86
     *
87
     * @return bool
88
     */
89
    public function __isset($name)
90
    {
91
        $nameOrig = $name;
×
92
        $name = \strtolower($name);
×
93

94
        switch ($name) {
95
            case 'outertext':
×
96
            case 'outerhtml':
×
97
            case 'innertext':
×
98
            case 'innerhtml':
×
99
            case 'innerhtmlkeep':
×
100
            case 'plaintext':
×
101
            case 'text':
×
102
            case 'tag':
×
103
                return true;
×
104
            default:
105
                if ($this->node && \property_exists($this->node, $nameOrig)) {
×
106
                    return isset($this->node->{$nameOrig});
×
107
                }
108

109
                return $this->hasAttribute($name);
×
110
        }
111
    }
112

113
    /**
114
     * @param string $name
115
     * @param mixed  $value
116
     *
117
     * @return SimpleXmlDomInterface|null
118
     */
119
    public function __set($name, $value)
120
    {
121
        $nameOrig = $name;
×
122
        $name = \strtolower($name);
×
123

124
        switch ($name) {
125
            case 'outerhtml':
×
126
            case 'outertext':
×
127
                return $this->replaceNodeWithString($value);
×
128
            case 'innertext':
×
129
            case 'innerhtml':
×
130
                return $this->replaceChildWithString($value);
×
131
            case 'innerhtmlkeep':
×
132
                return $this->replaceChildWithString($value, false);
×
133
            case 'plaintext':
×
134
                return $this->replaceTextWithString($value);
×
135
            default:
136
                if ($this->node && \property_exists($this->node, $nameOrig)) {
×
137
                    return $this->node->{$nameOrig} = $value;
×
138
                }
139

140
                return $this->setAttribute($name, $value);
×
141
        }
142
    }
143

144
    /**
145
     * @return string
146
     */
147
    public function __toString()
148
    {
149
        return $this->xml();
×
150
    }
151

152
    /**
153
     * @param string $name
154
     *
155
     * @return void
156
     */
157
    public function __unset($name)
158
    {
159
        /** @noinspection UnusedFunctionResultInspection */
160
        $this->removeAttribute($name);
×
161
    }
162

163
    /**
164
     * @param string $selector
165
     * @param int|null   $idx
166
     *
167
     * @return SimpleXmlDomInterface|SimpleXmlDomInterface[]|SimpleXmlDomNodeInterface<SimpleXmlDomInterface>
168
     */
169
    abstract public function find(string $selector, $idx = null);
170

171
    /**
172
     * @return string[]|null
173
     */
174
    abstract public function getAllAttributes();
175

176
    /**
177
     * @param string $name
178
     *
179
     * @return string
180
     */
181
    abstract public function getAttribute(string $name): string;
182

183
    /**
184
     * @param string $name
185
     *
186
     * @return bool
187
     */
188
    abstract public function hasAttribute(string $name): bool;
189

190
    abstract public function innerXml(bool $multiDecodeNewHtmlEntity = false): string;
191

192
    abstract public function removeAttribute(string $name): SimpleXmlDomInterface;
193

194
    abstract protected function replaceChildWithString(string $string, bool $putBrokenReplacedBack = true): SimpleXmlDomInterface;
195

196
    abstract protected function replaceNodeWithString(string $string): SimpleXmlDomInterface;
197

198
    /**
199
     * @param string $string
200
     *
201
     * @return SimpleXmlDomInterface
202
     */
203
    abstract protected function replaceTextWithString($string): SimpleXmlDomInterface;
204

205
    /**
206
     * @param string $name
207
     * @param string|null   $value
208
     * @param bool   $strictEmptyValueCheck
209
     *
210
     * @return SimpleXmlDomInterface
211
     */
212
    abstract public function setAttribute(string $name, $value = null, bool $strictEmptyValueCheck = false): SimpleXmlDomInterface;
213

214
    abstract public function text(): string;
215

216
    abstract public function xml(bool $multiDecodeNewHtmlEntity = false): string;
217
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc