From 2b26e316fc265a2b7d84b29c9706ad6973811bc5 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 8 Oct 2024 11:27:29 +0200 Subject: [PATCH 1/4] refactor: add declare strict_types to all classes in ./src --- src/JsonSchema/ConstraintError.php | 2 ++ src/JsonSchema/Constraints/BaseConstraint.php | 2 ++ src/JsonSchema/Constraints/CollectionConstraint.php | 2 ++ src/JsonSchema/Constraints/ConstConstraint.php | 2 ++ src/JsonSchema/Constraints/Constraint.php | 2 ++ src/JsonSchema/Constraints/ConstraintInterface.php | 2 ++ src/JsonSchema/Constraints/EnumConstraint.php | 2 ++ src/JsonSchema/Constraints/Factory.php | 2 ++ src/JsonSchema/Constraints/FormatConstraint.php | 2 ++ src/JsonSchema/Constraints/NumberConstraint.php | 2 ++ src/JsonSchema/Constraints/ObjectConstraint.php | 2 ++ src/JsonSchema/Constraints/SchemaConstraint.php | 2 ++ src/JsonSchema/Constraints/StringConstraint.php | 2 ++ src/JsonSchema/Constraints/TypeCheck/LooseTypeCheck.php | 2 ++ src/JsonSchema/Constraints/TypeCheck/StrictTypeCheck.php | 2 ++ src/JsonSchema/Constraints/TypeCheck/TypeCheckInterface.php | 2 ++ src/JsonSchema/Constraints/TypeConstraint.php | 2 ++ src/JsonSchema/Constraints/UndefinedConstraint.php | 2 ++ src/JsonSchema/Entity/JsonPointer.php | 2 ++ src/JsonSchema/Enum.php | 2 ++ src/JsonSchema/Exception/ExceptionInterface.php | 2 ++ src/JsonSchema/Exception/InvalidArgumentException.php | 2 ++ src/JsonSchema/Exception/InvalidConfigException.php | 2 ++ src/JsonSchema/Exception/InvalidSchemaException.php | 2 ++ src/JsonSchema/Exception/InvalidSchemaMediaTypeException.php | 2 ++ src/JsonSchema/Exception/InvalidSourceUriException.php | 2 ++ src/JsonSchema/Exception/JsonDecodingException.php | 2 ++ src/JsonSchema/Exception/ResourceNotFoundException.php | 2 ++ src/JsonSchema/Exception/RuntimeException.php | 2 ++ src/JsonSchema/Exception/UnresolvableJsonPointerException.php | 2 ++ src/JsonSchema/Exception/UriResolverException.php | 2 ++ src/JsonSchema/Exception/ValidationException.php | 2 ++ src/JsonSchema/Iterator/ObjectIterator.php | 2 ++ src/JsonSchema/Rfc3339.php | 2 ++ src/JsonSchema/SchemaStorage.php | 2 ++ src/JsonSchema/SchemaStorageInterface.php | 2 ++ src/JsonSchema/Uri/Retrievers/AbstractRetriever.php | 3 +++ src/JsonSchema/Uri/Retrievers/Curl.php | 2 ++ src/JsonSchema/Uri/Retrievers/FileGetContents.php | 2 ++ src/JsonSchema/Uri/Retrievers/PredefinedArray.php | 2 ++ src/JsonSchema/Uri/Retrievers/UriRetrieverInterface.php | 2 ++ src/JsonSchema/Uri/UriResolver.php | 2 ++ src/JsonSchema/Uri/UriRetriever.php | 2 ++ src/JsonSchema/UriResolverInterface.php | 2 ++ src/JsonSchema/UriRetrieverInterface.php | 2 ++ src/JsonSchema/Validator.php | 2 ++ 46 files changed, 93 insertions(+) diff --git a/src/JsonSchema/ConstraintError.php b/src/JsonSchema/ConstraintError.php index ac7358a1..8b1c1450 100644 --- a/src/JsonSchema/ConstraintError.php +++ b/src/JsonSchema/ConstraintError.php @@ -1,5 +1,7 @@ Date: Wed, 9 Oct 2024 08:24:17 +0200 Subject: [PATCH 2/4] fix: correct regression from adding declare strict_types --- src/JsonSchema/Entity/JsonPointer.php | 2 +- tests/Constraints/FormatTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonSchema/Entity/JsonPointer.php b/src/JsonSchema/Entity/JsonPointer.php index d94d3d83..ee4a1d35 100644 --- a/src/JsonSchema/Entity/JsonPointer.php +++ b/src/JsonSchema/Entity/JsonPointer.php @@ -122,7 +122,7 @@ public function getPropertyPaths() public function withPropertyPaths(array $propertyPaths) { $new = clone $this; - $new->propertyPaths = $propertyPaths; + $new->propertyPaths = array_map(function ($p): string { return (string) $p; }, $propertyPaths); return $new; } diff --git a/tests/Constraints/FormatTest.php b/tests/Constraints/FormatTest.php index 2d91e5fe..98c0299e 100644 --- a/tests/Constraints/FormatTest.php +++ b/tests/Constraints/FormatTest.php @@ -186,7 +186,7 @@ public function getInvalidFormats(): array ['1999-01-11T00:00:00+1:00', 'date-time'], ['1999.000Z-01-11T00:00:00+1:00', 'date-time'], - [PHP_INT_MAX, 'utc-millisec'], + [(string) PHP_INT_MAX, 'utc-millisec'], ['grey', 'color'], ['#HHH', 'color'], From d9538d2403cf6c7e9b5057352dbf26f10d7a0892 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Mon, 28 Oct 2024 20:51:51 +0100 Subject: [PATCH 3/4] refactor: enforce string at datetime casting --- src/JsonSchema/Constraints/FormatConstraint.php | 2 +- tests/Constraints/FormatTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonSchema/Constraints/FormatConstraint.php b/src/JsonSchema/Constraints/FormatConstraint.php index 39c3eb8f..482ba668 100644 --- a/src/JsonSchema/Constraints/FormatConstraint.php +++ b/src/JsonSchema/Constraints/FormatConstraint.php @@ -176,7 +176,7 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i = protected function validateDateTime($datetime, $format) { - $dt = \DateTime::createFromFormat($format, $datetime); + $dt = \DateTime::createFromFormat($format, (string) $datetime); if (!$dt) { return false; diff --git a/tests/Constraints/FormatTest.php b/tests/Constraints/FormatTest.php index 98c0299e..2d91e5fe 100644 --- a/tests/Constraints/FormatTest.php +++ b/tests/Constraints/FormatTest.php @@ -186,7 +186,7 @@ public function getInvalidFormats(): array ['1999-01-11T00:00:00+1:00', 'date-time'], ['1999.000Z-01-11T00:00:00+1:00', 'date-time'], - [(string) PHP_INT_MAX, 'utc-millisec'], + [PHP_INT_MAX, 'utc-millisec'], ['grey', 'color'], ['#HHH', 'color'], From ce0b1d27274284d1ad5a8741b528b9bb9d46595c Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Thu, 21 Nov 2024 22:06:22 +0100 Subject: [PATCH 4/4] docs: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99726be8..7f7db619 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add ext-json to composer.json to ensure JSON extension available ([#759](https://github.com/jsonrainbow/json-schema/pull/759)) - Add visibility modifiers to class constants ([#757](https://github.com/jsonrainbow/json-schema/pull/757)) - Include PHP 8.4 in workflow ([#765](https://github.com/jsonrainbow/json-schema/pull/765)) +- Add `strict_types=1` to all classes in ./src ([#758](https://github.com/jsonrainbow/json-schema/pull/758)) ## [6.0.0] - 2024-07-30 ### Added