Skip to content

Commit 181d647

Browse files
committed
refactor: resolve PHPStan errors
1 parent 6e3d3cc commit 181d647

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/JsonSchema/Constraints/Factory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class Factory
5050
*/
5151
protected $errorContext = Validator::ERROR_DOCUMENT_VALIDATION;
5252

53+
private $defaultDialect = 'http://json-schema.org/draft-06/schema#';
54+
5355
/**
5456
* @var array
5557
*/
@@ -215,4 +217,14 @@ public function setErrorContext(int $errorContext): void
215217
{
216218
$this->errorContext = $errorContext;
217219
}
220+
221+
public function getDefaultDialect(): string
222+
{
223+
return $this->defaultDialect;
224+
}
225+
226+
public function setDefaultDialect(string $defaultDialect): void
227+
{
228+
$this->defaultDialect = $defaultDialect;
229+
}
218230
}

src/JsonSchema/Entity/ErrorBag.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
/**
1414
* @phpstan-type Error array{
15-
* property: string,
16-
* pointer: string,
17-
* message: string,
18-
* constraint: array{name: string, params: array<string, mixed>},
15+
* "property": string,
16+
* "pointer": string,
17+
* "message": string,
18+
* "constraint": array{"name": string, "params": array<string, mixed>},
1919
* "context": int-mask-of<Validator::ERROR_*>
2020
* }
2121
* @phpstan-type ErrorList list<Error>
@@ -91,9 +91,7 @@ public function addErrors(array $errors): void
9191
$this->errors = array_merge($this->errors, $errors);
9292
$errorMask = &$this->errorMask;
9393
array_walk($errors, static function ($error) use (&$errorMask) {
94-
if (isset($error['context'])) {
95-
$errorMask |= $error['context'];
96-
}
94+
$errorMask |= $error['context'];
9795
});
9896
}
9997

src/JsonSchema/Validator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,13 @@ public function validate(&$value, $schema = null, ?int $checkMode = null): int
7979
}
8080

8181
if ($this->factory->getConfig(Constraint::CHECK_MODE_STRICT)) {
82+
$dialect = $this->factory->getDefaultDialect();
83+
if (property_exists($schema, '$schema')) {
84+
$dialect = $schema->{'$schema'};
85+
}
86+
8287
$validator = $this->factory->createInstanceFor(
83-
$this->schemaUriToConstraintName($schema->{'$schema'})
88+
$this->schemaUriToConstraintName($dialect)
8489
);
8590
}
8691

0 commit comments

Comments
 (0)