Skip to content

Commit

Permalink
WiP
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Dec 19, 2023
1 parent 99f61bf commit c640021
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 84 deletions.
20 changes: 14 additions & 6 deletions src/NodeTraits/DeprecatedMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
*/
namespace s9e\SweetDOM\NodeTraits;

use const ENT_COMPAT, ENT_XML1, E_USER_DEPRECATED;
use DOMException;
use const DOM_SYNTAX_ERR, ENT_COMPAT, ENT_XML1, E_USER_DEPRECATED;
use function array_flip, htmlspecialchars, preg_match, preg_match_all, preg_replace_callback, strtolower, trigger_error;

/**
* @method mixed polyfillMethodsCall(string $name, array $arguments)
* @method mixed magicMethodsCall(string $name, array $arguments)
*/
trait DeprecatedMethods
{
use PolyfillMethods
use MagicMethods
{
PolyfillMethods::__call as polyfillMethodsCall;
MagicMethods::__call as magicMethodsCall;
}

public function __call(string $name, array $arguments)
Expand Down Expand Up @@ -45,7 +46,7 @@ public function __call(string $name, array $arguments)

}

return $this->polyfillMethodsCall($name, $arguments);
return $this->magicMethodsCall($name, $arguments);
}

/**
Expand All @@ -58,7 +59,14 @@ public function insertAdjacentXML(string $where, string $xml): void
$fragment = $this->ownerDocument->createDocumentFragment();
$fragment->appendXML($this->addMissingNamespaceDeclarations($xml));

$this->insertAdjacentNode($where, $fragment);
match (strtolower($where))
{
'beforebegin' => $this->before($fragment),
'beforeend' => $this->appendChild($fragment),
'afterend' => $this->after($fragment),
'afterbegin' => $this->prepend($fragment),
default => throw new DOMException("'$where' is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'", DOM_SYNTAX_ERR)
};
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/NodeTraits/ParentNodePolyfill.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
namespace s9e\SweetDOM\NodeTraits;

use DOMElement;
use DOMException;
use DOMNode;
use const DOM_SYNTAX_ERR;
use function strtolower;

trait ParentNodePolyfill
Expand Down
69 changes: 0 additions & 69 deletions src/NodeTraits/PolyfillMethods.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/PatchedNodes/DocumentFragment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
namespace s9e\SweetDOM\PatchedNodes;

use s9e\SweetDOM\DocumentFragment as ParentClass;
use s9e\SweetDOM\NodeTraits\ParentNodePolyfill;
use s9e\SweetDOM\NodeTraits\ParentNodeWorkarounds;

class DocumentFragment extends ParentClass
{
use ParentNodePolyfill;
use ParentNodeWorkarounds;
}
2 changes: 2 additions & 0 deletions src/PatchedNodes/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

use s9e\SweetDOM\Element as ParentClass;
use s9e\SweetDOM\NodeTraits\ChildNodeWorkarounds;
use s9e\SweetDOM\NodeTraits\ParentNodePolyfill;
use s9e\SweetDOM\NodeTraits\ParentNodeWorkarounds;

class Element extends ParentClass
{
use ChildNodeWorkarounds;
use ParentNodePolyfill;
use ParentNodeWorkarounds;
}
10 changes: 1 addition & 9 deletions tests/ElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,17 +633,9 @@ protected function runPolyfillTest(string $expected, string $methodName, callabl
$dom = new Document;
$dom->loadXML('<p xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><span><br/></span></p>');

$dom->firstOf('//span')->__call($methodName, $argumentsCallback($dom));
$dom->firstOf('//span')->$methodName(...$argumentsCallback($dom));
$this->assertXmlStringEqualsXmlString($expected, $dom->saveXML($dom->documentElement));

if (method_exists('DOMElement', $methodName))
{
$dom = new Document;
$dom->loadXML('<p xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><span><br/></span></p>');

$dom->firstOf('//span')->$methodName(...$argumentsCallback($dom));
$this->assertXmlStringEqualsXmlString($expected, $dom->saveXML($dom->documentElement), 'Reference does not match');
}
}

#[DataProvider('getInsertAdjacentElementTests')]
Expand Down

0 comments on commit c640021

Please sign in to comment.