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

Declare the reconnect parameter deprecated in the disconnect #11

Merged
merged 2 commits into from
Mar 6, 2024

Conversation

msmakouz
Copy link
Member

@msmakouz msmakouz commented Mar 6, 2024

Q A
Bugfix? ✔️
Breaks BC?
New feature?

The reconnect parameter was removed in centrifugal/centrifugo v5.0.0:
https://centrifugal.dev/docs/getting-started/migration_v5

reconnect flag removed from disconnect API call and proxy structures for custom disconnection

@msmakouz msmakouz added the bug Something isn't working label Mar 6, 2024
@msmakouz msmakouz self-assigned this Mar 6, 2024
Copy link

coderabbitai bot commented Mar 6, 2024

Walkthrough

The updates focus on deprecating the reconnect property in the Disconnect class and its usage across various components due to changes in the centrifugal/centrifugo v5.0.0 API. The reconnect parameter is removed from method signatures and tests, reflecting its deprecation in version 2.0.1 and planned removal in version 3.0.0. These modifications ensure compatibility with the latest API standards and prepare for future releases.

Changes

File Path Change Summary
src/Payload/Disconnect.php, src/Request/AbstractRequest.php, src/Request/RequestInterface.php Deprecated reconnect property in Disconnect class; removed related constructor parameter and updated method documentation.
src/RPCCentrifugoApi.php, tests/Unit/RPCCentrifugoApiTest.php Removed reconnect parameter from disconnect method in RPCCentrifugoApi.php; added tests with Disconnect object and deprecated reconnect parameter.
tests/Unit/Request/AbstractRequestTest.php Updated tests for disconnect method; removed reconnect parameter, and renamed test functions to highlight deprecation.

🐰✨
Changes abound, in code, we trust,
reconnect fades to dust.
Through fields of code, the rabbit hops,
Deprecated now, but progress never stops.
🚀🌌
In version three, we'll say goodbye,
'Til then, under the coder's sky.

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

codecov bot commented Mar 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.93%. Comparing base (4633c33) to head (2b4a7dd).

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x      #11      +/-   ##
============================================
+ Coverage     75.66%   78.93%   +3.27%     
  Complexity      147      147              
============================================
  Files            23       23              
  Lines           489      489              
============================================
+ Hits            370      386      +16     
+ Misses          119      103      -16     

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

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.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4633c33 and e231d05.
Files selected for processing (6)
  • src/Payload/Disconnect.php (1 hunks)
  • src/RPCCentrifugoApi.php (1 hunks)
  • src/Request/AbstractRequest.php (1 hunks)
  • src/Request/RequestInterface.php (1 hunks)
  • tests/Unit/RPCCentrifugoApiTest.php (2 hunks)
  • tests/Unit/Request/AbstractRequestTest.php (2 hunks)
Additional comments: 5
src/Payload/Disconnect.php (1)
  • 9-12: The reconnect property is correctly marked as deprecated. This is a good practice to inform users of the library about the upcoming removal of this property in future versions.
src/Request/RequestInterface.php (1)
  • 46-48: The documentation for the disconnect method correctly notes the deprecation of the $reconnect parameter. This is a good practice for informing users about deprecated features and aligning with the updated external API.
tests/Unit/Request/AbstractRequestTest.php (1)
  • 102-102: The testDisconnect method correctly tests the disconnect functionality without using the deprecated reconnect parameter. This aligns with the updated API behavior.
tests/Unit/RPCCentrifugoApiTest.php (1)
  • 77-100: The testDisconnectWithDisconnectObject method correctly tests the disconnect functionality using the Disconnect object without the deprecated reconnect parameter. This aligns with the updated API behavior.
src/RPCCentrifugoApi.php (1)
  • 158-163: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [97-126]

The disconnect method has been updated to no longer pass the reconnect parameter in the DTO\Disconnect object, aligning with the updated centrifugal/centrifugo v5.0.0 API. This change correctly reflects the deprecation of the reconnect parameter and ensures the library remains compatible with the latest API standards.

Comment on lines 14 to 23
/**
* @param bool $reconnect This parameter is no longer used since v2.0.1 due to the removal of this option in
* centrifugal/centrifugo v5.0.0 API. It will be removed in v3.0.0.
*/
public function __construct(
public readonly int $code,
public readonly string $reason,
public readonly bool $reconnect = false
bool $reconnect = false
) {
$this->reconnect = $reconnect;
Copy link

Choose a reason for hiding this comment

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

The constructor still accepts the $reconnect parameter, which is marked for removal in future versions. While it's good to maintain backward compatibility, it's important to ensure that this deprecated feature does not cause confusion. Consider adding a trigger for a deprecation warning when this parameter is used, to inform developers of its impending removal.

public function __construct(
    public readonly int $code,
    public readonly string $reason,
    bool $reconnect = false
) {
    if ($reconnect !== false) {
        trigger_error('The $reconnect parameter is deprecated and will be removed in v3.0.0.', E_USER_DEPRECATED);
    }
    $this->reconnect = $reconnect;
}

Comment on lines +63 to +71
/**
* @param bool $reconnect This parameter is no longer used since v2.0.1 due to the removal of this option in
* centrifugal/centrifugo v5.0.0 API. It will be removed in v3.0.0.
*/
final public function disconnect(int $code, string $reason, bool $reconnect = false): void
{
$response = $this->getResponseObject();
$response->setDisconnect(
new Disconnect(\compact('code', 'reason', 'reconnect')),
new Disconnect(\compact('code', 'reason')),
Copy link

Choose a reason for hiding this comment

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

The disconnect method documentation correctly indicates the deprecation of the $reconnect parameter. However, the method still accepts and processes this parameter. As with the Disconnect class, consider adding a deprecation warning when this parameter is used, to better inform developers of its impending removal.

final public function disconnect(int $code, string $reason, bool $reconnect = false): void
{
    if ($reconnect !== false) {
        trigger_error('The $reconnect parameter is deprecated and will be removed in v3.0.0.', E_USER_DEPRECATED);
    }
    // Existing implementation...
}

Comment on lines 115 to 125
$req->disconnect(111, 'some');
}

public function testDisconnectWithReconnect(): void
public function testDisconnectWithDeprecatedReconnect(): void
{
$worker = $this->createWorker(function (Payload $arg) {
$expects = new Payload((new ConnectResponse())
->setDisconnect(new Disconnect(['code' => 111, 'reason' => 'some', 'reconnect' => true]))
->setDisconnect(new Disconnect(['code' => 111, 'reason' => 'some']))
->serializeToString()
);

Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [118-126]

The testDisconnectWithDeprecatedReconnect method tests the disconnect functionality with the deprecated reconnect parameter. While it's important to test deprecated features for backward compatibility, ensure that this test is clearly marked or documented as testing deprecated behavior, to avoid confusion.

Consider adding a comment or documentation to clarify that this test is specifically for ensuring backward compatibility with the deprecated reconnect parameter.

Comment on lines +103 to +126
public function testDisconnectWithDisconnectObjectAndDeprecatedReconnect(): void
{
$this->rpc->shouldReceive('call')
->once()
->withArgs(fn(
string $method,
DTO\DisconnectRequest $request,
string $responseClass
): bool => $method === 'centrifuge.Unsubscribe'
&& $request->getUser() === 'foo-user'
&& $request->getClient() === 'foo-client'
&& $request->getSession() === 'foo-session'
&& $request->getDisconnect()->getCode() === 400
&& $request->getDisconnect()->getReason() === 'foo-reason'
&& $responseClass === DTO\DisconnectResponse::class
)
->andReturn(new DTO\DisconnectResponse);

$this->api->disconnect(
user: 'foo-user',
client: 'foo-client',
session: 'foo-session',
disconnect: new Disconnect(code: 400, reason: 'foo-reason', reconnect: true),
);
Copy link

Choose a reason for hiding this comment

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

The testDisconnectWithDisconnectObjectAndDeprecatedReconnect method tests the disconnect functionality with the deprecated reconnect parameter. As with the previous test file, ensure that this test is clearly marked or documented as testing deprecated behavior.

Consider adding a comment or documentation to clarify that this test is specifically for ensuring backward compatibility with the deprecated reconnect parameter.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e231d05 and 2b4a7dd.
Files selected for processing (2)
  • src/Payload/Disconnect.php (1 hunks)
  • src/Request/Connect.php (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/Payload/Disconnect.php
Additional comments: 1
src/Request/Connect.php (1)
  • 106-106: The change to explicitly check if expireAt is not null, instead of relying on its truthiness, is a good practice for clarity and avoiding potential bugs related to falsy values that are not null. This aligns well with the PR's objectives of ensuring compatibility with updated API specifications.

@msmakouz msmakouz merged commit 1a25f03 into 2.x Mar 6, 2024
7 checks passed
@msmakouz msmakouz deleted the bugfix/deprecate-reconnect branch March 6, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants