Skip to content

Commit

Permalink
Merge pull request #69 from veewee/psalm-520
Browse files Browse the repository at this point in the history
Fix psalm 5.20
  • Loading branch information
veewee committed Jan 19, 2024
2 parents 90affd5 + ba9b82e commit 6fae11b
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Xml/Dom/Manipulator/Attribute/rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function rename(DOMAttr $target, string $newQName, ?string $newNamespaceURI = nu
$namespace = $newNamespaceURI ?? $target->namespaceURI;
$value = $target->nodeValue ?? '';

$builder = $namespace
$builder = $namespace !== null
? namespaced_attribute($namespace, $newQName, $value)
: attribute($newQName, $value);

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 @@ -26,7 +26,7 @@ function rename(DOMElement $target, string $newQName, ?string $newNamespaceURI =
$isRootElement = $target->ownerDocument && $target === $target->ownerDocument->documentElement;
$parent = $isRootElement ? $target->ownerDocument : parent_element($target);
$namespace = $newNamespaceURI ?? $target->namespaceURI;
$builder = $namespace
$builder = $namespace !== null
? namespaced_element($namespace, $newQName)
: element($newQName);

Expand Down
3 changes: 2 additions & 1 deletion src/Xml/Dom/Manipulator/Xmlns/rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
function rename(DOMDocument $document, string $namespaceURI, string $newPrefix): void
{
// Check for prefix collisions
if (($existingUri = $document->lookupNamespaceURI($newPrefix)) && $existingUri !== $namespaceURI) {
$existingUri = $document->lookupNamespaceURI($newPrefix);
if ($existingUri !== null && $existingUri !== $namespaceURI) {
throw RuntimeException::withMessage(
sprintf(
'Cannot rename the namespace uri %s because the prefix %s is already linked to uri %s',
Expand Down
2 changes: 1 addition & 1 deletion src/Xml/Dom/Traverser/Visitor/RemoveNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function onNodeLeave(DOMNode $node): Action
}

$namespaces = xmlns_attributes_list($node);
if ($this->filter) {
if ($this->filter !== null) {
$namespaces = $namespaces->filter($this->filter);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Xml/Encoding/Internal/Encoder/Builder/element.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function element(string $name, array $data): Closure

/** @var list<Closure(DOMElement): DOMElement> $children */
$children = filter_nulls([
$attributes ? attributes($attributes) : null,
$attributes !== null ? attributes($attributes) : null,
$namedNamespaces ? xmlns_attributes($namedNamespaces) : null,
$cdata !== null ? childrenBuilder(cdata($cdata)) : null,
$value !== null ? escaped_value($value) : null,
Expand All @@ -66,7 +66,7 @@ function element(string $name, array $data): Closure
)),
]);

return $currentNamespace
return $currentNamespace !== null
? namespacedElementBuilder($currentNamespace, $name, ...$children)
: elementBuilder($name, ...$children);
}
4 changes: 2 additions & 2 deletions src/Xml/Reader/Matcher/nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function nested(callable ... $matchers): Closure
return static function (NodeSequence $sequence) use ($matchers) : bool {
$lastMatchedAtIndex = -1;
$currentMatcher = array_shift($matchers);
if (!$currentMatcher) {
if ($currentMatcher === null) {
return false;
}

Expand All @@ -51,7 +51,7 @@ function nested(callable ... $matchers): Closure
// If the list of matchers is empty
// The function will return true if the element is the last step in the complete sequence.
// Otherwise, the nested match has an even deeper element on which we don't wish to match.
if (!$currentMatcher) {
if ($currentMatcher === null) {
$isLastStep = $index === $stepCount - 1;

return $isLastStep;
Expand Down
2 changes: 2 additions & 0 deletions src/Xml/Reader/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ static function () use ($reader): array {

$pointer->enterElement($element);
$outerXml = $matcher($pointer->getNodeSequence()) ? $reader->readOuterXml() : null;

/** @psalm-suppress RiskyTruthyFalsyComparison */
$match = $outerXml ? new MatchingNode($outerXml, $pointer->getNodeSequence()) : null;

if ($isEmptyElement) {
Expand Down
3 changes: 2 additions & 1 deletion src/Xml/Writer/Builder/namespace_attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use XMLWriter;

/**
* @param non-empty-string|null $prefix
* @return Closure(XMLWriter): Generator<bool>
*/
function namespace_attribute(string $namespace, ?string $prefix = null): Closure
Expand All @@ -18,7 +19,7 @@ function namespace_attribute(string $namespace, ?string $prefix = null): Closure
* @return Generator<bool>
*/
static function (XMLWriter $writer) use ($namespace, $prefix): Generator {
if ($prefix) {
if ($prefix !== null) {
yield from prefixed_attribute('xmlns', $prefix, $namespace)($writer);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function overwrite_with_local_files(array $map): Closure
new SchemaCollection(
...$schemas->map(
static function (Schema $schema) use ($map): Schema {
/** @psalm-suppress RiskyTruthyFalsyComparison */
if (!$namespace = $schema->namespace()) {
return $schema;
}
Expand Down

0 comments on commit 6fae11b

Please sign in to comment.