Skip to content

Commit 5023f95

Browse files
committed
fix: resolve phpstan errors
1 parent 181d647 commit 5023f95

File tree

6 files changed

+20
-8
lines changed

6 files changed

+20
-8
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ parameters:
641641
path: src/JsonSchema/SchemaStorage.php
642642

643643
-
644-
message: "#^Call to function is_array\\(\\) with object will always evaluate to false\\.$#"
644+
message: "#^Call to function is_array\\(\\) with bool|object will always evaluate to false\\.$#"
645645
count: 1
646646
path: src/JsonSchema/SchemaStorage.php
647647

src/JsonSchema/Constraints/Factory.php

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

53+
/** @var string */
5354
private $defaultDialect = 'http://json-schema.org/draft-06/schema#';
5455

5556
/**

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,19 @@ protected function applyDefaultValues(&$value, $schema, $path): void
239239
return;
240240
}
241241

242+
if (is_bool($schema)) {
243+
return;
244+
}
245+
242246
// apply defaults if appropriate
243247
$requiredOnly = (bool) $this->factory->getConfig(self::CHECK_MODE_ONLY_REQUIRED_DEFAULTS);
244248
if (isset($schema->properties) && LooseTypeCheck::isObject($value)) {
245249
// $value is an object or assoc array, and properties are defined - treat as an object
246250
foreach ($schema->properties as $currentProperty => $propertyDefinition) {
247251
$propertyDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($propertyDefinition);
252+
if (is_bool($propertyDefinition)) {
253+
continue;
254+
}
248255
if (
249256
!LooseTypeCheck::propertyExists($value, $currentProperty)
250257
&& property_exists($propertyDefinition, 'default')
@@ -269,6 +276,10 @@ protected function applyDefaultValues(&$value, $schema, $path): void
269276
// $value is an array, and items are defined - treat as plain array
270277
foreach ($items as $currentItem => $itemDefinition) {
271278
$itemDefinition = $this->factory->getSchemaStorage()->resolveRefSchema($itemDefinition);
279+
if (is_bool($itemDefinition)) {
280+
continue;
281+
}
282+
272283
if (
273284
!array_key_exists($currentItem, $value)
274285
&& property_exists($itemDefinition, 'default')

src/JsonSchema/Entity/ErrorBag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ public function addError(ConstraintError $constraint, ?JsonPointer $path = null,
7676
if ($this->factory->getConfig(Constraint::CHECK_MODE_EXCEPTIONS)) {
7777
throw new ValidationException(sprintf('Error validating %s: %s', $error['pointer'], $error['message']));
7878
}
79-
8079
$this->errors[] = $error;
81-
$this->errorMask |= $error['context'];
80+
/** @see https://github.com/phpstan/phpstan/issues/9384 */
81+
$this->errorMask |= $error['context']; // @phpstan-ignore assign.propertyType
8282
}
8383

8484
/** @param ErrorList $errors */

src/JsonSchema/SchemaStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function resolveRefSchema($refSchema, $resolveStack = [])
182182
}
183183

184184
if (is_object($refSchema) && array_keys(get_object_vars($refSchema)) === ['']) {
185-
$refSchema = $refSchema->{''};
185+
$refSchema = get_object_vars($refSchema)[''];
186186
}
187187

188188
return $refSchema;

src/JsonSchema/SchemaStorageInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ interface SchemaStorageInterface
99
/**
1010
* Adds schema with given identifier
1111
*
12-
* @param object $schema
12+
* @param object|bool $schema
1313
*/
1414
public function addSchema(string $id, $schema = null): void;
1515

1616
/**
1717
* Returns schema for given identifier, or null if it does not exist
1818
*
19-
* @return object
19+
* @return object|bool
2020
*/
2121
public function getSchema(string $id);
2222

2323
/**
2424
* Returns schema for given reference with all sub-references resolved
2525
*
26-
* @return object
26+
* @return object|bool
2727
*/
2828
public function resolveRef(string $ref);
2929

@@ -32,7 +32,7 @@ public function resolveRef(string $ref);
3232
*
3333
* @param mixed $refSchema
3434
*
35-
* @return object
35+
* @return object|bool
3636
*/
3737
public function resolveRefSchema($refSchema);
3838
}

0 commit comments

Comments
 (0)