Skip to content

refactor: DRY cycle request context handling#24

Open
somethingwithproof wants to merge 2 commits intoCacti:developfrom
somethingwithproof:fix/dry-context-23
Open

refactor: DRY cycle request context handling#24
somethingwithproof wants to merge 2 commits intoCacti:developfrom
somethingwithproof:fix/dry-context-23

Conversation

@somethingwithproof
Copy link

Summary

  • add shared request-context helpers in cycle_helpers.php
  • deduplicate request extraction and default normalization logic used by both cycle_graphs() and cycle()
  • keep behavior unchanged while reducing repeated code in cycle.php

Tests

  • php -l cycle.php
  • php -l cycle_helpers.php
  • php -l tests/test_request_context.php
  • php tests/test_request_context.php

Closes #23

Copilot AI review requested due to automatic review settings March 15, 2026 22:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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()) in cycle_helpers.php.
  • Updated cycle.php to 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
);

Copy link
Author

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: DRY cycle request context handling

2 participants