From 05ae98b21ff6ef26d5caf966a3eb45026ae1e7ca Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 18 Jan 2024 15:04:27 +0100 Subject: [PATCH] Store schema versions for which the validation failed --- src/Util/Xml/SchemaDetector.php | 6 +++++- .../Xml/SuccessfulSchemaDetectionResult.php | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Util/Xml/SchemaDetector.php b/src/Util/Xml/SchemaDetector.php index 1877a9a1f92..2975789ba18 100644 --- a/src/Util/Xml/SchemaDetector.php +++ b/src/Util/Xml/SchemaDetector.php @@ -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; diff --git a/src/Util/Xml/SuccessfulSchemaDetectionResult.php b/src/Util/Xml/SuccessfulSchemaDetectionResult.php index 77202c352be..b8bd1af72b8 100644 --- a/src/Util/Xml/SuccessfulSchemaDetectionResult.php +++ b/src/Util/Xml/SuccessfulSchemaDetectionResult.php @@ -21,12 +21,19 @@ final class SuccessfulSchemaDetectionResult extends SchemaDetectionResult */ private $version; + /** + * @psalm-var list + */ + private $tried; + /** * @psalm-param non-empty-string $version + * @psalm-param list $tried */ - public function __construct(string $version) + public function __construct(string $version, array $tried) { $this->version = $version; + $this->tried = $tried; } /** @@ -44,4 +51,12 @@ public function version(): string { return $this->version; } + + /** + * @psalm-return list + */ + public function tried(): array + { + return $this->tried; + } }