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 decoder #24

Merged
merged 9 commits into from
Jan 5, 2024
Merged

Refactor decoder #24

merged 9 commits into from
Jan 5, 2024

Conversation

jenky
Copy link
Collaborator

@jenky jenky commented Jan 5, 2024

Introduced iterable as the new return type for decoders to allow for more flexible data structures, moving away from strict arrays. This allows the use of generators for on-demand data processing (cerbero/lazy-json, Laravel Lazy Collection), resulting in improved performance and reduced memory consumption when parsing large response bodies.

$response->decode(): iterable is now public instead of private to return the original value of the decoder.

Furthermore, decoders can implement the MapperInterface, allowing for the transformation of response bodies into objects. This facilitates object-oriented handling of response data using Data Transfer Objects (DTOs) or Value Objects (VOs). To retrieve your object, uses $response->object().

Introduced iterable as the return type for decoders to allow for more
flexible data structures, moving away from strict arrays. This allows
the use of generators for on-demand data processing. Added a
`MapperInterface`
for transforming responses into objects, facilitating object-oriented
handling of response data. Streamlined the creation of default decoders
by defining `ChainDecoder::default` to reduce redundancy and ensure
consistency across usage. A new `GenericMapper` allows custom mapping
functions, providing clients with customizable response handling
strategies.

Additionally, `Response` now implements `JsonSerializable`, offering a
standardized way to convert response data to JSON.
Copy link

codecov bot commented Jan 5, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (992f1e7) 84.77% compared to head (ec3bde0) 85.12%.
Report is 1 commits behind head on main.

Files Patch % Lines
src/Mapper/GenericMapper.php 83.33% 2 Missing ⚠️
src/Response.php 90.90% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main      #24      +/-   ##
============================================
+ Coverage     84.77%   85.12%   +0.35%     
- Complexity      313      326      +13     
============================================
  Files            38       39       +1     
  Lines           729      753      +24     
============================================
+ Hits            618      641      +23     
- Misses          111      112       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jenky jenky merged commit a291933 into main Jan 5, 2024
9 checks passed
@jenky jenky deleted the refactor-decoder branch January 5, 2024 04:29
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.

1 participant