From 2d4ad1026d4ab1a1e2aa0b44ed904a9f8edf8340 Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Fri, 15 Mar 2024 13:55:26 +0100 Subject: [PATCH] Fix psalm issues --- src/Console/Helper/ConfiguredLoader.php | 5 +++-- src/Xml/Configurator/FlattenWsdlImports.php | 2 +- src/Xml/Configurator/FlattenXsdImports.php | 8 +------- src/Xml/Validator/SchemaSyntaxValidator.php | 5 ++++- src/Xml/Validator/WsdlSyntaxValidator.php | 5 ++++- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Console/Helper/ConfiguredLoader.php b/src/Console/Helper/ConfiguredLoader.php index c50f558..882b8e6 100644 --- a/src/Console/Helper/ConfiguredLoader.php +++ b/src/Console/Helper/ConfiguredLoader.php @@ -23,7 +23,8 @@ public static function createFromConfig(?string $file, callable $configurator = { $loader = new StreamWrapperLoader(); - if ($file) { + if ($file !== null) { + invariant($file !== '', 'File must not be empty.'); invariant(Filesystem\exists($file), 'File "%s" does not exist.', $file); invariant(Filesystem\is_file($file), 'File "%s" is not a file.', $file); invariant(Filesystem\is_readable($file), 'File "%s" is not readable.', $file); @@ -34,6 +35,6 @@ public static function createFromConfig(?string $file, callable $configurator = $loader = instance_of(WsdlLoader::class)->assert($included); } - return $configurator ? $configurator($loader) : $loader; + return $configurator !== null ? $configurator($loader) : $loader; } } diff --git a/src/Xml/Configurator/FlattenWsdlImports.php b/src/Xml/Configurator/FlattenWsdlImports.php index e7733b6..69a0b13 100644 --- a/src/Xml/Configurator/FlattenWsdlImports.php +++ b/src/Xml/Configurator/FlattenWsdlImports.php @@ -60,7 +60,7 @@ private function importWsdlImportElement(DOMElement $import): void ); $result = $this->context->import($location); - if (!$result) { + if ($result === null || $result === '') { remove($import); return; } diff --git a/src/Xml/Configurator/FlattenXsdImports.php b/src/Xml/Configurator/FlattenXsdImports.php index d76757f..af52a5d 100644 --- a/src/Xml/Configurator/FlattenXsdImports.php +++ b/src/Xml/Configurator/FlattenXsdImports.php @@ -119,12 +119,6 @@ private function importSchema(DOMElement $import): ?DOMElement return null; } - // Normally an import has an owner document, since it is coming from xpath on an existing document - // However, static analysis does not know about this. - if (!$import->ownerDocument) { - return null; - } - // Find the schema that wants to import the new schema: $doc = Document::fromUnsafeDocument($import->ownerDocument); $xpath = $doc->xpath(new WsdlPreset($doc)); @@ -158,7 +152,7 @@ private function loadSchema(string $location): ?DOMElement $path = IncludePathBuilder::build($location, $this->currentLocation); $result = $this->context->import($path); - if (!$result) { + if ($result === null || $result === '') { return null; } diff --git a/src/Xml/Validator/SchemaSyntaxValidator.php b/src/Xml/Validator/SchemaSyntaxValidator.php index b3f971b..7b8e92b 100644 --- a/src/Xml/Validator/SchemaSyntaxValidator.php +++ b/src/Xml/Validator/SchemaSyntaxValidator.php @@ -17,9 +17,12 @@ final class SchemaSyntaxValidator implements Validator { private string $xsd; + /** + * @param non-empty-string|null $xsd + */ public function __construct(?string $xsd = null) { - $this->xsd = $xsd ?: dirname(__DIR__, 3).'/xsd/XMLSchema.xsd'; + $this->xsd = $xsd ?? dirname(__DIR__, 3).'/xsd/XMLSchema.xsd'; } /** diff --git a/src/Xml/Validator/WsdlSyntaxValidator.php b/src/Xml/Validator/WsdlSyntaxValidator.php index 72297fc..4e17df8 100644 --- a/src/Xml/Validator/WsdlSyntaxValidator.php +++ b/src/Xml/Validator/WsdlSyntaxValidator.php @@ -15,9 +15,12 @@ final class WsdlSyntaxValidator implements Validator { private string $xsd; + /** + * @param non-empty-string|null $xsd + */ public function __construct(?string $xsd = null) { - $this->xsd = $xsd ?: dirname(__DIR__, 3).'/xsd/wsdl.xsd'; + $this->xsd = $xsd ?? dirname(__DIR__, 3).'/xsd/wsdl.xsd'; } /**