Skip to content

Commit

Permalink
Fix psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Mar 15, 2024
1 parent ca6bc7b commit 0a072c6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/Console/Helper/ConfiguredLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Soap\Wsdl\Loader\WsdlLoader;
use function Psl\invariant;
use function Psl\Type\instance_of;
use function Psl\Type\non_empty_string;

final class ConfiguredLoader
{
Expand All @@ -23,7 +24,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);
Expand All @@ -34,6 +36,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;
}
}
2 changes: 1 addition & 1 deletion src/Xml/Configurator/FlattenWsdlImports.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private function importWsdlImportElement(DOMElement $import): void
);

$result = $this->context->import($location);
if (!$result) {
if ($result === null || $result === '') {
remove($import);
return;
}
Expand Down
8 changes: 1 addition & 7 deletions src/Xml/Configurator/FlattenXsdImports.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion src/Xml/Validator/SchemaSyntaxValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Xml/Validator/WsdlSyntaxValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down

0 comments on commit 0a072c6

Please sign in to comment.