Skip to content

[#458] Refactor debugbar() helper for structural and behavioral consi… - #463

Merged
armanist merged 1 commit into
quantum-php:masterfrom
armanist:issue/458-refactor-debugbar-helper
Apr 21, 2026
Merged

armanist merged 1 commit into
quantum-php:masterfrom
armanist:issue/458-refactor-debugbar-helper

Conversation

@armanist

@armanist armanist commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #458

Summary by CodeRabbit

  • Improvements

    • Debug bar now properly respects disabled state and skips rendering when debug mode is off, improving performance.
    • Updated debug bar initialization and template rendering across the application.
  • Tests

    • Added comprehensive test coverage for debug bar functionality and behavior.

…ioral consistency

Move debugbar() from View/Helpers to Debugger/Helpers so it lives alongside the Debugger class it serves. The helper now returns a Debugger instance instead of a rendered string, giving templates explicit control via debugbar()->render(). Add isEnabled() guard to Debugger::render() so it safely returns empty when debug mode is off.

Made-with: Cursor
@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5fb2525b-c813-4f28-bccf-781aa468b76f

📥 Commits

Reviewing files that changed from the base of the PR and between ef2b7c3 and 621c3d1.

📒 Files selected for processing (8)
  • src/Debugger/Debugger.php
  • src/Debugger/Helpers/debugger.php
  • src/Module/Templates/DefaultWeb/src/Views/layouts/main.php.tpl
  • src/Module/Templates/DemoWeb/src/Views/layouts/main.php.tpl
  • src/Module/Templates/Toolkit/src/Views/layouts/main.php.tpl
  • src/View/Helpers/view.php
  • tests/Unit/Debugger/DebuggerTest.php
  • tests/Unit/Debugger/Helpers/DebuggerHelperTest.php
💤 Files with no reviewable changes (1)
  • src/View/Helpers/view.php

📝 Walkthrough

Walkthrough

The debugbar() helper function has been relocated from the View module to the Debugger module in a dedicated helper file, changing it to return a Debugger instance instead of pre-rendered HTML. The Debugger::render() method now checks if debugging is enabled and returns an empty string when disabled. Template files have been updated to explicitly call the render() method on the debugger instance, and corresponding tests have been added.

Changes

Cohort / File(s) Summary
Debugger Core
src/Debugger/Debugger.php
Added early return in render() when isEnabled() is false. Updated method documentation to indicate it may throw DiException|ReflectionException in addition to DebugBarException.
Debugger Helper
src/Debugger/Helpers/debugger.php
New helper file defining global debugbar() function that returns Debugger instance, registering the service if not already present in the DI container.
Template Views
src/Module/Templates/DefaultWeb/src/Views/layouts/main.php.tpl, src/Module/Templates/DemoWeb/src/Views/layouts/main.php.tpl, src/Module/Templates/Toolkit/src/Views/layouts/main.php.tpl
Updated debug bar output expressions from <?php echo debugbar() ?> to <?= debugbar()->render() ?> to explicitly render via method call.
View Helpers
src/View/Helpers/view.php
Removed debugbar() helper function and its associated imports (Debugger, Di, DebugBarException).
Tests
tests/Unit/Debugger/DebuggerTest.php, tests/Unit/Debugger/Helpers/DebuggerHelperTest.php
Updated existing render test to set app.debug config to true. Added new test asserting render returns empty when disabled. Added new test class validating helper function returns Debugger instance and maintains singleton behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 The debugbar hops to its new home,
From views to helpers, no more to roam!
Now render calls keep secrets tight,
Disabled by default—production stays right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[#458] Refactor debugbar() helper for structural and behavioral consi…' directly references issue #458 and accurately describes the main refactoring of the debugbar() helper function.
Linked Issues check ✅ Passed All primary objectives from issue #458 are met: helper relocated to Debugger module, returns Debugger instance instead of rendered HTML, render() guards against disabled debug mode, templates updated to call render() explicitly.
Out of Scope Changes check ✅ Passed All changes directly support the stated objectives: moving the helper, updating render() behavior, modifying templates to call render() explicitly, and adding corresponding tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.78%. Comparing base (ef2b7c3) to head (621c3d1).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/Debugger/Helpers/debugger.php 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #463      +/-   ##
============================================
+ Coverage     82.72%   82.78%   +0.06%     
- Complexity     2862     2863       +1     
============================================
  Files           248      249       +1     
  Lines          7624     7623       -1     
============================================
+ Hits           6307     6311       +4     
+ Misses         1317     1312       -5     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 621c3d122d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Debugger/Helpers/debugger.php
@armanist armanist added the enhancement New feature or request label Apr 21, 2026
@armanist armanist added this to the 3.0.0 milestone Apr 21, 2026
@armanist
armanist requested a review from andrey-smaelov April 21, 2026 08:09
@armanist
armanist merged commit e9fdf53 into quantum-php:master Apr 21, 2026
6 of 7 checks passed
@armanist
armanist deleted the issue/458-refactor-debugbar-helper branch October 23, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor debugbar() Helper for Structural and Behavioral Consistency

2 participants