Skip to content

Commit

Permalink
Merge pull request #73 from veewee/psalm-fixes
Browse files Browse the repository at this point in the history
Fix new psalm reports + test compatibility
  • Loading branch information
veewee authored Feb 21, 2024
2 parents 7cb255b + df41fd5 commit 47504ae
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 17 deletions.
7 changes: 2 additions & 5 deletions src/Xml/Dom/Builder/cdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

use Closure;
use DOMCdataSection;
use DOMDocument;
use DOMNode;
use Webmozart\Assert\Assert;
use function VeeWee\Xml\Dom\Assert\assert_cdata;
use function VeeWee\Xml\Dom\Predicate\is_document;
use function VeeWee\Xml\Dom\Locator\Node\detect_document;
use function VeeWee\Xml\Internal\configure;

/**
Expand All @@ -21,8 +19,7 @@
function cdata(string $data, ...$configurators): Closure
{
return static function (DOMNode $node) use ($data, $configurators): DOMCdataSection {
$document = is_document($node) ? $node : $node->ownerDocument;
Assert::isInstanceOf($document, DOMDocument::class, 'Can not create cdata without a DOM document.');
$document = detect_document($node);

return assert_cdata(
configure(...$configurators)($document->createCDATASection($data))
Expand Down
7 changes: 2 additions & 5 deletions src/Xml/Dom/Builder/element.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
namespace VeeWee\Xml\Dom\Builder;

use Closure;
use DOMDocument;
use DOMElement;
use DOMNode;
use Webmozart\Assert\Assert;
use function VeeWee\Xml\Dom\Assert\assert_element;
use function VeeWee\Xml\Dom\Predicate\is_document;
use function VeeWee\Xml\Dom\Locator\Node\detect_document;
use function VeeWee\Xml\Internal\configure;

/**
Expand All @@ -21,8 +19,7 @@
function element(string $name, callable ...$configurators): Closure
{
return static function (DOMNode $node) use ($name, $configurators): DOMElement {
$document = is_document($node) ? $node : $node->ownerDocument;
Assert::isInstanceOf($document, DOMDocument::class, 'Can not create an element without a DOM document.');
$document = detect_document($node);

return assert_element(
configure(...$configurators)($document->createElement($name))
Expand Down
7 changes: 2 additions & 5 deletions src/Xml/Dom/Builder/namespaced_element.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
namespace VeeWee\Xml\Dom\Builder;

use Closure;
use DOMDocument;
use DOMElement;
use DOMNode;
use Webmozart\Assert\Assert;
use function VeeWee\Xml\Dom\Assert\assert_element;
use function VeeWee\Xml\Dom\Predicate\is_document;
use function VeeWee\Xml\Dom\Locator\Node\detect_document;
use function VeeWee\Xml\Internal\configure;

/**
Expand All @@ -21,8 +19,7 @@
function namespaced_element(string $namespace, string $qualifiedName, callable ...$configurators): Closure
{
return static function (DOMNode $node) use ($namespace, $qualifiedName, $configurators): DOMElement {
$document = is_document($node) ? $node : $node->ownerDocument;
Assert::isInstanceOf($document, DOMDocument::class, 'Can not create an element without a DOM document.');
$document = detect_document($node);

return assert_element(
configure(...$configurators)($document->createElementNS($namespace, $qualifiedName))
Expand Down
1 change: 1 addition & 0 deletions src/Xml/Dom/Locator/Node/detect_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

/**
* @throws InvalidArgumentException
* @psalm-suppress RedundantCondition - node->ownerDocument can also be null...
*/
function detect_document(DOMNode $node): DOMDocument
{
Expand Down
2 changes: 1 addition & 1 deletion src/Xml/Dom/Manipulator/Element/rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
function rename(DOMElement $target, string $newQName, ?string $newNamespaceURI = null): DOMElement
{
$isRootElement = $target->ownerDocument && $target === $target->ownerDocument->documentElement;
$isRootElement = $target === $target->ownerDocument->documentElement;
$parent = $isRootElement ? $target->ownerDocument : parent_element($target);
$namespace = $newNamespaceURI ?? $target->namespaceURI;
$builder = $namespace !== null
Expand Down
2 changes: 1 addition & 1 deletion tests/Xml/Xslt/Configurator/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ functions(['substr'])
);

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Not allowed to call handler \'strtoupper()\'');
$this->expectExceptionMessage('strtoupper');
$processor->transformDocumentToString($doc);
}

Expand Down

0 comments on commit 47504ae

Please sign in to comment.