Skip to content

Commit fbf0156

Browse files
committed
refactor: simplify schema id value fetching
1 parent c1ced78 commit fbf0156

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/JsonSchema/Constraints/TypeCheck/LooseTypeCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function propertyExists($value, $property)
4444
return property_exists($value, $property);
4545
}
4646

47-
return array_key_exists($property, $value);
47+
return is_array($value) && array_key_exists($property, $value);
4848
}
4949

5050
public static function propertyCount($value)

src/JsonSchema/Validator.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use JsonSchema\Constraints\BaseConstraint;
1515
use JsonSchema\Constraints\Constraint;
16+
use JsonSchema\Constraints\TypeCheck\LooseTypeCheck;
1617

1718
/**
1819
* A JsonSchema Constraint
@@ -59,12 +60,9 @@ public function validate(&$value, $schema = null, $checkMode = null)
5960
}
6061

6162
// add provided schema to SchemaStorage with internal URI to allow internal $ref resolution
62-
if (is_object($schema) && property_exists($schema, 'id')) {
63-
$schemaURI = $schema->id;
64-
} elseif (is_array($schema) && array_key_exists('id', $schema)) {
65-
$schemaURI = $schema['id'];
66-
} else {
67-
$schemaURI = SchemaStorage::INTERNAL_PROVIDED_SCHEMA_URI;
63+
$schemaURI = SchemaStorage::INTERNAL_PROVIDED_SCHEMA_URI;
64+
if (LooseTypeCheck::propertyExists($schema, 'id')) {
65+
$schemaURI = LooseTypeCheck::propertyGet($schema, 'id');
6866
}
6967
$this->factory->getSchemaStorage()->addSchema($schemaURI, $schema);
7068

0 commit comments

Comments
 (0)