Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/HtmlProcessor/AbstractHtmlProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ abstract class AbstractHtmlProcessor
= '%<template[\\s>][^<]*+(?:<(?!/template>)[^<]*+)*+(?:</template>|$)%i';

/**
* @var \DOMDocument|null
* @var \DOMDocument
*/
protected $domDocument = null;
private $domDocument;

/**
* @var \DOMXPath|null
Expand Down Expand Up @@ -115,15 +115,13 @@ private function setHtml(string $html): void
*/
public function getDomDocument(): \DOMDocument
{
\assert($this->domDocument instanceof \DOMDocument);

return $this->domDocument;
}

private function setDomDocument(\DOMDocument $domDocument): void
{
$this->domDocument = $domDocument;
$this->xPath = new \DOMXPath($this->domDocument);
$this->xPath = new \DOMXPath($domDocument);
}

/**
Expand Down Expand Up @@ -219,7 +217,7 @@ private function getBodyElement(): \DOMElement
}

/**
* Creates a DOM document from the given HTML and stores it in $this->domDocument.
* Creates a DOM document from the given HTML and stores it in `$this->domDocument`.
*
* The DOM document will always have a BODY element and a document type.
*/
Expand All @@ -230,7 +228,7 @@ private function createUnifiedDomDocument(string $html): void
}

/**
* Creates a DOMDocument instance from the given HTML and stores it in $this->domDocument.
* Creates a DOMDocument instance from the given HTML and stores it in `$this->domDocument`.
*/
private function createRawDomDocument(string $html): void
{
Expand Down Expand Up @@ -453,9 +451,7 @@ private function ensurePhpUnrecognizedSelfClosingTagsAreXml(string $html): strin
}

/**
* Checks that $this->domDocument has a BODY element and adds it if it is missing.
*
* @throws \UnexpectedValueException
Comment on lines -457 to -458
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getHtmlElement() currently throws this exception if there is no <html> element, which would only be the case if loadHTML() failed. But the documentation doesn't indicate under which circumstances it would fail, merely stating "malformed HTML should load successfully".

So perhaps we can assume that there will always be an <html> element, and change getHtmlElement() to assert() so as a separate PR. (Also, calling methods aren't currently declared with this @throws annotation.)

* Checks that `$this->domDocument` has a BODY element and adds it if it is missing.
*/
private function ensureExistenceOfBodyElement(): void
{
Expand Down