Skip to content

Commit

Permalink
Store schema versions for which the validation failed
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 18, 2024
1 parent 3d0024b commit 05ae98b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Util/Xml/SchemaDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ public function detect(string $filename): SchemaDetectionResult

$schemaFinder = new SchemaFinder;

$tried = [];

foreach ($schemaFinder->available() as $candidate) {
$schema = (new SchemaFinder)->find($candidate);

if (!(new Validator)->validate($document, $schema)->hasValidationErrors()) {
return new SuccessfulSchemaDetectionResult($candidate);
return new SuccessfulSchemaDetectionResult($candidate, $tried);
}

$tried[] = $candidate;
}

return new FailedSchemaDetectionResult;
Expand Down
17 changes: 16 additions & 1 deletion src/Util/Xml/SuccessfulSchemaDetectionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ final class SuccessfulSchemaDetectionResult extends SchemaDetectionResult
*/
private $version;

/**
* @psalm-var list<non-empty-string>
*/
private $tried;

/**
* @psalm-param non-empty-string $version
* @psalm-param list<non-empty-string> $tried
*/
public function __construct(string $version)
public function __construct(string $version, array $tried)
{
$this->version = $version;
$this->tried = $tried;
}

/**
Expand All @@ -44,4 +51,12 @@ public function version(): string
{
return $this->version;
}

/**
* @psalm-return list<non-empty-string>
*/
public function tried(): array
{
return $this->tried;
}
}

0 comments on commit 05ae98b

Please sign in to comment.