From 92a5a26a502a10c218fd715f10c9bdfb46b98adb Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 18 Mar 2025 20:17:50 +0100 Subject: [PATCH 1/3] refactor: resolve phpstan findings from baseline --- src/JsonSchema/Validator.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/JsonSchema/Validator.php b/src/JsonSchema/Validator.php index bf172640..1049a77b 100644 --- a/src/JsonSchema/Validator.php +++ b/src/JsonSchema/Validator.php @@ -41,14 +41,11 @@ class Validator extends BaseConstraint * * @param mixed $value * @param mixed $schema - * @param int $checkMode - * - * @return int * * @phpstan-param int-mask-of $checkMode * @phpstan-return int-mask-of */ - public function validate(&$value, $schema = null, $checkMode = null) + public function validate(&$value, $schema = null, int $checkMode = null): int { // reset errors prior to validation $this->reset(); @@ -82,9 +79,14 @@ public function validate(&$value, $schema = null, $checkMode = null) /** * Alias to validate(), to maintain backwards-compatibility with the previous API * - * @deprecated + * @deprecated since 6.0.0, use Validator::validate() instead, to be removed in 7.0 + * + * @param mixed $value + * @param mixed $schema + * + * @phpstan-return int-mask-of */ - public function check($value, $schema) + public function check($value, $schema): int { return $this->validate($value, $schema); } @@ -92,9 +94,14 @@ public function check($value, $schema) /** * Alias to validate(), to maintain backwards-compatibility with the previous API * - * @deprecated + * @deprecated since 6.0.0, use Validator::validate() instead, to be removed in 7.0 + * + * @param mixed $value + * @param mixed $schema + * + * @phpstan-return int-mask-of */ - public function coerce(&$value, $schema) + public function coerce(&$value, $schema): int { return $this->validate($value, $schema, Constraint::CHECK_MODE_COERCE_TYPES); } From e8124cdcdd3d4219f14ee6ced12daafecba73a48 Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 18 Mar 2025 20:18:16 +0100 Subject: [PATCH 2/3] refactor: remove resolved findings from baseline --- phpstan-baseline.neon | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index aaa7831a..d708b079 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -900,33 +900,3 @@ parameters: count: 1 path: src/JsonSchema/Uri/UriRetriever.php - - - message: "#^Method JsonSchema\\\\Validator\\:\\:check\\(\\) has no return type specified\\.$#" - count: 1 - path: src/JsonSchema/Validator.php - - - - message: "#^Method JsonSchema\\\\Validator\\:\\:check\\(\\) has parameter \\$schema with no type specified\\.$#" - count: 1 - path: src/JsonSchema/Validator.php - - - - message: "#^Method JsonSchema\\\\Validator\\:\\:check\\(\\) has parameter \\$value with no type specified\\.$#" - count: 1 - path: src/JsonSchema/Validator.php - - - - message: "#^Method JsonSchema\\\\Validator\\:\\:coerce\\(\\) has no return type specified\\.$#" - count: 1 - path: src/JsonSchema/Validator.php - - - - message: "#^Method JsonSchema\\\\Validator\\:\\:coerce\\(\\) has parameter \\$schema with no type specified\\.$#" - count: 1 - path: src/JsonSchema/Validator.php - - - - message: "#^Method JsonSchema\\\\Validator\\:\\:coerce\\(\\) has parameter \\$value with no type specified\\.$#" - count: 1 - path: src/JsonSchema/Validator.php - From b57d80457764e2c13b3994c7b3b05c7f6ddd8eda Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 25 Mar 2025 13:45:00 +0100 Subject: [PATCH 3/3] fix: correct implicit nullable --- src/JsonSchema/Validator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JsonSchema/Validator.php b/src/JsonSchema/Validator.php index 1049a77b..d8c83876 100644 --- a/src/JsonSchema/Validator.php +++ b/src/JsonSchema/Validator.php @@ -45,7 +45,7 @@ class Validator extends BaseConstraint * @phpstan-param int-mask-of $checkMode * @phpstan-return int-mask-of */ - public function validate(&$value, $schema = null, int $checkMode = null): int + public function validate(&$value, $schema = null, ?int $checkMode = null): int { // reset errors prior to validation $this->reset();