Skip to content

More-phpstan-typing #781

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 1 commit into from
Feb 10, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage
composer.lock
docs-api
phpunit.xml
.phpunit.result.cache
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Used PHPStan's int-mask-of<T> type where applicable ([#779](https://github.com/jsonrainbow/json-schema/pull/779))
- Fixed some PHPStan errors ([#781](https://github.com/jsonrainbow/json-schema/pull/781))

## [6.1.0] - 2025-02-04
### Added
Expand Down
4 changes: 1 addition & 3 deletions bin/validate-json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ if (count($arArgs) == 1) {

/**
* Show the json parse error that happened last
*
* @return void
*/
function showJsonError()
function showJsonError(): void
{
$constants = get_defined_constants(true);
$json_errors = [];
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"style-fix": "php-cs-fixer fix --verbose",
"test": "phpunit",
"testOnly": "phpunit --colors --filter",
"phpstan": "@php phpstan"
"phpstan": "@php phpstan",
"phpstan-generate-baseline": "@php phpstan --generate-baseline"
}
}
195 changes: 5 additions & 190 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:addError\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:addError\\(\\) has parameter \\$more with no value type specified in iterable type array\\.$#"
count: 1
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:addErrors\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:addErrors\\(\\) has parameter \\$errors with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -26,32 +16,7 @@ parameters:
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:getErrors\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:getErrors\\(\\) has parameter \\$errorContext with no type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:isValid\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:numErrors\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:numErrors\\(\\) has parameter \\$errorContext with no type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:reset\\(\\) has no return type specified\\.$#"
message: "#^Method JsonSchema\\\\Constraints\\\\BaseConstraint\\:\\:getErrors\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/JsonSchema/Constraints/BaseConstraint.php

Expand All @@ -65,11 +30,6 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Ternary operator condition is always true\\.$#"
count: 2
path: src/JsonSchema/Constraints/BaseConstraint.php

-
message: "#^Cannot access property \\$additionalItems on stdClass\\|null\\.$#"
count: 3
Expand All @@ -80,16 +40,6 @@ parameters:
count: 6
path: src/JsonSchema/Constraints/CollectionConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\CollectionConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/CollectionConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\CollectionConstraint\\:\\:validateItems\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/CollectionConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\CollectionConstraint\\:\\:validateItems\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -105,61 +55,11 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/CollectionConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/ConstConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkArray\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkConst\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkEnum\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkFormat\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkNumber\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkObject\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkObject\\(\\) has parameter \\$appliedDefaults with no type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkString\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkType\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkUndefined\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkUndefined\\(\\) has parameter \\$fromDefault with no type specified\\.$#"
count: 1
Expand All @@ -170,31 +70,16 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/Constraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:addError\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/ConstraintInterface.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:addError\\(\\) has parameter \\$more with no value type specified in iterable type array\\.$#"
count: 1
path: src/JsonSchema/Constraints/ConstraintInterface.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:addErrors\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/ConstraintInterface.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:addErrors\\(\\) has parameter \\$errors with no value type specified in iterable type array\\.$#"
count: 1
path: src/JsonSchema/Constraints/ConstraintInterface.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/ConstraintInterface.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\ConstraintInterface\\:\\:getErrors\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -205,49 +90,24 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/ConstraintInterface.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\EnumConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/EnumConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:addConfig\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Factory.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:createInstanceFor\\(\\) should return JsonSchema\\\\Constraints\\\\BaseConstraint&JsonSchema\\\\Constraints\\\\ConstraintInterface but returns object\\.$#"
count: 1
path: src/JsonSchema/Constraints/Factory.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getErrorContext\\(\\) should return 1\\|2 but returns int\\.$#"
count: 1
path: src/JsonSchema/Constraints/Factory.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getSchemaStorage\\(\\) has no return type specified\\.$#"
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getConfig\\(\\) should return int\\<0, 511\\> but returns int\\.$#"
count: 1
path: src/JsonSchema/Constraints/Factory.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getTypeCheck\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Factory.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:removeConfig\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/Factory.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:setConfig\\(\\) has no return type specified\\.$#"
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:getErrorContext\\(\\) should return 1\\|2 but returns int\\.$#"
count: 1
path: src/JsonSchema/Constraints/Factory.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\Factory\\:\\:setErrorContext\\(\\) has no return type specified\\.$#"
count: 1
message: "#^Property JsonSchema\\\\Constraints\\\\Factory\\:\\:\\$checkMode \\(int\\<0, 511\\>\\) does not accept int\\.$#"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a bug in phpstan.
The type should be an int-mask but it is being loosened to just int for some reason

count: 2
path: src/JsonSchema/Constraints/Factory.php

-
Expand All @@ -265,11 +125,6 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/Factory.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\FormatConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/FormatConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\FormatConstraint\\:\\:validateColor\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -335,11 +190,6 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/FormatConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\NumberConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/NumberConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\NumberConstraint\\:\\:fmod\\(\\) has no return type specified\\.$#"
count: 1
Expand All @@ -365,11 +215,6 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/ObjectConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\ObjectConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/ObjectConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\ObjectConstraint\\:\\:check\\(\\) has parameter \\$additionalProp with no type specified\\.$#"
count: 1
Expand Down Expand Up @@ -430,16 +275,6 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/ObjectConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\SchemaConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/SchemaConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\StringConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/StringConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\StringConstraint\\:\\:strlen\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -700,11 +535,6 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/TypeCheck/TypeCheckInterface.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\TypeConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/TypeConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\TypeConstraint\\:\\:implodeWith\\(\\) has parameter \\$elements with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -750,16 +580,6 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/TypeConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:applyDefaultValues\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/UndefinedConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:check\\(\\) has no return type specified\\.$#"
count: 1
path: src/JsonSchema/Constraints/UndefinedConstraint.php

-
message: "#^Method JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:check\\(\\) has parameter \\$fromDefault with no type specified\\.$#"
count: 1
Expand Down Expand Up @@ -805,11 +625,6 @@ parameters:
count: 1
path: src/JsonSchema/Constraints/UndefinedConstraint.php

-
message: "#^Parameter \\#1 \\$requiredOnly of method JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:shouldApplyDefaultValue\\(\\) expects bool, int given\\.$#"
count: 3
path: src/JsonSchema/Constraints/UndefinedConstraint.php

-
message: "#^Property JsonSchema\\\\Constraints\\\\UndefinedConstraint\\:\\:\\$appliedDefaults type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ parameters:
paths:
- ./src/
ignoreErrors: []
phpVersion: 70200

includes:
- phpstan-baseline.neon
Expand Down
Loading