Skip to content

fix: Correct logic for adjusting right value in subtree size calculation in NestedSetsBehavior class. #55

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

Merged
merged 5 commits into from
Jul 3, 2025

Conversation

terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Jul 3, 2025

Q A
Is bugfix? ✔️
New feature?
Breaks BC?

Summary by CodeRabbit

  • Refactor

    • Simplified internal logic for moving nodes within the same tree, improving maintainability.
    • Updated object instantiation in several methods for cleaner code.
  • Tests

    • Enhanced a test to explicitly set and save a node attribute before performing an append operation, ensuring test accuracy.

@terabytesoftw terabytesoftw added the bug Something isn't working label Jul 3, 2025
Copy link

coderabbitai bot commented Jul 3, 2025

Walkthrough

This update refactors internal logic in the executeSameTreeMove method of NestedSetsBehavior, simplifying how left and right values are adjusted during node moves. It also updates factory methods in NodeContext to use positional arguments and modifies a test to explicitly set an attribute before an append operation.

Changes

File(s) Change Summary
src/NestedSetsBehavior.php Refactored executeSameTreeMove to unify and simplify the conditional increment of left/right values. Added comments and a mutation testing directive.
src/NodeContext.php Replaced named arguments with positional arguments in four static factory methods for object construction.
tests/NestedSetsBehaviorTest.php Added lines to explicitly set and save the 'lft' attribute of a node before an append operation in a test.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Child2 as Node ($child2)
    participant Child1 as Node ($child1)
    participant Behavior as NestedSetsBehavior

    Test->>Child2: Set 'lft' attribute to 3
    Test->>Child2: Save node
    Test->>Child2: appendTo(Child1)
    Child2->>Behavior: executeSameTreeMove()
    Behavior->>Behavior: Adjust left/right values (new unified logic)
    Behavior-->>Child2: Update node positions
    Test->>Test: Verify cache invalidation
Loading

Possibly related PRs

Poem

A rabbit hopped through nested trees,
Adjusting left and right with ease.
No more double checks or fuss,
Just one condition—less for us!
With tests and context neat and tight,
This patch brings code that feels just right.
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.15)

Note: Using configuration file /phpstan.neon.
Invalid configuration:
Unexpected item 'parameters › yii2'.


📜 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 48ad412 and f500cb0.

📒 Files selected for processing (3)
  • src/NestedSetsBehavior.php (1 hunks)
  • src/NodeContext.php (4 hunks)
  • tests/NestedSetsBehaviorTest.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: terabytesoftw
PR: yii2-extensions/nested-sets-behavior#13
File: src/NestedSetsBehavior.php:145-145
Timestamp: 2025-06-29T11:22:41.889Z
Learning: The user terabytesoftw prefers to keep PRs focused and small, implementing enhancements in separate dedicated PRs rather than bundling multiple changes together.
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: phpunit-compatibility / PHP 8.3-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.4-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.3-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.4-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-ubuntu-latest
  • GitHub Check: composer-require-checker / PHP 8.4-ubuntu-latest
  • GitHub Check: easy-coding-standard / PHP 8.4-ubuntu-latest
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
  • GitHub Check: phpstan / PHP 8.4-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.2-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.3-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
  • GitHub Check: phpunit / PHP 8.3-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.4-windows-latest
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.1-windows-latest
  • GitHub Check: mutation / PHP 8.4-ubuntu-latest
🔇 Additional comments (6)
src/NodeContext.php (4)

45-45: LGTM - Clean simplification using positional arguments.

The change from named to positional arguments in the constructor call maintains the same functionality while reducing verbosity.


62-62: LGTM - Consistent with the positional argument pattern.

Good consistency with the other factory methods.


79-79: LGTM - Maintains readability with positional arguments.

The positional mapping is clear and well-defined.


96-96: LGTM - Completes the consistent refactoring pattern.

All factory methods now use the same concise positional argument style.

src/NestedSetsBehavior.php (1)

320-328: Excellent refactoring - simplified subtree adjustment logic.

The change consolidates the left and right value adjustments into a single conditional check, which is more efficient and clearer. In nested sets, subtree boundaries always move together, so checking only the left value and applying the same offset to both values is the correct approach.

The comment explaining that equality is impossible due to the algorithm's nature demonstrates good understanding of the nested set model.

tests/NestedSetsBehaviorTest.php (1)

2414-2416: LGTM! Well-designed test enhancement for cache invalidation.

The explicit modification of the lft attribute before the appendTo operation creates a realistic scenario where cached values might be stale, ensuring the cache invalidation mechanism is thoroughly tested. This change aligns well with the PR's focus on fixing subtree size calculation logic.

✨ 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.

Copy link

codecov bot commented Jul 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (48ad412) to head (f500cb0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #55   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
+ Complexity       137       136    -1     
===========================================
  Files              4         4           
  Lines            554       537   -17     
===========================================
- Hits             554       537   -17     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@terabytesoftw terabytesoftw merged commit c1423e7 into main Jul 3, 2025
45 checks passed
@terabytesoftw terabytesoftw deleted the fix-mini-46 branch July 3, 2025 22:28
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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy