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

refactor: remove redundant $toClass from MicroMapper, allowing improvement of generic templating #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bendavies
Copy link
Contributor

@bendavies bendavies commented Oct 20, 2023

Follows #4

This PR removes the $toClass paramters from MicroMapper::load(), allowing for better generics templating. no stable release yet so I hope this is acceptable!

Here is a full example with no \assert(...) or @var required on the params of MicroMapper::load() and MicroMapper::populate():
https://phpstan.org/r/bae2f18f-8eb5-4377-827a-0814b86bc383
thanks to @ondrejmirtes for the help!

@bendavies bendavies marked this pull request as ready for review October 20, 2023 08:52
@bendavies bendavies force-pushed the generics-further-fixing branch 3 times, most recently from 6ee4ee8 to 083ed66 Compare October 20, 2023 09:02
Copy link

@stof stof left a comment

Choose a reason for hiding this comment

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

As is, the analysis of the project won't be valid.
The only reason it passes is because the CI runs phpstan at level 4, which disables many rules. Try analysing this code at level 6 at least (or even at level 8 if possible). This will show you that it will likely require more changes (in the MapperConfig class for instance) to properly support those generics.

* @param TTo $to
* @param TFrom $from
* @param TTo $to
* @param array<mixed> $context
Copy link

Choose a reason for hiding this comment

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

should this be array<string, mixed> ? I think the context is expected to be an associative array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@bocharsky-bw
Copy link
Member

@bendavies are you going to continue working on this PR? I updated this branch with latest changes from main branch and fix merge complicts here

@bendavies
Copy link
Contributor Author

@bocharsky-bw thanks for the nudge.
is there anything to do apart from fixing @stof 's comment?

@bendavies
Copy link
Contributor Author

ok, bumping phpstan up from level 4 to at least 6 looks important.

Copy link
Member

@bocharsky-bw bocharsky-bw left a comment

Choose a reason for hiding this comment

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

Changes look good to me here.

But it might be so that tests pass because I temporarily skipped out the related test, see #12 (comment)

If you could take a look at that failed test and make it working - would be awesome. I'm not sure how to get that done yet

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.

3 participants