Skip to content
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

More-phpstan-typing #781

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

jack-worman
Copy link
Contributor

Just some more low hanging phpstan error fixes

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

Copy link
Collaborator

@DannyvdSluijs DannyvdSluijs left a comment

Choose a reason for hiding this comment

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

Thanks on these type of contributions. I'm unclear if there is a specific reason for adding the types as DocBlock version instead of native ones. The master branch supports PHP 7.2 and up, so we can use most of the native typehints. We only can't use typed properties, mixed return type, union types or Enums.

Would you be okay with improving the PR to use more of the native type hints instead of adding their respective. DocBlock versions. Obvious the @phpstan-param can remain to reduce the type further.

@@ -89,6 +92,12 @@ public function addErrors(array $errors)
}
}

/**
* @param int $errorContext
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer the native type hint over a docblock

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added native typehints for some the stuff i already touched (and a bit more)

@jack-worman
Copy link
Contributor Author

Adding native typehints would be a BC break for people extending the class. Is this okay?

@DannyvdSluijs
Copy link
Collaborator

Adding native typehints would be a BC break for people extending the class. Is this okay?

I don't think this is a big problem. We are just strengthening the code base as we are making more explicit what the return types are.

@DannyvdSluijs
Copy link
Collaborator

Thanks for all the additions. This is a great step forward into type completion for JSON Schema and bringing it back into modern PHP standards.

@DannyvdSluijs DannyvdSluijs merged commit afee666 into jsonrainbow:master Feb 10, 2025
14 checks passed
@jack-worman jack-worman deleted the More-phpstan-typing branch February 10, 2025 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants