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

Preserve the pagination data in the result set #43

Closed
wants to merge 3 commits into from

Conversation

davidyell
Copy link
Collaborator

Resolves #42

When reading apis which are paginated, it's helpful to have a recursive function. However it needs an exit condition, so preserving the pagination data it returns allows for this by keeping the pagination data with the result set.

@ADmad
Copy link
Member

ADmad commented Aug 15, 2017

Looks okay (besides coding standards errors), I'll just consult someone to ensure this is the right way.

@codecov
Copy link

codecov bot commented Aug 15, 2017

Codecov Report

Merging #43 into master will increase coverage by 1.43%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #43      +/-   ##
============================================
+ Coverage     71.57%   73.01%   +1.43%     
- Complexity      352      360       +8     
============================================
  Files            13       13              
  Lines           876      893      +17     
============================================
+ Hits            627      652      +25     
+ Misses          249      241       -8
Impacted Files Coverage Δ Complexity Δ
src/ResultSet.php 100% <100%> (ø) 13 <2> (+1) ⬆️
src/Model/Schema.php 66.66% <0%> (-8.34%) 2% <0%> (ø)
src/Model/Endpoint.php 71.96% <0%> (-0.19%) 133% <0%> (+4%)
src/Model/Resource.php 100% <0%> (ø) 8% <0%> (ø) ⬇️
src/Query.php 100% <0%> (ø) 49% <0%> (ø) ⬇️
src/Model/ResourceBasedEntityTrait.php 0% <0%> (ø) 2% <0%> (ø) ⬇️
src/Routing/Filter/ControllerEndpointFilter.php 0% <0%> (ø) 3% <0%> (ø) ⬇️
src/Webservice/Webservice.php 96.84% <0%> (+0.13%) 34% <0%> (ø) ⬇️
src/Connection.php 94.11% <0%> (+0.36%) 7% <0%> (ø) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b0bfe90...db914e8. Read the comment docs.

ADmad
ADmad previously requested changes Aug 15, 2017
* @param array $pagination Array of pagination data
* @param int|null $total The total amount of resources available
* @param array $total Array of pagination data
* @param null $pagination The total amount of resources available
Copy link
Member

Choose a reason for hiding this comment

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

You have mixed up the two params.

@ADmad ADmad dismissed their stale review August 15, 2017 20:49

docblock is fixed

@ADmad
Copy link
Member

ADmad commented Aug 15, 2017

So adding paging data to result is fine but I would prefer some changes:

  • Rather than adding a new argument lets just change the second param to $pagingParams since total too is a paging param. For BC add check if $pagingParams is not array then do $pagingParams = ['total' => $pagingParams].
  • Rename pagination() to getPagingParams() for consistency with core's Paginator::getPagingParams().
  • Accept only normalized keys for paging params since the purpose of the plugin providing a consistent representation of web services. Allowed keys can be subset of these

@davidyell
Copy link
Collaborator Author

davidyell commented Aug 15, 2017

I have problems with these requested changes.

  1. My pagination is custom, therefore only accepting certain keys will not work for me. Which is exactly why I assigned an array. Assuming only cake pagination style will be returned from any api endpoint seems naive. Having userland code translate the api response to cake language seems like extra effort for both the user to implement and the plugin to document.

  2. Mixed mode methods are evil. This isn't something which needs to happen at all. Just having a straight method with a nullable param will both preserve BC and make the method obvious, easier to read and also understand. Without the need for a mixed type param.

  3. Although prefixing with a get might be consistent with the core, it's not consistent with the rest of the plugin. If there is a drive to prefix the plugins methods with get and set prefixes, then this should be done outside the scope of this pull request and within the same scope of pushing the plugins minimum cake version to 3.4

@ADmad
Copy link
Member

ADmad commented Aug 16, 2017

My pagination is custom, therefore only accepting certain keys will not work for me. Which is exactly why I assigned an array. Assuming only cake pagination style will be returned from any api endpoint seems naive. Having userland code translate the api response to cake language seems like extra effort for both the user to implement and the plugin to document.

Pagination is a pretty standard thing. Each provider may give that information in a different way using different names but at the end it's the same. For e.g. every key shown under pagination in #42 maps to corresponding key used by core's paginator.

The whole point of this plugin is to provided a consistent representation of different webservices/APIs. That will involve some overheard. If you don't like that than perhaps this is not the right tool for you.

Mixed mode methods are evil. This isn't something which needs to happen at all. Just having a straight method with a nullable param will both preserve BC and make the method obvious, easier to read and also understand. Without the need for a mixed type param.

Yes allowing different types for an argument is not ideal but this is just temporary to maintain BC. In next major release it would only take an array. This is still better than adding an unnecessary extra argument when total itself is a paging param.

Although prefixing with a get might be consistent with the core, it's not consistent with the rest of the plugin. If there is a drive to prefix the plugins methods with get and set prefixes, then this should be done outside the scope of this pull request and within the same scope of pushing the plugins minimum cake version to 3.4

Knowingly using names for new methods which could change in future is silly. I doubt currently anyone is willing to spend the time updating all methods. So let's just use proper name for new method to be added.

@davidyell
Copy link
Collaborator Author

davidyell commented Aug 16, 2017

If the pagination is standard like this, then we should consider using a value object, which implements an interface and typehint against that in the method. This way developers can assign their own values to that object, and the interface will ensure consistency.

Using a value object would also solve the params problem and avoid the mixed method requirement. As well as making any transition to PHP 7.0 much easier.

I value consistency above all else. The api of this plugin is already a mess, as detailed in #40 and #36. Using methods which match the way the plugin currently works means that it will be easier to guess the method.

I'd be happy to go through and update all the method names if it's required.

All in all this discussion is making me think it's worth implementing and releasing a new major version with these changes.

@davidyell
Copy link
Collaborator Author

If you won't like that than perhaps this is not the right tool for you.

You might be right, perhaps it's worth me maintaining my own fork.

@davidyell davidyell closed this Aug 16, 2017
@davidyell
Copy link
Collaborator Author

I'll have to revisit this, as the plugin does need some pagination support.

@davidyell davidyell mentioned this pull request Feb 20, 2018
23 tasks
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