Skip to content

HQD-104: add asJson method to return JSON response in Action class#345

Merged
SilverFire merged 1 commit into
hiqdev:masterfrom
tafid:HQD-104
May 15, 2026
Merged

HQD-104: add asJson method to return JSON response in Action class#345
SilverFire merged 1 commit into
hiqdev:masterfrom
tafid:HQD-104

Conversation

@tafid
Copy link
Copy Markdown
Member

@tafid tafid commented May 14, 2026

Summary by CodeRabbit

  • New Features
    • Added a helper method to streamline JSON response handling in actions, reducing boilerplate code when returning JSON data.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

📝 Walkthrough

Walkthrough

Added a public asJson() helper method to the Action class that simplifies generating JSON responses from controller actions. The method accepts optional data, configures the controller's response format to JSON, assigns the data payload, and returns the response object.

Changes

JSON Response Helper

Layer / File(s) Summary
JSON response helper method
src/actions/Action.php
Import of yii\web\Response and new public asJson(array $data = []): Response method that configures the controller response to JSON format with the provided data payload and returns the response.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A helper so tidy, so neat and so small,
Makes JSON responses a breeze after all,
Just pass in your data and watch it take flight—
From Action to Response, a hop-skip-jump right! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 change: adding an asJson method to the Action class for JSON responses.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

Copy link
Copy Markdown

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

Adds a JSON response helper to the base hipanel\actions\Action class so action implementations can return JSON responses directly.

Changes:

  • Imports yii\web\Response.
  • Adds Action::asJson() to set response format/data and return the response object.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/actions/Action.php
]);
}

public function asJson(array $data = []): Response
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/actions/Action.php (1)

320-327: ⚡ Quick win

Consider adding PHPDoc for consistency.

Most other public methods in this class include PHPDoc comments. Consider adding documentation to maintain consistency with the existing code style.

📝 Suggested PHPDoc
+    /**
+     * Creates a JSON response with the provided data.
+     *
+     * `@param` array $data The data to be sent in the response
+     * `@return` Response The configured response object
+     */
     public function asJson(array $data = []): Response
     {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/actions/Action.php` around lines 320 - 327, Add a PHPDoc block for the
public method asJson(array $data = []): Response to match the rest of the class
style; document the method purpose, the parameter $data (array), and the return
type Response, and include any relevant tags like `@param` and `@return` above the
asJson method that operates on $this->controller->response and sets
Response::FORMAT_JSON.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/actions/Action.php`:
- Around line 320-327: Add a PHPDoc block for the public method asJson(array
$data = []): Response to match the rest of the class style; document the method
purpose, the parameter $data (array), and the return type Response, and include
any relevant tags like `@param` and `@return` above the asJson method that operates
on $this->controller->response and sets Response::FORMAT_JSON.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6671c6ac-cb20-4eef-a02c-8c1c57f88181

📥 Commits

Reviewing files that changed from the base of the PR and between 8b885f5 and 85cac5e.

📒 Files selected for processing (1)
  • src/actions/Action.php

@SilverFire SilverFire merged commit 7429014 into hiqdev:master May 15, 2026
5 of 7 checks passed
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.

3 participants