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

Update metafiles and code style #36

Merged
merged 4 commits into from
Jan 9, 2025
Merged

Update metafiles and code style #36

merged 4 commits into from
Jan 9, 2025

Conversation

roxblnfk
Copy link
Member

@roxblnfk roxblnfk commented Jan 9, 2025

  • applied Spiral CS
  • added CS fix in CI
  • updated metafiles

Summary by CodeRabbit

Release Notes

  • Code Style

    • Introduced new code style configuration and automated fixes.
    • Updated PHP code style and static analysis tools.
  • Development Dependencies

    • Added new development dependencies for code style and debugging.
  • Configuration Updates

    • Updated various configuration files for PHPUnit, Psalm, and Git.
    • Refined project-wide development workflow.
  • Minor Refactoring

    • Simplified several class constructors and method signatures.
    • Removed deprecated error message constants.
    • Updated method formatting across multiple files.
  • Testing

    • Minor adjustments to test methods and interfaces.

Copy link

coderabbitai bot commented Jan 9, 2025

Warning

Rate limit exceeded

@roxblnfk has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between a367a4c and 3e4512d.

📒 Files selected for processing (1)
  • phpunit.xml (1 hunks)

Walkthrough

This pull request introduces comprehensive configuration and code style updates across the project. The changes span multiple files, focusing on improving code consistency, updating development dependencies, and refining workflow configurations. Key modifications include adding code style fixer configurations, updating GitHub Actions workflows, adjusting Git-related files like .gitignore and .gitattributes, and making minor formatting changes in source and test files. The updates aim to standardize code style and improve development processes.

Changes

File Change Summary
.gitattributes Added global text attribute, export-ignore rules for various file types
.github/workflows/cs-fix.yml New workflow for automated code style fixes
.gitignore Updated ignored/tracked files and directories
.php-cs-fixer.dist.php New PHP code style configuration file
composer.json Added development dependencies, modified scripts
phpunit.xml Updated schema location, added result cache file
psalm-baseline.xml Added XML declaration and Psalm version
psalm.xml Added error baseline attribute
src/* Minor formatting and method signature changes
tests/* Code formatting and minor test adjustments

Possibly related PRs

Suggested reviewers

  • butschster
  • msmakouz

Poem

🐰 Coding rabbits hop with glee,
Fixing styles so clean and free,
Commas dance, braces align,
Our code now sparkles, line by line!
Git attributes sing their sweet song 🎵


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>, please review it.
    • 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 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 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 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. (Beta)
  • @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.

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: 2

🧹 Nitpick comments (3)
src/Method.php (2)

58-79: LGTM! Robust method parsing implementation.

The parse method provides a type-safe way to create Method instances from ReflectionMethod objects.

Note: Consider adding PHPDoc for thrown exceptions to improve API documentation.

     /**
      * Creates a new {@see Method} object from a {@see \ReflectionMethod} object.
+     * @throws GRPCException When the method signature is invalid
      */
     public static function parse(\ReflectionMethod $method): Method

Line range hint 15-39: Consider cleaning up unused error constants.

Some error constants appear to be only used in private validation methods. Consider moving them closer to their usage or making them private if they're not part of the public API.

tests/Stub/TestService.php (1)

39-41: Remove Unnecessary Braces

The braces around the throw statement are unnecessary and can be removed to simplify the code.

Apply this diff to remove the unnecessary braces:

-        {
            throw new \Exception("Just another exception");
-        }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 51f8373 and c825782.

📒 Files selected for processing (21)
  • .gitattributes (1 hunks)
  • .github/workflows/cs-fix.yml (1 hunks)
  • .gitignore (1 hunks)
  • .php-cs-fixer.dist.php (1 hunks)
  • composer.json (2 hunks)
  • phpunit.xml (1 hunks)
  • psalm-baseline.xml (1 hunks)
  • psalm.xml (1 hunks)
  • src/Context.php (1 hunks)
  • src/Internal/Json.php (1 hunks)
  • src/Invoker.php (0 hunks)
  • src/Method.php (1 hunks)
  • src/ResponseHeaders.php (0 hunks)
  • src/Server.php (3 hunks)
  • src/ServiceInterface.php (1 hunks)
  • tests/ContextTest.php (5 hunks)
  • tests/InvalidInterface.php (1 hunks)
  • tests/MethodTest.php (1 hunks)
  • tests/ServerTest.php (6 hunks)
  • tests/ServiceWrapperTest.php (8 hunks)
  • tests/Stub/TestService.php (3 hunks)
💤 Files with no reviewable changes (2)
  • src/Invoker.php
  • src/ResponseHeaders.php
✅ Files skipped from review due to trivial changes (9)
  • .php-cs-fixer.dist.php
  • src/Internal/Json.php
  • tests/ContextTest.php
  • tests/InvalidInterface.php
  • tests/ServiceWrapperTest.php
  • src/Context.php
  • src/ServiceInterface.php
  • psalm-baseline.xml
  • tests/MethodTest.php
🧰 Additional context used
🪛 GitHub Actions: phpunit
phpunit.xml

[warning] No filter is configured, code coverage will not be processed

tests/ServerTest.php

[warning] 112-112: Risky test in testExceptionDetails: Test code or tested code closed output buffers other than its own

🔇 Additional comments (15)
src/Method.php (2)

42-42: LGTM! Constructor style improvement.

Empty constructor body has been simplified to use the constructor property promotion feature.


44-56: LGTM! Well-designed method signature validation.

The match method provides a clean way to validate method signatures without throwing exceptions.

.gitignore (1)

1-4: LGTM! Standardized .gitignore entries.

The entries have been standardized to use leading slashes, which makes the paths more explicit and prevents accidental matches in subdirectories.

.gitattributes (1)

1-10: LGTM! Improved Git attributes configuration.

The changes:

  • Add proper line ending normalization with text=auto
  • Exclude development files from package exports
  • Use consistent formatting for export-ignore rules
phpunit.xml (1)

3-5: LGTM! Good improvements to the PHPUnit configuration.

The changes to use local schema and enable result caching are good practices that will improve reliability and performance.

🧰 Tools
🪛 GitHub Actions: phpunit

[warning] No filter is configured, code coverage will not be processed

psalm.xml (1)

6-6: LGTM! Good addition of Psalm baseline configuration.

Adding error baseline support is a good practice that will help track and manage existing issues while preventing new ones.

composer.json (1)

54-55: LGTM! Well-structured updates for code style tooling.

The additions of code style dependencies and related scripts are well organized and align perfectly with the PR objectives. The script naming follows common conventions and provides good separation between checking (cs:diff) and fixing (cs:fix) operations.

Also applies to: 71-75

src/Server.php (3)

42-42: Constructor Simplification Looks Good

The constructor has been simplified, and the initializations appear correct.


90-90: Confirm Exception Handling Logic

Casting the exception to a string when isDebugMode() is true will include the stack trace in the error message. Ensure that this behavior is intended and acceptable, as it may expose sensitive information in a production environment.


115-146: Reintroduction of Private Methods Appears Correct

The methods tick, workerSend, and workerError have been reintroduced and appear to be correctly implemented. They restore functionality for processing requests and handling responses.

tests/Stub/TestService.php (2)

3-3: Enabling Strict Types

The addition of declare(strict_types=1); is a good practice to enforce strict type checking.


49-49: Consistent Use of Global Namespace for Built-in Functions

Prefacing built-in function calls with the global namespace \ (e.g., \error_log, \getenv, \getmypid, \json_encode) is good practice to prevent potential conflicts with user-defined functions.

Also applies to: 60-60, 64-64, 68-68

tests/ServerTest.php (3)

59-62: Use of Static Anonymous Functions and Global Namespaces

Adding the static keyword to anonymous functions and prefixing global function calls with \ (e.g., \base64_decode, \json_decode, \mb_strlen) is a good practice that can improve performance and avoid conflicts with overridden functions.

Also applies to: 81-84, 103-103, 127-128, 168-168, 173-173


145-147: Changing setUp Method Visibility to Protected

Changing the setUp method from private to protected enhances test extensibility by allowing subclasses to override the setup process.


156-156: ⚠️ Potential issue

Investigate Risky Test Due to Output Buffering

The addition of \ob_end_clean(); in the tearDown method may be addressing output buffering issues. However, the pipeline reports a risky test in testExceptionDetails: "Test code or tested code closed output buffers other than its own."

Please verify that output buffering is properly managed within the tests. Ensure that any output buffers started during a test are appropriately closed, and avoid closing output buffers that the test did not open. Consider using PHPUnit's built-in methods for handling output buffering.

Comment on lines +1 to +12
on:
push:
branches:
- '*'

name: Fix Code Style

jobs:
cs-fix:
permissions:
contents: write
uses: spiral/gh-actions/.github/workflows/cs-fix.yml@master
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Using a floating reference (@master) is indeed risky

The verification confirms that:

  • The repository has no tagged releases
  • The workflow file receives active updates (last modified Dec 11, 2024)
  • Breaking changes have occurred (e.g., removal of dry-run option in September 2024)

To ensure stability, pin the workflow to a specific commit SHA:

-    uses: spiral/gh-actions/.github/workflows/cs-fix.yml@master
+    uses: spiral/gh-actions/.github/workflows/cs-fix.yml@69d50ba35b48703584c28dc0600cc283d96f2303
🔗 Analysis chain

Consider pinning the workflow version.

The workflow is well-configured, but it uses a floating reference (@master) which could lead to unexpected behavior if the upstream workflow changes.

Consider using a specific commit SHA or tag for spiral/gh-actions to ensure reproducible builds:

-    uses: spiral/gh-actions/.github/workflows/cs-fix.yml@master
+    uses: spiral/gh-actions/.github/workflows/[email protected]  # or specific SHA
🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Check repository and its releases
gh repo view spiral/gh-actions --json url,description,isArchived,defaultBranch
gh release list --repo spiral/gh-actions

# Check commit history of the specific workflow file
gh api -X GET /repos/spiral/gh-actions/commits \
  --jq '.[] | {sha: .sha, date: .commit.committer.date, message: .commit.message}' \
  -F path=.github/workflows/cs-fix.yml \
  -F per_page=5 \
  --repo spiral/gh-actions

Length of output: 2838


Script:

#!/bin/bash
# Check repository info
gh repo view spiral/gh-actions --json url,description,isArchived

# List releases
gh release list --repo spiral/gh-actions

# Check recent commits
gh api \
  repos/spiral/gh-actions/commits \
  --jq '.[] | {sha: .sha, date: .commit.committer.date, message: .commit.message}' \
  -X GET \
  -f path=.github/workflows/cs-fix.yml \
  -f per_page=5

Length of output: 897

Comment on lines +2 to +13
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile="runtime/phpunit/result.cache"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
stopOnError="false"
stderr="true"
backupStaticProperties="false"
>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add coverage configuration to fix pipeline warning.

The pipeline is warning about missing coverage filter. This could impact code coverage reporting.

Add the following configuration:

 <phpunit ...>
+    <coverage>
+        <include>
+            <directory>src</directory>
+        </include>
+    </coverage>
     <testsuites>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile="runtime/phpunit/result.cache"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
stopOnError="false"
stderr="true"
backupStaticProperties="false"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile="runtime/phpunit/result.cache"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
stopOnError="false"
stderr="true"
backupStaticProperties="false"
>
<coverage>
<include>
<directory>src</directory>
</include>
</coverage>
🧰 Tools
🪛 GitHub Actions: phpunit

[warning] No filter is configured, code coverage will not be processed

@roxblnfk roxblnfk merged commit bc04ee6 into 3.x Jan 9, 2025
6 of 7 checks passed
@roxblnfk roxblnfk deleted the metadata branch January 9, 2025 20:08
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