Skip to content

Feat/named arguments#66

Merged
kjdev merged 2 commits into
masterfrom
feat/named-arguments
May 13, 2025
Merged

Feat/named arguments#66
kjdev merged 2 commits into
masterfrom
feat/named-arguments

Conversation

@kjdev

@kjdev kjdev commented May 13, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added support for named arguments in Brotli compression and decompression functions for PHP 8.0 and above.
  • Tests
    • Introduced new tests to verify Brotli functions with named arguments, including both standard and incremental compression/decompression scenarios.
  • Refactor
    • Enhanced argument and return type information for Brotli functions on PHP 8.0+, improving type safety and compatibility with reflection tools.

@coderabbitai

coderabbitai Bot commented May 13, 2025

Copy link
Copy Markdown

Walkthrough

This update introduces PHP 8.0+ conditional arginfo with precise return and argument types for all Brotli extension functions and methods, enhancing type safety and reflection metadata. Additionally, two new test scripts are added to verify the correct behavior of Brotli functions when using named arguments, including incremental compression and decompression scenarios.

Changes

File(s) Change Summary
brotli.c Updated arginfo declarations for all Brotli functions and methods to use conditional compilation for PHP 8.0+, specifying precise return types and argument type hints. Legacy arginfo retained for older PHP versions.
tests/named_args.phpt Added new test to verify Brotli compression and decompression functions with named arguments, including error handling and round-trip validation.
tests/named_args_incremental.phpt Added new test for incremental Brotli compression and decompression using named arguments, including validation for argument errors and correct output.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BrotliExtension

    User->>BrotliExtension: brotli_compress(data: string, level?: int, mode?: int)
    BrotliExtension-->>User: string|false

    User->>BrotliExtension: brotli_uncompress(data: string, length?: int)
    BrotliExtension-->>User: string|false

    User->>BrotliExtension: brotli_compress_init(level?: int, mode?: int)
    BrotliExtension-->>User: BrotliCompressContext|false

    User->>BrotliExtension: brotli_compress_add(ctx: BrotliCompressContext, data: string, mode?: int)
    BrotliExtension-->>User: string|false

    User->>BrotliExtension: brotli_uncompress_init()
    BrotliExtension-->>User: BrotliUncompressContext|false

    User->>BrotliExtension: brotli_uncompress_add(ctx: BrotliUncompressContext, data: string)
    BrotliExtension-->>User: string|false
Loading

Possibly related PRs

  • kjdev/php-ext-brotli#58: Updates context handles from resources to PHP objects and modifies function signatures, directly relating to the arginfo and type declaration changes in this PR.

Poem

In the warren of code, a bunny hops fast,
With arginfo precise, and type safety cast.
Named arguments tested, old and new,
Compression and decompression, all passing through.
PHP 8 shines bright, as rabbits delight—
Hooray for Brotli, and code that’s just right! 🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54c7328 and 2d4c1ee.

📒 Files selected for processing (3)
  • brotli.c (1 hunks)
  • tests/named_args.phpt (1 hunks)
  • tests/named_args_incremental.phpt (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
brotli.c (1)
brotli.stub.php (2)
  • Context (91-93)
  • Context (99-101)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: ci (8.0-alpine, ghcr.io/kjdev/php, linux/amd64)
  • GitHub Check: ci (8.2-alpine, php, linux/amd64)
  • GitHub Check: ci (8.2-alpine, apcu, php, linux/amd64)
  • GitHub Check: ci (8.2-alpine, system, apcu, php, linux/amd64)
  • GitHub Check: ci (8.1, x86, nts, vs16, true)
  • GitHub Check: ci (8.1, x86, ts, vs16, true)
  • GitHub Check: ci (8.1, x64, ts, vs16, true)
  • GitHub Check: ci (8.1, x64, nts, vs16, false)
  • GitHub Check: ci (8.1, x64, ts, vs16, false)
  • GitHub Check: ci (8.2, x86, ts, vs16, false)
  • GitHub Check: ci (8.3, x86, nts, vs16, true)
  • GitHub Check: ci (8.1, x64, nts, vs16, true)
  • GitHub Check: ci (8.2, x64, nts, vs16, true)
  • GitHub Check: ci (8.2, x64, ts, vs16, false)
  • GitHub Check: ci (8.3, x86, ts, vs16, true)
  • GitHub Check: ci (8.2, x86, nts, vs16, true)
  • GitHub Check: ci (8.2, x64, nts, vs16, false)
  • GitHub Check: ci (8.3, x64, ts, vs16, true)
🔇 Additional comments (14)
brotli.c (6)

35-45: Well-structured conditional arginfo for brotli_compress function

The implementation now provides proper type hints for PHP 8.0+, including return type mask and parameter types with default values. This enables named arguments support while maintaining backward compatibility with older PHP versions.


48-57: Well-defined arginfo for brotli_uncompress function

Good implementation of PHP 8.0+ type information for the uncompress function, correctly specifying that it returns either a string or false, and properly typing the parameters.


59-68: Proper object return type for brotli_compress_init

The function now correctly specifies that it returns a Brotli\Compress\Context object or false for PHP 8.0+, with appropriate default values for optional parameters.


70-81: Improved type safety for brotli_compress_add

The implementation now properly types the context parameter as an object of Brotli\Compress\Context class and specifies proper return types and default values.


83-88: Enhanced type information for brotli_uncompress_init

The function now correctly specifies that it returns a Brotli\UnCompress\Context object or false for PHP 8.0+.


90-101: Complete type information for brotli_uncompress_add

The implementation now properly types the context parameter as an object of Brotli\UnCompress\Context class with appropriate string|false return type and default values for PHP 8.0+.

tests/named_args.phpt (4)

1-9: Good test setup with proper PHP version check

The test file correctly checks for PHP 8.0+ since named arguments were introduced in that version, and includes the necessary test data.


11-64: Comprehensive testing of brotli_compress with named arguments

The test thoroughly covers various combinations of named arguments for brotli_compress, including error cases when required arguments are missing and validation that compression/decompression cycle preserves data integrity.


66-96: Comprehensive testing of brotli_uncompress with named arguments

The test cases appropriately verify different combinations of named arguments for brotli_uncompress, checking error conditions and verifying data integrity after compression and decompression.


97-127: Well-structured expected output section

The expected output correctly matches the test cases, showing appropriate error messages when arguments are missing and confirming successful operations with the correct return types.

tests/named_args_incremental.phpt (4)

1-10: Good test setup for incremental compression

The test file correctly checks for PHP 8.0+ compatibility and includes the necessary test data for incremental compression and decompression with named arguments.


11-70: Well-structured test function for incremental operations

The test function comprehensively tests incremental compression and decompression with named arguments, including different modes and verifying data integrity at each step.


72-78: Thorough testing with various compression levels and modes

The test appropriately verifies behavior with valid and invalid compression levels and modes, ensuring the extension correctly validates these parameters.


80-127: Comprehensive expected output section

The expected output correctly includes success messages for valid operations and appropriate warnings for invalid parameters, ensuring proper error handling is tested.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

@kjdev

kjdev commented May 13, 2025

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 13, 2025

Copy link
Copy Markdown
✅ 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.

@kjdev kjdev merged commit 2d4c1ee into master May 13, 2025
@kjdev kjdev deleted the feat/named-arguments branch May 13, 2025 02:33
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