@@ -58,7 +58,7 @@ class Crawler implements \Countable, \IteratorAggregate
58
58
*/
59
59
private bool $ isHtml = true ;
60
60
61
- private ? HTML5 $ html5Parser ;
61
+ private HTML5 $ html5Parser ;
62
62
63
63
/**
64
64
* @param \DOMNodeList|\DOMNode|\DOMNode[]|string|null $node A Node to use as the base for the crawling
@@ -67,7 +67,7 @@ public function __construct(\DOMNodeList|\DOMNode|array|string $node = null, str
67
67
{
68
68
$ this ->uri = $ uri ;
69
69
$ this ->baseHref = $ baseHref ?: $ uri ;
70
- $ this ->html5Parser = class_exists ( HTML5 ::class) ? new HTML5 (['disable_html_ns ' => true ]) : null ;
70
+ $ this ->html5Parser = new HTML5 (['disable_html_ns ' => true ]);
71
71
$ this ->cachedNamespaces = new \ArrayObject ();
72
72
73
73
$ this ->add ($ node );
@@ -589,7 +589,7 @@ public function html(string $default = null): string
589
589
$ node = $ this ->getNode (0 );
590
590
$ owner = $ node ->ownerDocument ;
591
591
592
- if (null !== $ this -> html5Parser && '<!DOCTYPE html> ' === $ owner ->saveXML ($ owner ->childNodes [0 ])) {
592
+ if ('<!DOCTYPE html> ' === $ owner ->saveXML ($ owner ->childNodes [0 ])) {
593
593
$ owner = $ this ->html5Parser ;
594
594
}
595
595
@@ -610,7 +610,7 @@ public function outerHtml(): string
610
610
$ node = $ this ->getNode (0 );
611
611
$ owner = $ node ->ownerDocument ;
612
612
613
- if (null !== $ this -> html5Parser && '<!DOCTYPE html> ' === $ owner ->saveXML ($ owner ->childNodes [0 ])) {
613
+ if ('<!DOCTYPE html> ' === $ owner ->saveXML ($ owner ->childNodes [0 ])) {
614
614
$ owner = $ this ->html5Parser ;
615
615
}
616
616
@@ -1178,12 +1178,10 @@ private function parseHtmlString(string $content, string $charset): \DOMDocument
1178
1178
1179
1179
private function canParseHtml5String (string $ content ): bool
1180
1180
{
1181
- if (null === $ this ->html5Parser ) {
1182
- return false ;
1183
- }
1184
1181
if (false === ($ pos = stripos ($ content , '<!doctype html> ' ))) {
1185
1182
return false ;
1186
1183
}
1184
+
1187
1185
$ header = substr ($ content , 0 , $ pos );
1188
1186
1189
1187
return '' === $ header || $ this ->isValidHtml5Heading ($ header );
0 commit comments