From 791de98f0f8ff12d91d13e2633e619d45552217b Mon Sep 17 00:00:00 2001 From: Jack Worman <66142217+jack-worman@users.noreply.github.com> Date: Tue, 4 Feb 2025 15:00:57 -0500 Subject: [PATCH 1/2] Better phpstan typing --- phpstan-baseline.neon | 4 ++-- src/JsonSchema/Constraints/BaseConstraint.php | 2 ++ src/JsonSchema/Validator.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c6277a6d..dd1172e3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -451,7 +451,7 @@ parameters: path: src/JsonSchema/Constraints/StringConstraint.php - - message: "#^Parameter \\#2 \\$encoding of function mb_strlen expects string, string\\|false given\\.$#" + message: "#^Parameter \\#2 \\$encoding of function mb_strlen expects string\\|null, string\\|false given\\.$#" count: 1 path: src/JsonSchema/Constraints/StringConstraint.php @@ -971,7 +971,7 @@ parameters: path: src/JsonSchema/Uri/Retrievers/FileGetContents.php - - message: "#^Parameter \\#1 \\$callback of function set_error_handler expects \\(callable\\(int, string, string, int, array\\)\\: bool\\)\\|null, Closure\\(mixed, mixed\\)\\: void given\\.$#" + message: "#^Parameter \\#1 \\$callback of function set_error_handler expects \\(callable\\(int, string, string, int\\)\\: bool\\)\\|null, Closure\\(mixed, mixed\\)\\: void given\\.$#" count: 1 path: src/JsonSchema/Uri/Retrievers/FileGetContents.php diff --git a/src/JsonSchema/Constraints/BaseConstraint.php b/src/JsonSchema/Constraints/BaseConstraint.php index a4b4c9a2..0b661e0f 100644 --- a/src/JsonSchema/Constraints/BaseConstraint.php +++ b/src/JsonSchema/Constraints/BaseConstraint.php @@ -30,6 +30,7 @@ class BaseConstraint /** * @var int All error types which have occurred + * @phpstan-var int-mask-of */ protected $errorMask = Validator::ERROR_NONE; @@ -129,6 +130,7 @@ public function reset() * Get the error mask * * @return int + * @phpstan-return int-mask-of */ public function getErrorMask() { diff --git a/src/JsonSchema/Validator.php b/src/JsonSchema/Validator.php index 86440949..a02c2e5d 100644 --- a/src/JsonSchema/Validator.php +++ b/src/JsonSchema/Validator.php @@ -44,7 +44,8 @@ class Validator extends BaseConstraint * * @return int * - * @phpstan-param Constraint::CHECK_MODE_* $checkMode + * @phpstan-param int-mask-of $checkMode + * @phpstan-return int-mask-of */ public function validate(&$value, $schema = null, $checkMode = null) { From 229c5843d760c5a6abb44344597a5e0b03556acd Mon Sep 17 00:00:00 2001 From: Jack Worman Date: Wed, 5 Feb 2025 16:41:43 -0500 Subject: [PATCH 2/2] Better phpstan typing --- CHANGELOG.md | 4 +++- phpstan-baseline.neon | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed5c87ba..e91d27af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Used PHPStan's int-mask-of type where applicable ([#779](https://github.com/jsonrainbow/json-schema/pull/779)) ## [6.1.0] - 2025-02-04 ### Added @@ -91,4 +93,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix: Clean up `.gitattributes` ([#687](https://github.com/jsonrainbow/json-schema/pull/687)) - Fix: Order `friendsofphp/php-cs-fixer` rules ([#688](https://github.com/jsonrainbow/json-schema/pull/688)) - HTTP to HTTPS redirection breaks remote reference resolution ([#709](https://github.com/jsonrainbow/json-schema/pull/709)) -- Corrected several typos and code style issues \ No newline at end of file +- Corrected several typos and code style issues diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index dd1172e3..c6277a6d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -451,7 +451,7 @@ parameters: path: src/JsonSchema/Constraints/StringConstraint.php - - message: "#^Parameter \\#2 \\$encoding of function mb_strlen expects string\\|null, string\\|false given\\.$#" + message: "#^Parameter \\#2 \\$encoding of function mb_strlen expects string, string\\|false given\\.$#" count: 1 path: src/JsonSchema/Constraints/StringConstraint.php @@ -971,7 +971,7 @@ parameters: path: src/JsonSchema/Uri/Retrievers/FileGetContents.php - - message: "#^Parameter \\#1 \\$callback of function set_error_handler expects \\(callable\\(int, string, string, int\\)\\: bool\\)\\|null, Closure\\(mixed, mixed\\)\\: void given\\.$#" + message: "#^Parameter \\#1 \\$callback of function set_error_handler expects \\(callable\\(int, string, string, int, array\\)\\: bool\\)\\|null, Closure\\(mixed, mixed\\)\\: void given\\.$#" count: 1 path: src/JsonSchema/Uri/Retrievers/FileGetContents.php