-
-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: Streamline node movement logic in NestedSetsBehavior
class in afterUpdate()
method.
#15
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
…s in `afterUpdate()` method.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #15 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 82 86 +4
===========================================
Files 2 2
Lines 457 460 +3
===========================================
+ Hits 457 460 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
""" WalkthroughThe Changes
Possibly related PRs
Poem
""" 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. 🔧 phpcs (3.7.2)src/NestedSetsBehavior.phpWarning: PHP Startup: Invalid date.timezone value 'UTC', using 'UTC' instead in Unknown on line 0 Fatal error: Uncaught Error: Class "Phar" not found in /usr/local/bin/phpcs:3 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (17)
✨ Finishing Touches
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/NestedSetsBehavior.php (1)
250-265
: Consider usingmatch
expression for cleaner control flow.The refactoring to pass
$this->node
explicitly tomoveNode()
is excellent, but the change frommatch
toswitch(true)
makes the code more verbose without clear benefits. Consider using amatch
expression with the explicit parameter passing:- switch (true) { - case $this->operation === self::OPERATION_APPEND_TO && $this->node !== null: - $this->moveNode($this->node, $this->node->getAttribute($this->rightAttribute), 1); - break; - case $this->operation === self::OPERATION_INSERT_AFTER && $this->node !== null: - $this->moveNode($this->node, $this->node->getAttribute($this->rightAttribute) + 1, 0); - break; - case $this->operation === self::OPERATION_INSERT_BEFORE && $this->node !== null: - $this->moveNode($this->node, $this->node->getAttribute($this->leftAttribute), 0); - break; - case $this->operation === self::OPERATION_MAKE_ROOT: - $this->moveNodeAsRoot(); - break; - case $this->operation === self::OPERATION_PREPEND_TO && $this->node !== null: - $this->moveNode($this->node, $this->node->getAttribute($this->leftAttribute) + 1, 1); - } + match ($this->operation) { + self::OPERATION_APPEND_TO when $this->node !== null => + $this->moveNode($this->node, $this->node->getAttribute($this->rightAttribute), 1), + self::OPERATION_INSERT_AFTER when $this->node !== null => + $this->moveNode($this->node, $this->node->getAttribute($this->rightAttribute) + 1, 0), + self::OPERATION_INSERT_BEFORE when $this->node !== null => + $this->moveNode($this->node, $this->node->getAttribute($this->leftAttribute), 0), + self::OPERATION_MAKE_ROOT => + $this->moveNodeAsRoot(), + self::OPERATION_PREPEND_TO when $this->node !== null => + $this->moveNode($this->node, $this->node->getAttribute($this->leftAttribute) + 1, 1), + default => null, + };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/NestedSetsBehavior.php
(3 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.839Z
Learning: The user terabytesoftw prefers to keep PRs focused and small, implementing enhancements in separate dedicated PRs rather than bundling multiple changes together.
🧬 Code Graph Analysis (1)
src/NestedSetsBehavior.php (1)
tests/TestCase.php (1)
getDb
(40-43)
⏰ Context from checks skipped due to timeout of 90000ms (7)
- GitHub Check: phpunit / PHP 8.4-windows-latest
- GitHub Check: phpunit / PHP 8.1-windows-latest
- GitHub Check: phpunit / PHP 8.3-windows-latest
- GitHub Check: phpunit / PHP 8.2-windows-latest
- GitHub Check: phpunit-compatibility / PHP 8.3-windows-latest
- GitHub Check: phpunit-compatibility / PHP 8.2-windows-latest
- GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
🔇 Additional comments (1)
src/NestedSetsBehavior.php (1)
1169-1169
: Excellent refactoring to use explicit parameter.The replacement of
$this->node
references with the passed$node
parameter improves the method's encapsulation and makes it independent of internal behavior state. This change enhances testability and makes the code more explicit about which node is being operated on.Also applies to: 1175-1175, 1236-1236
…`int` for clarity.
…te() method for improved readability.
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 afterUpdate()
method in NestedSetsBehavior
to use a boolean match
for operation dispatch and updates the moveNode
method to accept an explicit ActiveRecord $node
parameter.
- Streamlined operation handling in
afterUpdate()
usingmatch(true)
- Changed
moveNode
signature to include the node instance and updated internal references - Added a docblock parameter for
$node
Comments suppressed due to low confidence (3)
src/NestedSetsBehavior.php:1155
- The docblock now includes a new
$node
parameter but the existing@param
tags for$value
and$depth
are unchanged; please update and reorder the docblock to document all parameters consistently.
* @param ActiveRecord $node Node to be moved within the nested set tree.
src/NestedSetsBehavior.php:248
- The updated
afterUpdate()
logic now dispatches different operations with explicit node handling; consider adding or updating unit tests to cover each operation path (append, prepend, insert before/after, make root).
public function afterUpdate(): void
src/NestedSetsBehavior.php:1159
- Changing the protected
moveNode
signature is a backward-incompatible change for any subclasses that override this method; consider deprecating the old signature or increasing the major version to reflect the API change.
protected function moveNode(ActiveRecord $node, int $value, int $depth): void
Summary by CodeRabbit