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

voku / simple_html_dom / 24359589807

13 Apr 2026 06:19PM UTC coverage: 68.781% (-0.4%) from 69.192%
24359589807

Pull #134

github

web-flow
Merge deba06344 into ec1d6a961
Pull Request #134: [WIP] Add support for PHP8's Nullsafe operator

18 of 38 new or added lines in 10 files covered. (47.37%)

10 existing lines in 2 files now uncovered.

1388 of 2018 relevant lines covered (68.78%)

225.24 hits per line

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

45.71
/src/voku/helper/SimpleHtmlDomNode.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace voku\helper;
6

7
/**
8
 * {@inheritdoc}
9
 */
10
class SimpleHtmlDomNode extends AbstractSimpleHtmlDomNode implements SimpleHtmlDomNodeInterface
11
{
12
    /**
13
     * Find list of nodes with a CSS selector.
14
     *
15
     * @param string   $selector
16
     * @param int|null $idx
17
     *
18
     * @return SimpleHtmlDomNodeInterface<SimpleHtmlDomInterface>|SimpleHtmlDomNodeInterface[]|null
19
     */
20
    public function find(string $selector, $idx = null)
21
    {
22
        // init
23
        $elements = new static();
77✔
24

25
        foreach ($this as $node) {
77✔
26
            \assert($node instanceof SimpleHtmlDomInterface);
27
            foreach ($node->find($selector) as $res) {
77✔
28
                $elements[] = $res;
70✔
29
            }
30
        }
31

32
        // return all elements
33
        if ($idx === null) {
77✔
34
            if (\count($elements) === 0) {
77✔
35
                return new SimpleHtmlDomNodeBlank();
7✔
36
            }
37

38
            return $elements;
70✔
39
        }
40

41
        // handle negative values
42
        if ($idx < 0) {
×
43
            $idx = \count($elements) + $idx;
×
44
        }
45

46
        // return one element
47
        return $elements[$idx] ?? null;
×
48
    }
49

50
    /**
51
     * Find nodes with a CSS selector.
52
     *
53
     * @param string $selector
54
     *
55
     * @return SimpleHtmlDomInterface[]|SimpleHtmlDomNodeInterface<SimpleHtmlDomInterface>
56
     */
57
    public function findMulti(string $selector): SimpleHtmlDomNodeInterface
58
    {
59
        return $this->find($selector, null);
×
60
    }
61

62
    /**
63
     * Find nodes with a CSS selector.
64
     *
65
     * @param string $selector
66
     *
67
     * @return false|SimpleHtmlDomInterface[]|SimpleHtmlDomNodeInterface<SimpleHtmlDomInterface>
68
     */
69
    public function findMultiOrFalse(string $selector)
70
    {
71
        $return = $this->find($selector, null);
×
72

73
        if ($return instanceof SimpleHtmlDomNodeBlank) {
×
74
            return false;
×
75
        }
76

77
        return $return;
×
78
    }
79

80
    /**
81
     * Find nodes with a CSS selector or null, if no element is found.
82
     *
83
     * @param string $selector
84
     *
85
     * @return null|SimpleHtmlDomInterface[]|SimpleHtmlDomNodeInterface<SimpleHtmlDomInterface>
86
     */
87
    public function findMultiOrNull(string $selector)
88
    {
NEW
89
        $return = $this->find($selector, null);
×
90

NEW
91
        if ($return instanceof SimpleHtmlDomNodeBlank) {
×
NEW
92
            return null;
×
93
        }
94

NEW
95
        return $return;
×
96
    }
97

98
    /**
99
     * Find one node with a CSS selector.
100
     *
101
     * @param string $selector
102
     *
103
     * @return SimpleHtmlDomNodeInterface<SimpleHtmlDomInterface>
104
     */
105
    public function findOne(string $selector)
106
    {
107
        $return = $this->find($selector, 0);
×
108

109
        return $return ?? new SimpleHtmlDomNodeBlank();
×
110
    }
111

112
    /**
113
     * Find one node with a CSS selector.
114
     *
115
     * @param string $selector
116
     *
117
     * @return false|SimpleHtmlDomNodeInterface<SimpleHtmlDomInterface>
118
     */
119
    public function findOneOrFalse(string $selector)
120
    {
121
        $return = $this->find($selector, 0);
×
122

123
        return $return ?? false;
×
124
    }
125

126
    /**
127
     * Find one node with a CSS selector or null, if no element is found.
128
     *
129
     * @param string $selector
130
     *
131
     * @return null|SimpleHtmlDomNodeInterface<SimpleHtmlDomInterface>
132
     */
133
    public function findOneOrNull(string $selector)
134
    {
NEW
135
        return $this->find($selector, 0);
×
136
    }
137

138
    /**
139
     * Get html of elements.
140
     *
141
     * @return string[]
142
     */
143
    public function innerHtml(): array
144
    {
145
        // init
146
        $html = [];
7✔
147

148
        foreach ($this as $node) {
7✔
149
            $html[] = $node->outertext;
7✔
150
        }
151

152
        return $html;
7✔
153
    }
154

155
    /**
156
     * alias for "$this->innerHtml()" (added for compatibly-reasons with v1.x)
157
     *
158
     * @return string[]
159
     */
160
    public function innertext()
161
    {
UNCOV
162
        return $this->innerHtml();
×
163
    }
164

165
    /**
166
     * alias for "$this->innerHtml()" (added for compatibly-reasons with v1.x)
167
     *
168
     * @return string[]
169
     */
170
    public function outertext()
171
    {
UNCOV
172
        return $this->innerHtml();
×
173
    }
174

175
    /**
176
     * Get plain text.
177
     *
178
     * @return string[]
179
     */
180
    public function text(): array
181
    {
182
        // init
183
        $text = [];
49✔
184

185
        foreach ($this as $node) {
49✔
186
            $text[] = $node->plaintext;
49✔
187
        }
188

189
        return $text;
49✔
190
    }
191
}
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