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 missing methods from serializer interface #192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michaelcozzolino
Copy link

@michaelcozzolino michaelcozzolino commented Oct 15, 2023

This PR adds methods available in the symfony serializer to the SerializerInterface such as denormalize and supportsDenormalization and similar

Summary by CodeRabbit

  • New Features

    • Enhanced the serialization functionality with new methods for denormalization, encoding, and decoding.
    • Introduced support checking methods for normalization, denormalization, encoding, and decoding.
  • Improvements

    • Updated the normalize method to specify return type hints and handle additional return types for better flexibility and error handling.

@michaelcozzolino michaelcozzolino marked this pull request as ready for review October 15, 2023 15:15
@michaelcozzolino
Copy link
Author

@lotyp please review

@lotyp
Copy link
Member

lotyp commented Jun 18, 2024

@coderabbitai review

Copy link

coderabbitai bot commented Jun 18, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Jun 18, 2024

Walkthrough

Recent updates have enhanced the SerializerInterface by introducing additional methods for normalization and encoding, accompanied by more specific return type hints. Changes to the Serializer.php and SerializerManager.php files include method signature updates and removal of an exception declaration. These changes ensure a more robust and versatile serialization process.

Changes

File Change Summary
src/Contracts/SerializerInterface.php Added methods such as normalize, denormalize, supportsNormalization, supportsDenormalization, encode, decode, supportsEncoding, and supportsDecoding. Updated return type hints for normalize method.
src/Serializer.php Removed @throws ExceptionInterface from normalize method and the use statement for ExceptionInterface.
src/SerializerManager.php Added use ArrayObject;. Expanded normalize method return types and introduced new methods: denormalize, supportsNormalization, supportsDenormalization, encode, decode, supportsEncoding, and supportsDecoding.

Poem

In code we trust, with changes bright
Serialization now takes flight.
Normalize, denormalize — our new delight,
Encoding, decoding in purest light. ✨
With each method, enhancements rise,
Agile, robust, and ever-wise.
Cheers to progress, with coderabbit eyes! 🐇💻


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ba830d8 and d0ca33b.

Files selected for processing (3)
  • src/Contracts/SerializerInterface.php (1 hunks)
  • src/Serializer.php (2 hunks)
  • src/SerializerManager.php (2 hunks)
Files skipped from review due to trivial changes (1)
  • src/Serializer.php
Additional comments not posted (4)
src/Contracts/SerializerInterface.php (2)

17-26: The normalize method now includes a detailed return type and a throws declaration. Ensure that all implementations of this interface handle the potential exceptions as documented.


28-28: The addition of denormalize, supportsNormalization, supportsDenormalization, encode, decode, supportsEncoding, and supportsDecoding methods are well-defined and adhere to the interface segregation principle, ensuring that the interface remains specific to client's needs.

Also applies to: 32-32, 34-34, 36-36, 38-38, 40-40

src/SerializerManager.php (2)

7-7: The use of ArrayObject and Stringable is appropriate here given the context and usage in method signatures.


37-37: The implementation of the new methods (denormalize, supportsNormalization, supportsDenormalization, encode, decode, supportsEncoding, supportsDecoding) in SerializerManager properly delegates functionality to the serializer retrieved based on the format. This promotes single responsibility and adheres to the open/closed principle. However, ensure that all possible exceptions are handled or documented.

Also applies to: 42-47, 49-54, 56-61, 63-68, 70-75, 77-82, 84-88

Comment on lines +7 to +9
use ArrayObject;
use Stringable;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
Copy link

Choose a reason for hiding this comment

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

Consider removing the unused import Symfony\Component\Serializer\Exception\ExceptionInterface if it is not required in this file.

@lotyp
Copy link
Member

lotyp commented Jun 18, 2024

Hi @michaelcozzolino, 👋

Thank you for your contribution and sorry for the delay in reviewing it. 🙏

I noticed you had an issue with missing methods in the Manager class.

For the 1.x version, you can access the original Symfony Serializer through Laravel's container like this:

$serializer = $app->make(\Symfony\Component\Serializer\SerializerInterface);

You can find more details in the code here:
SerializerServiceProvider.php#L146

I am currently doing a big refactor for the 2.x version, which you can follow in this PR:
#199

In version 2.x, I have added two new Facades:

These Facades let you access the Manager and the already configured original Serializer.

I will check your changes and see how the Manager class can be improved and if it needs the additional methods. In version 2.x, normalization is done automatically by calling the serialize() method, so no more manual normalization calls are needed.

For more details on this change, see:
ResponseFactory.php#L72

You can also find the test here:
ResponseFactoryTest.php#L92

Thanks again for your contribution!

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.

None yet

2 participants