Skip to content

Commit 60b095b

Browse files
Correct PHPStan findings in validator (#808)
This pull request includes several changes to the `JsonSchema` library, focusing on adding type hints and improving code documentation. The most important changes include removing certain entries from `phpstan-baseline.neon`, adding type hints to methods in `Validator.php`, and updating deprecation notices. Improvements to type hints and code documentation: * [`src/JsonSchema/Validator.php`](diffhunk://#diff-41de454e04e08a0284513e682c94d3f01f9c4a2a6b2faa51b5868bdd0826e42eL44-R48): Added type hints to the `validate`, `check`, and `coerce` methods, specifying the return type as `int` and including detailed parameter documentation. [[1]](diffhunk://#diff-41de454e04e08a0284513e682c94d3f01f9c4a2a6b2faa51b5868bdd0826e42eL44-R48) [[2]](diffhunk://#diff-41de454e04e08a0284513e682c94d3f01f9c4a2a6b2faa51b5868bdd0826e42eL85-R104) Updates to `phpstan-baseline.neon`: * [`phpstan-baseline.neon`](diffhunk://#diff-995edee38ad4f8387e58ebd52c31bcc04c56cc2448d331b1cf5e0b35c57b9efaL903-L932): Removed multiple entries related to the `JsonSchema\Validator` class, which were previously indicating missing type hints. These entries are no longer needed due to the added type hints in the code.
1 parent f769861 commit 60b095b

File tree

2 files changed

+15
-38
lines changed

2 files changed

+15
-38
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -900,33 +900,3 @@ parameters:
900900
count: 1
901901
path: src/JsonSchema/Uri/UriRetriever.php
902902

903-
-
904-
message: "#^Method JsonSchema\\\\Validator\\:\\:check\\(\\) has no return type specified\\.$#"
905-
count: 1
906-
path: src/JsonSchema/Validator.php
907-
908-
-
909-
message: "#^Method JsonSchema\\\\Validator\\:\\:check\\(\\) has parameter \\$schema with no type specified\\.$#"
910-
count: 1
911-
path: src/JsonSchema/Validator.php
912-
913-
-
914-
message: "#^Method JsonSchema\\\\Validator\\:\\:check\\(\\) has parameter \\$value with no type specified\\.$#"
915-
count: 1
916-
path: src/JsonSchema/Validator.php
917-
918-
-
919-
message: "#^Method JsonSchema\\\\Validator\\:\\:coerce\\(\\) has no return type specified\\.$#"
920-
count: 1
921-
path: src/JsonSchema/Validator.php
922-
923-
-
924-
message: "#^Method JsonSchema\\\\Validator\\:\\:coerce\\(\\) has parameter \\$schema with no type specified\\.$#"
925-
count: 1
926-
path: src/JsonSchema/Validator.php
927-
928-
-
929-
message: "#^Method JsonSchema\\\\Validator\\:\\:coerce\\(\\) has parameter \\$value with no type specified\\.$#"
930-
count: 1
931-
path: src/JsonSchema/Validator.php
932-

src/JsonSchema/Validator.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,11 @@ class Validator extends BaseConstraint
4141
*
4242
* @param mixed $value
4343
* @param mixed $schema
44-
* @param int $checkMode
45-
*
46-
* @return int
4744
*
4845
* @phpstan-param int-mask-of<Constraint::CHECK_MODE_*> $checkMode
4946
* @phpstan-return int-mask-of<Validator::ERROR_*>
5047
*/
51-
public function validate(&$value, $schema = null, $checkMode = null)
48+
public function validate(&$value, $schema = null, ?int $checkMode = null): int
5249
{
5350
// reset errors prior to validation
5451
$this->reset();
@@ -82,19 +79,29 @@ public function validate(&$value, $schema = null, $checkMode = null)
8279
/**
8380
* Alias to validate(), to maintain backwards-compatibility with the previous API
8481
*
85-
* @deprecated
82+
* @deprecated since 6.0.0, use Validator::validate() instead, to be removed in 7.0
83+
*
84+
* @param mixed $value
85+
* @param mixed $schema
86+
*
87+
* @phpstan-return int-mask-of<Validator::ERROR_*>
8688
*/
87-
public function check($value, $schema)
89+
public function check($value, $schema): int
8890
{
8991
return $this->validate($value, $schema);
9092
}
9193

9294
/**
9395
* Alias to validate(), to maintain backwards-compatibility with the previous API
9496
*
95-
* @deprecated
97+
* @deprecated since 6.0.0, use Validator::validate() instead, to be removed in 7.0
98+
*
99+
* @param mixed $value
100+
* @param mixed $schema
101+
*
102+
* @phpstan-return int-mask-of<Validator::ERROR_*>
96103
*/
97-
public function coerce(&$value, $schema)
104+
public function coerce(&$value, $schema): int
98105
{
99106
return $this->validate($value, $schema, Constraint::CHECK_MODE_COERCE_TYPES);
100107
}

0 commit comments

Comments
 (0)