@@ -297,8 +297,8 @@ public function __toString()
297
297
*/
298
298
public function clear ()
299
299
{
300
- // Break link to origin & branch
301
- unset( $ this ->dom , $ this -> parent ) ;
300
+ $ this -> dom = null ;
301
+ $ this ->parent = null ;
302
302
}
303
303
304
304
/**
@@ -321,7 +321,7 @@ public function dump($show_attr = true, $depth = 0)
321
321
322
322
echo "\n" ;
323
323
324
- if ($ this ->nodes ) {
324
+ if (! empty ( $ this ->nodes ) ) {
325
325
foreach ($ this ->nodes as $ node ) {
326
326
$ node ->dump ($ show_attr , $ depth + 1 );
327
327
}
@@ -475,7 +475,7 @@ public function outertext()
475
475
$ ret .= $ this ->_ [self ::HDOM_INFO_INNER ];
476
476
}
477
477
478
- if ($ this ->nodes ) {
478
+ if (! empty ( $ this ->nodes ) ) {
479
479
foreach ($ this ->nodes as $ n ) {
480
480
$ ret .= $ n ->outertext ();
481
481
}
@@ -531,34 +531,32 @@ public function text($trim = true)
531
531
$ ret = $ this ->_ [self ::HDOM_INFO_TEXT ];
532
532
}
533
533
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 )));
537
538
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
+ }
541
542
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 )));
545
550
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
+ }
553
554
554
- if (empty ($ inline )) {
555
- continue ;
555
+ $ ret .= $ this ->convert_text ($ n ->text (false ));
556
556
}
557
-
557
+ } else {
558
558
$ ret .= $ this ->convert_text ($ n ->text (false ));
559
559
}
560
- } else {
561
- $ ret .= $ this ->convert_text ($ n ->text (false ));
562
560
}
563
561
}
564
562
@@ -1537,23 +1535,23 @@ public function setAttribute($name, $value)
1537
1535
*/
1538
1536
public function hasAttribute ($ name )
1539
1537
{
1540
- return isset ($ this ->{ $ name} );
1538
+ return isset ($ this ->attr [ $ name] );
1541
1539
}
1542
1540
1543
1541
/**
1544
1542
* @param string $name
1545
1543
*/
1546
1544
public function removeAttribute ($ name )
1547
1545
{
1548
- unset($ this ->{ $ name} );
1546
+ unset($ this ->attr [ $ name] );
1549
1547
}
1550
1548
1551
1549
/**
1552
1550
* Remove
1553
1551
*/
1554
1552
public function remove ()
1555
1553
{
1556
- if ($ this ->parent ) {
1554
+ if (! empty ( $ this ->parent ) ) {
1557
1555
$ this ->parent ->removeChild ($ this );
1558
1556
}
1559
1557
}
0 commit comments