Skip to content

Commit

Permalink
Merge branch '10.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 18, 2024
2 parents 546cd50 + cb04e88 commit d257301
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Expand Up @@ -18,6 +18,9 @@
*/
abstract readonly class SchemaDetectionResult
{
/**
* @psalm-assert-if-true SuccessfulSchemaDetectionResult $this
*/
public function detected(): bool
{
return false;
Expand Down
Expand Up @@ -26,12 +26,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
Expand Up @@ -16,20 +16,47 @@
*/
final readonly class SuccessfulSchemaDetectionResult extends SchemaDetectionResult
{
/**
* @psalm-var non-empty-string
*/
private string $version;

public function __construct(string $version)
/**
* @psalm-var list<non-empty-string>
*/
private array $tried;

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

/**
* @psalm-assert-if-true SuccessfulSchemaDetectionResult $this
*/
public function detected(): bool
{
return true;
}

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

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

0 comments on commit d257301

Please sign in to comment.