-
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: Improve depth
attribute handling in shiftLeftRightAttribute
method of NestedSetsBehavior
class.
#21
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
Conversation
…ute` method of `NestedSetsBehavior` class.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #21 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 88 89 +1
===========================================
Files 2 2
Lines 465 465
===========================================
Hits 465 465 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
WalkthroughThe Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant NestedSetsBehavior
participant OwnerNode
participant TargetNode
Caller->>NestedSetsBehavior: beforeInsertNode(owner, target, value, depthOffset)
alt target's depth is not null
NestedSetsBehavior->>OwnerNode: Set depth attribute to target.depth + depthOffset
end
alt treeAttribute enabled and target is not null
NestedSetsBehavior->>OwnerNode: Set tree attribute from target
end
alt value is not null
NestedSetsBehavior->>NestedSetsBehavior: shiftLeftRightAttribute(value)
end
Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (3)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the handling of the depth attribute in the shiftLeftRightAttribute method of the NestedSetsBehavior class to avoid unintended updates when attribute values are null.
- Updated depth attribute logic to update only when a valid depth value is present.
- Modified tree attribute assignment to occur only if a node is available.
- Adjusted the left-right shifting to execute only when a non-null value is provided.
Comments suppressed due to low confidence (3)
src/NestedSetsBehavior.php:1057
- [nitpick] Consider adding a comment to explain why the depth attribute update is skipped when the node's depth value is null, highlighting the intention behind removing the default fallback of 0.
$nodeDepthValue = $this->node?->getAttribute($this->depthAttribute);
src/NestedSetsBehavior.php:1063
- [nitpick] Add a brief comment clarifying that the tree attribute assignment is now intentionally omitted when no node is present, contrasting with the previous behavior that would assign a null value.
if ($this->treeAttribute !== false && $this->node !== null) {
src/NestedSetsBehavior.php:1067
- [nitpick] Ensure that the decision to not call shiftLeftRightAttribute when $value is null is intended; a comment clarifying this change from the previous default of 0 would improve code clarity.
if ($value !== null) {
…ht` shifting in `beforeInsertNode` method of `NestedSetsBehavior` class.
There was a problem hiding this 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
🧹 Nitpick comments (1)
tests/NestedSetsBehaviorTest.php (1)
1624-1669
: Good test coverage for null node handling, but fix coding style issue.The test correctly validates that
beforeInsertNode
works properly when the internal node reference is null. The anonymous class approach for exposing protected methods is appropriate for testing internal behavior.However, fix the coding style issue flagged by the pipeline:
- $behavior = new class () extends NestedSetsBehavior { + $behavior = new class extends NestedSetsBehavior {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/NestedSetsBehavior.php
(1 hunks)tests/NestedSetsBehaviorTest.php
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/NestedSetsBehavior.php
🧰 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.839Z
Learning: The user terabytesoftw prefers to keep PRs focused and small, implementing enhancements in separate dedicated PRs rather than bundling multiple changes together.
🪛 GitHub Actions: ecs
tests/NestedSetsBehaviorTest.php
[warning] 1625-1625: PhpCsFixer: NewWithParenthesesFixer suggests removing parentheses in 'new class ()' to 'new class'. Fixable by running with '--fix'.
[warning] 1672-1672: PhpCsFixer: NewWithParenthesesFixer suggests removing parentheses in 'new class ()' to 'new class'. Fixable by running with '--fix'.
⏰ Context from checks skipped due to timeout of 90000ms (20)
- GitHub Check: easy-coding-standard / PHP 8.4-ubuntu-latest
- GitHub Check: phpstan / PHP 8.4-ubuntu-latest
- GitHub Check: phpunit-compatibility / PHP 8.4-windows-latest
- GitHub Check: phpunit-compatibility / PHP 8.2-windows-latest
- GitHub Check: phpunit / PHP 8.1-windows-latest
- GitHub Check: phpunit-compatibility / PHP 8.2-ubuntu-latest
- GitHub Check: phpunit-compatibility / PHP 8.4-ubuntu-latest
- GitHub Check: phpunit / PHP 8.2-windows-latest
- GitHub Check: phpunit / PHP 8.3-ubuntu-latest
- GitHub Check: phpunit-compatibility / PHP 8.3-windows-latest
- GitHub Check: phpunit-compatibility / PHP 8.1-ubuntu-latest
- GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
- GitHub Check: phpunit / PHP 8.4-windows-latest
- GitHub Check: phpunit / PHP 8.3-windows-latest
- GitHub Check: phpunit / 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 / PHP 8.1-windows-latest
- GitHub Check: phpunit / PHP 8.3-windows-latest
- GitHub Check: composer-require-checker / PHP 8.4-ubuntu-latest
🔇 Additional comments (1)
tests/NestedSetsBehaviorTest.php (1)
1713-1763
: Excellent integration test for tree structure validation.This test provides valuable validation that the refactored
beforeInsertNode
method doesn't break normal tree operations. The test correctly:
- Validates the initial root node state
- Tests the
appendTo
operation- Verifies tree structure integrity after the operation
- Uses proper error handling with try-catch
The assertions effectively check the nested set model constraints and depth calculations.
…antiation in `NestedSetsBehaviorTest`
Summary by CodeRabbit