Skip to content

Commit 0a72030

Browse files
committed
...
1 parent ccafdc9 commit 0a72030

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

HtmlNode.php

+26-28
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ public function __toString()
297297
*/
298298
public function clear()
299299
{
300-
// Break link to origin & branch
301-
unset($this->dom, $this->parent);
300+
$this->dom = null;
301+
$this->parent = null;
302302
}
303303

304304
/**
@@ -321,7 +321,7 @@ public function dump($show_attr = true, $depth = 0)
321321

322322
echo "\n";
323323

324-
if ($this->nodes) {
324+
if (! empty($this->nodes)) {
325325
foreach ($this->nodes as $node) {
326326
$node->dump($show_attr, $depth + 1);
327327
}
@@ -475,7 +475,7 @@ public function outertext()
475475
$ret .= $this->_[self::HDOM_INFO_INNER];
476476
}
477477

478-
if ($this->nodes) {
478+
if (! empty($this->nodes)) {
479479
foreach ($this->nodes as $n) {
480480
$ret .= $n->outertext();
481481
}
@@ -531,34 +531,32 @@ public function text($trim = true)
531531
$ret = $this->_[self::HDOM_INFO_TEXT];
532532
}
533533

534-
if ($this->nodes === null) {
535-
return '';
536-
}
534+
if (! empty($this->nodes)) {
535+
foreach ($this->nodes as $n) {
536+
if ($this->is_block_element($n)) {
537+
$block = ltrim($this->convert_text($n->text(false)));
537538

538-
foreach ($this->nodes as $n) {
539-
if ($this->is_block_element($n)) {
540-
$block = ltrim($this->convert_text($n->text(false)));
539+
if (empty($block)) {
540+
continue;
541+
}
541542

542-
if (empty($block)) {
543-
continue;
544-
}
543+
$ret = rtrim($ret) . "\n\n" . $block;
544+
} elseif ($this->is_inline_element($n)) {
545+
// todo: <br> introduces code smell because no space but \n
546+
if (strtolower($n->tag) === 'br') {
547+
$ret .= $this->dom->default_br_text ?: DEFAULT_BR_TEXT;
548+
} else {
549+
$inline = ltrim($this->convert_text($n->text(false)));
545550

546-
$ret = rtrim($ret) . "\n\n" . $block;
547-
} elseif ($this->is_inline_element($n)) {
548-
// todo: <br> introduces code smell because no space but \n
549-
if (strtolower($n->tag) === 'br') {
550-
$ret .= $this->dom->default_br_text ?: DEFAULT_BR_TEXT;
551-
} else {
552-
$inline = ltrim($this->convert_text($n->text(false)));
551+
if (empty($inline)) {
552+
continue;
553+
}
553554

554-
if (empty($inline)) {
555-
continue;
555+
$ret .= $this->convert_text($n->text(false));
556556
}
557-
557+
} else {
558558
$ret .= $this->convert_text($n->text(false));
559559
}
560-
} else {
561-
$ret .= $this->convert_text($n->text(false));
562560
}
563561
}
564562

@@ -1537,23 +1535,23 @@ public function setAttribute($name, $value)
15371535
*/
15381536
public function hasAttribute($name)
15391537
{
1540-
return isset($this->{$name});
1538+
return isset($this->attr[$name]);
15411539
}
15421540

15431541
/**
15441542
* @param string $name
15451543
*/
15461544
public function removeAttribute($name)
15471545
{
1548-
unset($this->{$name});
1546+
unset($this->attr[$name]);
15491547
}
15501548

15511549
/**
15521550
* Remove
15531551
*/
15541552
public function remove()
15551553
{
1556-
if ($this->parent) {
1554+
if (! empty($this->parent)) {
15571555
$this->parent->removeChild($this);
15581556
}
15591557
}

0 commit comments

Comments
 (0)