Skip to content

Commit 6bc7438

Browse files
committed
Added more type checking to avoid strict type errors.
1 parent e2d2d2e commit 6bc7438

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
@@ -22,6 +22,9 @@ class Curl implements CurlInterface
2222
public function get(string $url, array $options): string
2323
{
2424
$ch = curl_init($url);
25+
if ($ch === false) {
26+
throw new CurlException('Curl Init return `false`.');
27+
}
2528

2629
if ( ! ini_get('open_basedir')) {
2730
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
@@ -42,6 +45,8 @@ public function get(string $url, array $options): string
4245
// there was a problem
4346
$error = curl_error($ch);
4447
throw new CurlException('Error retrieving "'.$url.'" ('.$error.')');
48+
} elseif ($content === true) {
49+
throw new CurlException('Unexpected return value of content set to true.');
4550
}
4651

4752
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)