Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new psalm reports + test compatibility #73

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
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