Skip to content

[#459] Refactor view() helper to service locator and rename QtView to View#464

Merged
armanist merged 2 commits into
quantum-php:masterfrom
armanist:issue/459-refactor-view-helper
Apr 21, 2026
Merged

[#459] Refactor view() helper to service locator and rename QtView to View#464
armanist merged 2 commits into
quantum-php:masterfrom
armanist:issue/459-refactor-view-helper

Conversation

@armanist

@armanist armanist commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Closes #459

Summary by CodeRabbit

  • Refactor
    • Streamlined debugger initialization through helper functions for improved code clarity.
    • Enhanced view rendering with explicit content retrieval methods for better consistency.
    • Updated internal view system architecture for improved maintainability across application templates.

…e QtView to View

Rename QtView class to View for naming consistency with the rest of the framework. Convert view() helper from returning a rendered string to returning the View instance, letting templates call view()->getContent() explicitly. Rename getView() to getContent() to avoid tautological naming. Also adopt debugbar() helper in ViewFactory, InitDebuggerStage, MessageAdapter and WebAppTrait.

Made-with: Cursor
@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@armanist has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 42 minutes and 35 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 42 minutes and 35 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 18a0b2dc-3735-447a-9d00-7d55cd89f677

📥 Commits

Reviewing files that changed from the base of the PR and between ef6c704 and c4b5f03.

📒 Files selected for processing (1)
  • src/App/Traits/WebAppTrait.php
📝 Walkthrough

Walkthrough

This PR refactors the View subsystem by renaming QtView to View, converting the view() helper to return a View instance rather than a string, and renaming getView() to getContent(). Additionally, debugger initialization is refactored to use the debugbar() helper instead of DI container lookups.

Changes

Cohort / File(s) Summary
Debugger Integration Refactoring
src/App/Stages/InitDebuggerStage.php, src/App/Traits/WebAppTrait.php, src/Logger/Adapters/MessageAdapter.php
Replaced direct DI container calls (Di::isRegistered(), Di::get()) with debugbar() helper function calls; removed associated exception annotations (DiException, ReflectionException, DebugBarException).
View Class Rename and Refactoring
src/View/View.php
Renamed class from QtView to View and renamed public method getView(): ?string to getContent(): ?string while preserving functionality.
View Factory and Helper Updates
src/View/Factories/ViewFactory.php, src/View/Helpers/view.php
Updated ViewFactory to return View instead of QtView; refactored view() helper to return View instance instead of string, enabling fluent method chaining and converting helper to act as true service locator.
BaseController Template Updates
src/Module/Templates/DemoWeb/src/Controllers/BaseController.php.tpl, src/Module/Templates/Toolkit/src/Controllers/BaseController.php.tpl
Updated view property type from QtView to View in template base controllers.
View Layout Template Updates
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/..., tests/_root/modules/Test/Views/...
Changed view rendering from <?php echo view() ?> to <?= view()->getContent() ?> across all layout templates; added support for Twig templates with {{ view().getContent() }}.
Unit Test Updates
tests/Unit/View/ViewTest.php, tests/Unit/View/Factories/ViewFactoryTest.php, tests/Unit/View/Helpers/ViewHelperTest.php
Updated test imports and assertions to reference View instead of QtView; renamed test class QtViewTest to ViewTest; updated test methods to call getContent() instead of getView(); added test for new view()->getContent() behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • andrey-smaelov

Poem

🐰 QtView hops away, now View takes the stage,
Helpers return instances, fluent methods engage,
No more DI chains, just debugbar() calls so clean,
Content flows smoother through layouts serene,
A refactored garden where code dances free! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% 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 accurately describes the main changes: renaming QtView to View and refactoring the view() helper to act as a service locator.
Linked Issues check ✅ Passed All coding requirements from issue #459 are met: QtView renamed to View across codebase, view() helper refactored to return View instance, getView() renamed to getContent(), and all templates and tests updated accordingly.
Out of Scope Changes check ✅ Passed Additional refactoring to use debugbar() helper instead of DI container in InitDebuggerStage, WebAppTrait, and MessageAdapter is tangential but supports the overall modernization goals and does not introduce unrelated functionality.

✏️ 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 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.80%. Comparing base (e9fdf53) to head (c4b5f03).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/View/Helpers/view.php 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #464      +/-   ##
============================================
+ Coverage     82.78%   82.80%   +0.01%     
+ Complexity     2863     2861       -2     
============================================
  Files           249      249              
  Lines          7623     7619       -4     
============================================
- Hits           6311     6309       -2     
+ Misses         1312     1310       -2     

☔ 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.

@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

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/App/Traits/WebAppTrait.php (1)

103-104: Reuse the resolved debugger instance.

This is functionally fine, but calling debugbar() twice performs duplicate helper/DI lookups. Caching it locally also matches the pattern used in MessageAdapter.

♻️ Optional refactor
-        if (debugbar()->isEnabled()) {
-            debugbar()->addToStoreCell(Debugger::HOOKS, 'info', hook()->getRegistered());
+        $debugger = debugbar();
+
+        if ($debugger->isEnabled()) {
+            $debugger->addToStoreCell(Debugger::HOOKS, 'info', hook()->getRegistered());
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/App/Traits/WebAppTrait.php` around lines 103 - 104, The code calls
debugbar() twice causing duplicate helper/DI lookups; resolve and reuse the
debugger instance by storing debugbar() in a local variable (e.g., $debugbar)
and then call $debugbar->isEnabled() and
$debugbar->addToStoreCell(Debugger::HOOKS, 'info', hook()->getRegistered());
mirror the pattern used in MessageAdapter to avoid repeated lookups and keep
hook()->getRegistered() as the payload.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/App/Traits/WebAppTrait.php`:
- Around line 103-104: The code calls debugbar() twice causing duplicate
helper/DI lookups; resolve and reuse the debugger instance by storing debugbar()
in a local variable (e.g., $debugbar) and then call $debugbar->isEnabled() and
$debugbar->addToStoreCell(Debugger::HOOKS, 'info', hook()->getRegistered());
mirror the pattern used in MessageAdapter to avoid repeated lookups and keep
hook()->getRegistered() as the payload.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c2c5268e-dee7-493f-ab6c-4cf498756ebe

📥 Commits

Reviewing files that changed from the base of the PR and between e9fdf53 and ef6c704.

📒 Files selected for processing (17)
  • src/App/Stages/InitDebuggerStage.php
  • src/App/Traits/WebAppTrait.php
  • src/Logger/Adapters/MessageAdapter.php
  • src/Module/Templates/DefaultWeb/src/Views/layouts/main.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/BaseController.php.tpl
  • src/Module/Templates/DemoWeb/src/Views/layouts/main.php.tpl
  • src/Module/Templates/Toolkit/src/Controllers/BaseController.php.tpl
  • src/Module/Templates/Toolkit/src/Views/layouts/iframe.php.tpl
  • src/Module/Templates/Toolkit/src/Views/layouts/main.php.tpl
  • src/View/Factories/ViewFactory.php
  • src/View/Helpers/view.php
  • src/View/View.php
  • tests/Unit/View/Factories/ViewFactoryTest.php
  • tests/Unit/View/Helpers/ViewHelperTest.php
  • tests/Unit/View/ViewTest.php
  • tests/_root/modules/Test/Views/layout.php
  • tests/_root/modules/Test/Views/layout.twig.php

@armanist armanist requested a review from andrey-smaelov April 21, 2026 09:21
@armanist

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ 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".

@armanist armanist merged commit 5abd353 into quantum-php:master Apr 21, 2026
7 checks passed
@armanist armanist deleted the issue/459-refactor-view-helper branch April 21, 2026 09:52
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 view() Helper and Standardize QtView Class Name

2 participants