Skip to content

Commit e2d2d2e

Browse files
committed
Fixed small issues with the Dom object
1 parent b48462d commit e2d2d2e

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/PHPHtmlParser/Dom.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,14 @@ public function find(string $selector, int $nth = null)
252252
{
253253
$this->isLoaded();
254254

255-
return $this->root->find($selector, $nth, $this->options->get('depthFirstSearch'));
255+
$depthFirstSearch = $this->options->get('depthFirstSearch');
256+
if (is_bool($depthFirstSearch)) {
257+
$result = $this->root->find($selector, $nth, $depthFirstSearch);
258+
} else {
259+
$result = $this->root->find($selector, $nth);
260+
}
261+
262+
return $result;
256263
}
257264

258265
/**
@@ -793,15 +800,16 @@ protected function detectCharset(): bool
793800
return false;
794801
}
795802

803+
/** @var AbstractNode $meta */
796804
$meta = $this->root->find('meta[http-equiv=Content-Type]', 0);
797805
if (is_null($meta)) {
798806
// could not find meta tag
799807
$this->root->propagateEncoding($encode);
800808

801809
return false;
802810
}
803-
$content = $meta->content;
804-
if (empty($content)) {
811+
$content = $meta->getAttribute('content');
812+
if (is_null($content)) {
805813
// could not find content
806814
$this->root->propagateEncoding($encode);
807815

src/PHPHtmlParser/Dom/AbstractNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ public function getAttributes(): array
342342
* on the tag of this node.
343343
*
344344
* @param string $key
345-
* @return mixed
345+
* @return string|null
346346
*/
347-
public function getAttribute(string $key)
347+
public function getAttribute(string $key): ?string
348348
{
349349
$attribute = $this->tag->getAttribute($key);
350350
if ( ! is_null($attribute)) {

src/PHPHtmlParser/Dom/Tag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public function getAttributes()
294294
* Returns an attribute by the key
295295
*
296296
* @param string $key
297-
* @return mixed
297+
* @return array|null
298298
*/
299299
public function getAttribute(string $key):array
300300
{

0 commit comments

Comments
 (0)