refactor: DRY cycle request context handling#24
Open
somethingwithproof wants to merge 2 commits intoCacti:developfrom
Open
refactor: DRY cycle request context handling#24somethingwithproof wants to merge 2 commits intoCacti:developfrom
somethingwithproof wants to merge 2 commits intoCacti:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the Cycle plugin’s request-context extraction/normalization to reduce duplication by introducing a shared helper used by both cycle_graphs() and cycle().
Changes:
- Added shared request-context helpers (
cycle_get_request_context(),cycle_get_default_tree_id()) incycle_helpers.php. - Updated
cycle.phpto use the shared helper in both rendering paths. - Added a standalone regression test to validate normalization behavior and guard against regressions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
tests/test_request_context.php |
Adds regression coverage for helper normalization and a guard asserting usage from cycle.php. |
cycle_helpers.php |
Introduces shared helper functions for request-context extraction and default normalization. |
cycle.php |
Replaces duplicated request extraction/defaulting with calls to the shared helper in both code paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+74
to
+79
| $cycle_source = file_get_contents(__DIR__ . '/../cycle.php'); | ||
| assert_true( | ||
| 'cycle.php uses shared request context in both paths', | ||
| preg_match_all('/cycle_get_request_context\\s*\\(/', $cycle_source) >= 2 | ||
| ); | ||
|
|
Author
There was a problem hiding this comment.
Addressed in 31dfe04: replaced the count-based source assertion with a readability check plus a non-counted helper-usage assertion to avoid implementation-detail coupling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cycle_helpers.phpcycle_graphs()andcycle()cycle.phpTests
php -l cycle.phpphp -l cycle_helpers.phpphp -l tests/test_request_context.phpphp tests/test_request_context.phpCloses #23