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

Add psalm specific generic return type for deserialize #1091

Merged
merged 1 commit into from Jun 3, 2019

Conversation

Projects
None yet
2 participants
@bdsl
Copy link
Contributor

commented Jun 3, 2019

See https://psalm.dev/ and
https://medium.com/vimeo-engineering-blog/uncovering-php-bugs-with-template-a4ca46eb9aeb

Q A
Bug fix? no
New feature? yes
Doc updated no
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #...
License MIT
@bdsl

This comment has been minimized.

Copy link
Contributor Author

commented Jun 3, 2019

These annotations tell the Psalm static analyser that the object returned by deserialize will be an instance of the class named in the $type parameter. Psalm can use that to find errors, e.g. calling a function that doesn't exist in that class, and also to provide autocompletion suggestions.

@bdsl bdsl force-pushed the bdsl:templated-return branch from 14b8fd2 to e9e8fa2 Jun 3, 2019

@goetas

This comment has been minimized.

Copy link
Collaborator

commented Jun 3, 2019

Im fine with this, but is there a way to test it?

@bdsl

This comment has been minimized.

Copy link
Contributor Author

commented Jun 3, 2019

@goetas Probably if you want to have this work reliably you'd need need to add psalm to the build pipeline for serializer, firstly to check that it doesn't error when parsing this docblock, and then also to make sure that it infers the type correctly when a caller uses this method.

For now you can see how this allows psalm to detect a spelling mistake when calling a function on the DTO at https://psalm.dev/r/1f725d788b

@goetas goetas merged commit 48be7ea into schmittjoh:master Jun 3, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@goetas

This comment has been minimized.

Copy link
Collaborator

commented Jun 3, 2019

thanks

@bdsl

This comment has been minimized.

Copy link
Contributor Author

commented Jun 3, 2019

You're welcome, thanks for the quick response. Do you have any plan for when this would be in a release? I don't know if there are any set release dates or roadmaps for this project.

@bdsl bdsl deleted the bdsl:templated-return branch Jun 3, 2019

@goetas

This comment has been minimized.

Copy link
Collaborator

commented Jun 3, 2019

this project does not have "time scheduled" releases. Generally when I have some time I create a changelog and do the release.

@bdsl

This comment has been minimized.

Copy link
Contributor Author

commented Jun 3, 2019

Thanks @goetas . Let me know if you and other maintainers would like a PR to add psalm to the travis build. Psalm has a baselining feature so any issues it finds in when first set up don't have to be immediately fixed.

@goetas

This comment has been minimized.

Copy link
Collaborator

commented Jun 4, 2019

Having some basic Psalm integration into the serializer would be very nice. I guess is not any easy task, but would be happy to see a PR with that

@bdsl bdsl referenced this pull request Jun 4, 2019

Closed

Add Psalm to pipeline #1092

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.