diff --git a/CHANGELOG.md b/CHANGELOG.md index a6e05a9b..90ded89e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Added extra breaking change to UPDATE-6.0.md regarding BaseConstraint::addError signature change ([#823](https://github.com/jsonrainbow/json-schema/pull/823) +- Update constraint class to PHP 7.2 language level ([#824](https://github.com/jsonrainbow/json-schema/pull/824) + ## [6.4.1] - 2025-04-04 ### Fixed diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7e4ba4a4..42bea6be 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -40,21 +40,6 @@ parameters: count: 1 path: src/JsonSchema/Constraints/CollectionConstraint.php - - - message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkObject\\(\\) has parameter \\$appliedDefaults with no type specified\\.$#" - count: 1 - path: src/JsonSchema/Constraints/Constraint.php - - - - message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkUndefined\\(\\) has parameter \\$fromDefault with no type specified\\.$#" - count: 1 - path: src/JsonSchema/Constraints/Constraint.php - - - - message: "#^Property JsonSchema\\\\Constraints\\\\Constraint\\:\\:\\$inlineSchemaProperty has no type specified\\.$#" - count: 1 - path: src/JsonSchema/Constraints/Constraint.php - - message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:addError\\(\\) has parameter \\$more with no value type specified in iterable type array\\.$#" count: 1 @@ -205,11 +190,6 @@ parameters: count: 1 path: src/JsonSchema/Constraints/ObjectConstraint.php - - - message: "#^Method JsonSchema\\\\Constraints\\\\ObjectConstraint\\:\\:check\\(\\) has parameter \\$appliedDefaults with no type specified\\.$#" - count: 1 - path: src/JsonSchema/Constraints/ObjectConstraint.php - - message: "#^Method JsonSchema\\\\Constraints\\\\ObjectConstraint\\:\\:check\\(\\) has parameter \\$patternProperties with no type specified\\.$#" count: 1 @@ -255,11 +235,6 @@ parameters: count: 1 path: src/JsonSchema/Constraints/ObjectConstraint.php - - - message: "#^Property JsonSchema\\\\Constraints\\\\ObjectConstraint\\:\\:\\$appliedDefaults type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/JsonSchema/Constraints/ObjectConstraint.php - - message: "#^Method JsonSchema\\\\Constraints\\\\StringConstraint\\:\\:strlen\\(\\) has no return type specified\\.$#" count: 1 @@ -565,11 +540,6 @@ parameters: count: 1 path: src/JsonSchema/Constraints/TypeConstraint.php - - - message: "#^Method JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:check\\(\\) has parameter \\$fromDefault with no type specified\\.$#" - count: 1 - path: src/JsonSchema/Constraints/UndefinedConstraint.php - - message: "#^Method JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:shouldApplyDefaultValue\\(\\) has parameter \\$name with no type specified\\.$#" count: 1 @@ -610,21 +580,11 @@ parameters: count: 1 path: src/JsonSchema/Constraints/UndefinedConstraint.php - - - message: "#^Property JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:\\$appliedDefaults type has no value type specified in iterable type array\\.$#" - count: 1 - path: src/JsonSchema/Constraints/UndefinedConstraint.php - - message: "#^Method JsonSchema\\\\Entity\\\\JsonPointer\\:\\:encodePropertyPaths\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: src/JsonSchema/Entity/JsonPointer.php - - - message: "#^Method JsonSchema\\\\Entity\\\\JsonPointer\\:\\:setFromDefault\\(\\) has no return type specified\\.$#" - count: 1 - path: src/JsonSchema/Entity/JsonPointer.php - - message: "#^Method JsonSchema\\\\Entity\\\\JsonPointer\\:\\:withPropertyPaths\\(\\) has parameter \\$propertyPaths with no value type specified in iterable type array\\.$#" count: 1 diff --git a/src/JsonSchema/Constraints/Constraint.php b/src/JsonSchema/Constraints/Constraint.php index 49cec0a3..8e818f0a 100644 --- a/src/JsonSchema/Constraints/Constraint.php +++ b/src/JsonSchema/Constraints/Constraint.php @@ -2,25 +2,13 @@ declare(strict_types=1); -/* - * This file is part of the JsonSchema package. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace JsonSchema\Constraints; use JsonSchema\Entity\JsonPointer; -/** - * The Base Constraints, all Validators should extend this class - * - * @author Robert Schönthal - * @author Bruno Prieto Reis - */ abstract class Constraint extends BaseConstraint implements ConstraintInterface { + /** @var string */ protected $inlineSchemaProperty = '$schema'; public const CHECK_MODE_NONE = 0x00000000; @@ -48,14 +36,12 @@ protected function incrementPath(?JsonPointer $path, $i): JsonPointer return $path; } - $path = $path->withPropertyPaths( + return $path->withPropertyPaths( array_merge( $path->getPropertyPaths(), [$i] ) ); - - return $path; } /** @@ -76,15 +62,22 @@ protected function checkArray(&$value, $schema = null, ?JsonPointer $path = null /** * Validates an object * - * @param mixed $value - * @param mixed $schema - * @param mixed $properties - * @param mixed $additionalProperties - * @param mixed $patternProperties + * @param mixed $value + * @param mixed $schema + * @param mixed $properties + * @param mixed $additionalProperties + * @param mixed $patternProperties + * @param array $appliedDefaults */ - protected function checkObject(&$value, $schema = null, ?JsonPointer $path = null, $properties = null, - $additionalProperties = null, $patternProperties = null, $appliedDefaults = []): void - { + protected function checkObject( + &$value, + $schema = null, + ?JsonPointer $path = null, + $properties = null, + $additionalProperties = null, + $patternProperties = null, + array $appliedDefaults = [] + ): void { /** @var ObjectConstraint $validator */ $validator = $this->factory->createInstanceFor('object'); $validator->check($value, $schema, $path, $properties, $additionalProperties, $patternProperties, $appliedDefaults); @@ -93,7 +86,7 @@ protected function checkObject(&$value, $schema = null, ?JsonPointer $path = nul } /** - * Validates the type of a property + * Validates the type of the value * * @param mixed $value * @param mixed $schema @@ -114,7 +107,7 @@ protected function checkType(&$value, $schema = null, ?JsonPointer $path = null, * @param mixed $schema * @param mixed $i */ - protected function checkUndefined(&$value, $schema = null, ?JsonPointer $path = null, $i = null, $fromDefault = false): void + protected function checkUndefined(&$value, $schema = null, ?JsonPointer $path = null, $i = null, bool $fromDefault = false): void { /** @var UndefinedConstraint $validator */ $validator = $this->factory->createInstanceFor('undefined'); diff --git a/src/JsonSchema/Constraints/ObjectConstraint.php b/src/JsonSchema/Constraints/ObjectConstraint.php index e55d7656..c2c614a9 100644 --- a/src/JsonSchema/Constraints/ObjectConstraint.php +++ b/src/JsonSchema/Constraints/ObjectConstraint.php @@ -2,37 +2,32 @@ declare(strict_types=1); -/* - * This file is part of the JsonSchema package. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace JsonSchema\Constraints; use JsonSchema\ConstraintError; use JsonSchema\Entity\JsonPointer; -/** - * The ObjectConstraint Constraints, validates an object against a given schema - * - * @author Robert Schönthal - * @author Bruno Prieto Reis - */ class ObjectConstraint extends Constraint { /** - * @var array List of properties to which a default value has been applied + * @var list List of properties to which a default value has been applied */ protected $appliedDefaults = []; /** * {@inheritdoc} + * + * @param list $appliedDefaults */ - public function check(&$element, $schema = null, ?JsonPointer $path = null, $properties = null, - $additionalProp = null, $patternProperties = null, $appliedDefaults = []): void - { + public function check( + &$element, + $schema = null, + ?JsonPointer $path = null, + $properties = null, + $additionalProp = null, + $patternProperties = null, + $appliedDefaults = [] + ): void { if ($element instanceof UndefinedConstraint) { return; } diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index b9e00121..1ea0a7bc 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -2,13 +2,6 @@ declare(strict_types=1); -/* - * This file is part of the JsonSchema package. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace JsonSchema\Constraints; use JsonSchema\ConstraintError; @@ -18,24 +11,18 @@ use JsonSchema\Tool\DeepCopy; use JsonSchema\Uri\UriResolver; -/** - * The UndefinedConstraint Constraints - * - * @author Robert Schönthal - * @author Bruno Prieto Reis - */ #[\AllowDynamicProperties] class UndefinedConstraint extends Constraint { /** - * @var array List of properties to which a default value has been applied + * @var list List of properties to which a default value has been applied */ protected $appliedDefaults = []; /** * {@inheritdoc} - */ - public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null, $fromDefault = false): void + * */ + public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = null, bool $fromDefault = false): void { if (is_null($schema) || !is_object($schema)) { return; @@ -72,9 +59,10 @@ public function validateTypes(&$value, $schema, JsonPointer $path, $i = null) } // check object - if (LooseTypeCheck::isObject($value)) { // object processing should always be run on assoc arrays, - // so use LooseTypeCheck here even if CHECK_MODE_TYPE_CAST - // is not set (i.e. don't use $this->getTypeCheck() here). + if (LooseTypeCheck::isObject($value)) { + // object processing should always be run on assoc arrays, + // so use LooseTypeCheck here even if CHECK_MODE_TYPE_CAST + // is not set (i.e. don't use $this->getTypeCheck() here). $this->checkObject( $value, $schema, diff --git a/src/JsonSchema/Entity/JsonPointer.php b/src/JsonSchema/Entity/JsonPointer.php index ee4a1d35..e674fa6f 100644 --- a/src/JsonSchema/Entity/JsonPointer.php +++ b/src/JsonSchema/Entity/JsonPointer.php @@ -146,7 +146,7 @@ public function __toString() /** * Mark the value at this path as being set from a schema default */ - public function setFromDefault() + public function setFromDefault(): void { $this->fromDefault = true; }