Skip to content

Correct PHPStan findings in validator #808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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

23 changes: 15 additions & 8 deletions src/JsonSchema/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,11 @@ class Validator extends BaseConstraint
*
* @param mixed $value
* @param mixed $schema
* @param int $checkMode
*
* @return int
*
* @phpstan-param int-mask-of<Constraint::CHECK_MODE_*> $checkMode
* @phpstan-return int-mask-of<Validator::ERROR_*>
*/
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();
Expand Down Expand Up @@ -82,19 +79,29 @@ 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<Validator::ERROR_*>
*/
public function check($value, $schema)
public function check($value, $schema): int
{
return $this->validate($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<Validator::ERROR_*>
*/
public function coerce(&$value, $schema)
public function coerce(&$value, $schema): int
{
return $this->validate($value, $schema, Constraint::CHECK_MODE_COERCE_TYPES);
}
Expand Down