Skip to content

Commit 890431c

Browse files
committed
Added more type checking to avoid strict type errors.
1 parent 22d7fe3 commit 890431c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/PHPHtmlParser/Curl.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class Curl implements CurlInterface
2121
public function get(string $url): string
2222
{
2323
$ch = curl_init($url);
24+
if ($ch === false) {
25+
throw new CurlException('Curl Init return `false`.');
26+
}
2427

2528
if ( ! ini_get('open_basedir')) {
2629
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
@@ -37,6 +40,8 @@ public function get(string $url): string
3740
// there was a problem
3841
$error = curl_error($ch);
3942
throw new CurlException('Error retrieving "'.$url.'" ('.$error.')');
43+
} elseif ($content === true) {
44+
throw new CurlException('Unexpected return value of content set to true.');
4045
}
4146

4247
return $content;

src/PHPHtmlParser/Dom/InnerNode.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ public function addChild(AbstractNode $child, int $before = -1): bool
165165
array_splice($children, $index, 0, [$insert]);
166166

167167
// add the child
168-
$this->children = array_combine($keys, $children);
168+
$combination = array_combine($keys, $children);
169+
if ($combination !== false) {
170+
$this->children = $combination;
171+
}
169172

170173
// tell child I am the new parent
171174
$child->setParent($this);
@@ -338,7 +341,10 @@ public function replaceChild(int $childId, AbstractNode $newChild): void
338341
$keys = array_keys($this->children);
339342
$index = array_search($childId, $keys, true);
340343
$keys[$index] = $newChild->id();
341-
$this->children = array_combine($keys, $this->children);
344+
$combination = array_combine($keys, $this->children);
345+
if ($combination !== false) {
346+
$this->children = $combination;
347+
}
342348
$this->children[$newChild->id()] = [
343349
'prev' => $oldChild['prev'],
344350
'node' => $newChild,

0 commit comments

Comments
 (0)