使用PHP HTML Parser将HTML附加到标记

I am working on a project in which I will need to use PHP to modify the contents of any given website. To do this I am using this PHP HTML Parser.

Now, I need to be able to add a <style> tag to the end of the <head> of a document that's been loaded to $html using $html->loadFromFile($url) but I cannot seem to find an append() method in any of the classes. Is there any way for me to achieve this?

Here is my code

require("vendor/autoload.php");
use PHPHtmlParser\Dom;
$html = new Dom;

$url = https://www.example.com;
$html->loadFromFile($url);

// I need to do this:
$css = "<style>#custom{css:code;}.goes{over:here;}</style>"
$html->find("head")->append($css);

I think you can use it

$head = $html->getElementsByTagName('head');
$head->appendChild($css);