Skip to content

496 remove response param in templates#497

Merged
armanist merged 8 commits intosoftberg:masterfrom
armanist:496-remove-response-param-in-templates
May 4, 2026
Merged

496 remove response param in templates#497
armanist merged 8 commits intosoftberg:masterfrom
armanist:496-remove-response-param-in-templates

Conversation

@armanist
Copy link
Copy Markdown
Member

@armanist armanist commented May 1, 2026

Closes #496

Summary by CodeRabbit

  • Refactor

    • Controllers and middleware no longer require an injected Response parameter; responses are produced via a global response() helper. Method signatures and docblocks were simplified to reduce boilerplate and preserve existing behavior and payloads.
  • Chores

    • Template metadata updated to reflect version 3.0.0 and assorted PHPDoc/comment cleanups across templates.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

Warning

Rate limit exceeded

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

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ 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: 765703b8-386c-473b-9eae-39e574106fc5

📥 Commits

Reviewing files that changed from the base of the PR and between 2402dbb and 9b93179.

📒 Files selected for processing (1)
  • src/Module/Templates/DemoWeb/src/Middlewares/Password.php.tpl
📝 Walkthrough

Walkthrough

Removed injected Response $response parameters across module templates; controllers now call the global response() helper to build HTML/JSON responses. OpenAPI abstract signatures and middleware helper signatures were updated to match. Docblocks and @since tags were adjusted accordingly.

Changes

Template-wide Response removal & helper switch

Layer / File(s) Summary
API contract (OpenAPI abstracts)
src/Module/Templates/.../OpenApi/*.php.tpl
src/Module/Templates/DefaultApi/src/Controllers/OpenApi/OpenApiMainController.php.tpl
Abstract controller method signatures updated to remove Response $response parameters (e.g., signin(Request $request, Response $response)signin(Request $request)), aligning OpenAPI contracts with runtime controllers. @since bumped where present.
Controller runtime implementations
src/Module/Templates/**/src/Controllers/**/*.php.tpl
(DefaultApi, DefaultWeb, DemoApi, DemoWeb, Toolkit controllers)
Controller action signatures updated to drop injected Response $response; internal returns changed from $response->json(...) / $response->html(...) to response()->json(...) / response()->html(...). PHPDoc param annotations referencing Response removed; some minor whitespace/docs cleaned.
Middleware validation / helpers
src/Module/Templates/**/src/Middlewares/BaseMiddleware.php.tpl, .../Middlewares/*.php.tpl
Validation and error responder signatures changed to remove Response $response from validateRequest, respondWithError, unauthorizedResponse, etc. Implementations now call response() internally and return constructed responses; method docblocks updated and @since bumped to 3.0.0 in many templates.
Docblocks / metadata / small cleanups
src/Module/Templates/** (various)
Removed stale @var and @param Response PHPDoc lines, adjusted @since tags, and made small whitespace/formatting cleanups across templates and manifest entries (composer.json references in many templates).

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Middleware as Middleware
    participant Controller as Controller
    participant Validator as Validator
    participant ResponseHelper as response()

    Client->>Middleware: HTTP request
    Middleware->>Validator: validateRequest(Request)
    alt validation fails
        Validator-->>Middleware: errors
        Middleware->>ResponseHelper: respondWithError(Request, errors)
        ResponseHelper-->>Client: JSON/HTML error
    else validation passes
        Middleware-->>Controller: forward Request
        Controller->>Controller: handle business logic
        Controller->>ResponseHelper: response()->json(...) / response()->html(...)
        ResponseHelper-->>Client: HTTP response
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • andrey-smaelov
  • live-soft
  • Arno2005

Poem

"🐰 I hopped through templates tonight,
Dropped the Response to make things light,
Helpers now conjure JSON cheer,
Docblocks trimmed, the path is clear,
Templates sing in version three-oh-oh!"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title is concise and directly references the issue number, accurately summarizing the main change (removing Response parameters from controller and middleware templates).
Linked Issues check ✅ Passed All primary coding objectives from issue #496 are met: Response parameter removed from runtime controller actions [multiple controllers], OpenAPI abstract signatures updated [OpenApiAuthController, OpenApiPostController], middleware helpers refactored to use response() [BaseMiddleware, all middleware classes].
Out of Scope Changes check ✅ Passed All changes align with issue #496 scope: removing Response parameters from controller actions and middleware, updating signatures, switching to response() helper, and updating docblocks. No unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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
Review rate limit: 0/1 reviews remaining, refill in 25 minutes and 54 seconds.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.87%. Comparing base (e8bcbb4) to head (9b93179).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #497   +/-   ##
=========================================
  Coverage     90.87%   90.87%           
  Complexity     2926     2926           
=========================================
  Files           255      255           
  Lines          7703     7703           
=========================================
  Hits           7000     7000           
  Misses          703      703           

☔ 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 May 1, 2026
@armanist armanist added this to the 3.0.0 milestone May 1, 2026
Copy link
Copy Markdown

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

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: b6e8ba0b09

ℹ️ 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/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl Outdated
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.

Actionable comments posted: 17

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl (1)

31-37: ⚠️ Potential issue | 🟠 Major

Add return statement to prevent bypassing authorization check.

The respondWithError() method returns a Response object but is not returned in the conditional block. This causes unauthorized requests to proceed to line 37, where return $next($request) forwards them through the middleware chain, bypassing the authentication check entirely.

Proposed fix
         if (!auth()->check()) {
-            $this->respondWithError($request,
+            return $this->respondWithError($request,
                 t('validation.unauthorizedRequest'),
                 StatusCode::UNAUTHORIZED
             );
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl` around lines 31 -
37, In the authorization conditional where respondWithError(...) is called,
return its Response immediately instead of falling through; update the
middleware (Auth.php.tpl) so that the branch uses "return
$this->respondWithError($request, t('validation.unauthorizedRequest'),
StatusCode::UNAUTHORIZED);" so unauthorized requests do not reach "return
$next($request)" and bypass authentication.
src/Module/Templates/DemoApi/src/Controllers/AccountController.php.tpl (1)

60-63: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Exception paths still reference removed $response variable.

Lines 60 and 86 call $response->json(...), but $response is no longer a method parameter. Error handling will crash exactly when exceptions are thrown.

Suggested fix
         } catch (AuthException $e) {
-            return $response->json([
+            return response()->json([
                 'status' => self::STATUS_ERROR,
                 'message' => $e->getMessage()
             ]);
         }
@@
         } catch (AuthException $e) {
-            return $response->json([
+            return response()->json([
                 'status' => self::STATUS_ERROR,
                 'message' => $e->getMessage()
             ]);
         }

Also applies to: 86-89

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Module/Templates/DemoApi/src/Controllers/AccountController.php.tpl`
around lines 60 - 63, The exception handlers still call the removed local
$response->json(...) and will crash; replace those calls with the controller's
response accessor (e.g. $this->response->json([...]) or the project’s standard
response helper used elsewhere in AccountController) so the exception paths
return a valid JSON response; update both occurrences (the catch blocks at the
two exception paths) to use the controller-level response helper consistently.
src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl (2)

79-83: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Undefined $response in signout error branch

Line 79 returns $response->json(...), but this method does not define $response after removing injected response parameters.

Proposed fix
-        } else {
-            return $response->json([
-                'status' => self::STATUS_ERROR,
-                'message' => t('validation.unauthorizedRequest')
-            ], StatusCode::UNAUTHORIZED);
-        }
+        }
+        return response()->json([
+            'status' => self::STATUS_ERROR,
+            'message' => t('validation.unauthorizedRequest')
+        ], StatusCode::UNAUTHORIZED);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl` around
lines 79 - 83, The signout method references an undefined $response variable in
its error branch; update that return to use the controller's available response
object (e.g. $this->response->json([...], StatusCode::UNAUTHORIZED)) or the
class response helper used elsewhere in this template so the code compiles;
modify the return in signout to use $this->response->json(...) (or the same
response helper used by other methods) instead of $response->json(...).

151-154: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Undefined $response in exception handlers

Lines 151 and 169 use $response->json(...) in verify/resend catch blocks, but $response is never initialized in those methods.

Proposed fix
-            return $response->json([
+            return response()->json([
                 'status' => self::STATUS_ERROR,
                 'message' => $e->getMessage()
             ], StatusCode::UNAUTHORIZED);

Also applies to: 169-172

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl` around
lines 151 - 154, The catch blocks in the verify and resend methods reference an
undefined $response variable; update those returns to use the framework JSON
helper (e.g., response()->json([...], StatusCode::UNAUTHORIZED)) or
alternatively accept/use the existing $response parameter from the method
signature so the code returns a valid JsonResponse; modify the exception
handlers in verify and resend to replace $response->json(...) with a valid
response factory call or the method's $response variable.
src/Module/Templates/DemoApi/src/Controllers/PostController.php.tpl (1)

99-102: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Undefined $response after removing injected parameter

Line 99 still calls $response->json(...), but $response is no longer passed or initialized in this method. This will fail on the success path.

Proposed fix
-        return $response->json([
+        return response()->json([
             'status' => 'success',
             'data' => $postData,
         ]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Module/Templates/DemoApi/src/Controllers/PostController.php.tpl` around
lines 99 - 102, The code calls $response->json(...) but $response is no longer
injected or defined; replace that call with a valid response creation (e.g. use
the framework helper or Symfony/Laravel response object) — for example change
the return to response()->json(['status' => 'success', 'data' => $postData]) or
return new JsonResponse(['status' => 'success', 'data' => $postData]) in the
controller method that currently uses $response->json so $postData is returned
correctly without relying on an undefined $response.
🧹 Nitpick comments (1)
src/Module/Templates/DemoWeb/src/Middlewares/BaseMiddleware.php.tpl (1)

63-67: 💤 Low value

Base respondWithError returns an empty response.

The default implementation returns response() with no content. While documented as "subclasses override if needed," callers like validateRequest return this value directly. If a subclass forgets to override, the caller receives an empty response with no error indication.

Consider making this method abstract or providing a minimal error response as a safer default.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Module/Templates/DemoWeb/src/Middlewares/BaseMiddleware.php.tpl` around
lines 63 - 67, The current BaseMiddleware::respondWithError returns an empty
response which can cause callers like validateRequest to return a blank response
if a subclass forgets to override; change respondWithError in BaseMiddleware
(function respondWithError) to either be declared abstract so subclasses must
implement it, or implement a safe default that returns a minimal error Response
(e.g., JSON or text body with an error message and a 4xx status code such as
400) so callers always receive a meaningful error; update method signature and
PHPDoc accordingly and ensure any subclasses implement the new abstract method
if you choose the abstract route.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Module/Templates/DefaultWeb/src/Controllers/MainController.php.tpl`:
- Around line 47-54: The index() method in MainController (function
index(ViewFactory $view)) uses an undefined $response variable; change the call
to use the global response helper instead (replace the $response->html(...)
usage with response()->html(...)) so the view rendering returns a Response
without adding a new parameter to index; update the reference near the return
statement where $view->render('index') is passed.

In
`@src/Module/Templates/DemoApi/src/Controllers/OpenApi/OpenApiAuthController.php.tpl`:
- Line 1: The template file OpenApiAuthController.php.tpl contains a UTF-8 BOM
at the start which will emit output before the PHP opening tag; remove the BOM
so the file begins exactly with "<?php" (no hidden bytes or whitespace) to
prevent premature output that can break headers/cookies/sessions when generated;
ensure your editor/saving routine writes the file as UTF-8 without BOM and
verify by opening the template in a hex-aware editor or re-saving as "UTF-8
without BOM".

In `@src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl`:
- Line 1: Remove the UTF-8 BOM that appears before the PHP opening tag in the
template: open the template file containing the leading "<?php" token
(src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl), delete the
invisible BOM character so the file starts exactly with "<?php", and re-save the
template using UTF-8 without BOM (or ensure your editor/CI enforces "UTF-8 w/o
BOM") so generated middleware files do not emit premature output.

In `@src/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl`:
- Line 1: The template file contains a UTF-8 BOM at the very start before the
PHP open tag which can cause "headers already sent" errors; open
src/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl and remove
the BOM so the file begins with "<?php" (ensure the template is saved as UTF-8
without BOM), and if your template generator writes files programmatically,
update the writer to emit UTF-8 without BOM (inspect the template source and any
writeFile/createFile routines that produce BaseMiddleware.php.tpl to ensure no
BOM is prepended).

In `@src/Module/Templates/DemoApi/src/Middlewares/Editor.php.tpl`:
- Line 1: The template file Editor.php.tpl contains a UTF-8 BOM at the start
which can break PHP output; remove the BOM so the file begins with "<?php" (no
hidden characters) and ensure the template saving/commit uses UTF-8 without BOM;
update any template generation or editor settings that produce this file
(Editor.php.tpl) to save as UTF-8 (no BOM) to prevent the BOM from appearing in
other templates.

In `@src/Module/Templates/DemoApi/src/Middlewares/PostOwner.php.tpl`:
- Line 1: The template file
Module/Templates/DemoApi/src/Middlewares/PostOwner.php.tpl (and any other
changed .tpl PHP templates) contains a UTF-8 BOM character before the "<?php"
tag which can emit output early; open each affected template (e.g.,
PostOwner.php.tpl), remove the leading BOM so the file is saved as UTF-8 without
BOM and ensure the first bytes begin with "<?php" with no invisible characters
before it, then commit the cleaned templates.

In `@src/Module/Templates/DemoApi/src/Middlewares/Reset.php.tpl`:
- Line 1: The file src/Module/Templates/DemoApi/src/Middlewares/Reset.php.tpl
contains a UTF-8 BOM at the start; remove the BOM so the file is saved as plain
UTF-8 without BOM (open Reset.php.tpl in your editor or run a tool to strip the
BOM) and commit the cleaned template so generated files will not contain the
invisible character.

In `@src/Module/Templates/DemoApi/src/Middlewares/Signout.php.tpl`:
- Around line 30-33: The handler in Signout.php.tpl calls
$this->respondWithError($request, [t('validation.nonExistingRecord','token')])
when the refresh token is missing but does not return, so execution continues
and $next($request) is invoked; fix by adding a return before the
respondWithError call (i.e., return $this->respondWithError(...)) to stop
further middleware execution and ensure the error response is returned instead
of falling through to $next($request).
- Line 1: Multiple PHP template files (e.g., Signout.php.tpl) contain a UTF-8
BOM which can emit output before "<?php" and break headers; remove the BOM bytes
(0xEF,0xBB,0xBF) from the start of each affected template so the file begins
exactly with "<?php", verify no invisible characters precede opening tag in all
listed templates across DemoApi, DemoWeb, and Toolkit modules, and re-save files
as UTF-8 without BOM before committing.

In `@src/Module/Templates/DemoWeb/src/Controllers/BaseController.php.tpl`:
- Line 1: Several PHP template files (e.g., BaseController.php.tpl) contain a
UTF-8 BOM before the opening "<?php" which emits output and breaks headers;
remove the BOM so each template begins exactly with "<?php" as the first
bytes—either re-save each file as "UTF-8 without BOM" in your editor or run a
one-off script to strip U+FEFF (e.g., delete any leading 0xEF 0xBB 0xBF) from
all 31 listed .tpl files.

In `@src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl`:
- Around line 80-81: The method signature for post(Request $request, ?string
$lang, string $postUuid) removed the $response parameter but the implementation
still calls $response->html(...), causing an undefined variable; fix by creating
or obtaining a Response instance inside post before use (e.g. $response = new
Response() or retrieve via the controller's response factory) and then call
$response->html(...); update the post method to use that local $response
variable (referencing the post function and the html call) so the runtime no
longer references an undefined $response.

In
`@src/Module/Templates/DemoWeb/src/Controllers/PostManagementController.php.tpl`:
- Line 99: The method signature for amendForm contains an extra space after the
first parameter—fix the parameter list in amendForm(Request $request,  ?string
$lang, string $postUuid) by removing the double space so it reads a single space
between $request, and ?string $lang; update the amendForm function declaration
accordingly to keep consistent spacing.

In `@src/Module/Templates/DemoWeb/src/Middlewares/Auth.php.tpl`:
- Line 1: The file src/Module/Templates/DemoWeb/src/Middlewares/Auth.php.tpl
contains a UTF-8 BOM at the very start; open Auth.php.tpl, remove the BOM
character (the invisible 0xEF 0xBB 0xBF bytes) so the file begins with "<?php"
and re-save it as UTF-8 without BOM, and also scan/update any other templates in
Module/Templates/DemoWeb (same pattern as Auth.php.tpl) to ensure they're saved
without BOM to prevent parsing issues.

In `@src/Module/Templates/DemoWeb/src/Middlewares/BaseMiddleware.php.tpl`:
- Line 1: The file
src/Module/Templates/DemoWeb/src/Middlewares/BaseMiddleware.php.tpl contains a
UTF-8 BOM before the opening PHP tag which can cause "headers already sent"
errors; remove the BOM so the file begins exactly with "<?php" (edit the
template BaseMiddleware.php.tpl and ensure there are no invisible
bytes/characters before the "<?php" token, saving the file as UTF-8 without
BOM).

In `@src/Module/Templates/DemoWeb/src/Middlewares/Guest.php.tpl`:
- Line 1: The file starts with a UTF-8 BOM before the "<?php" tag which can
break PHP parsing; remove the BOM so the file begins exactly with "<?php" and
re-save the template (Guest.php.tpl) as UTF-8 without BOM; check other template
files for the same pattern and ensure any automated editor/CI enforces saving
PHP templates without BOM to prevent this recurring.

In `@src/Module/Templates/Toolkit/src/Controllers/EmailsController.php.tpl`:
- Line 1: The template file begins with a UTF-8 BOM before the '<?php' opening
tag which can emit output early; open
src/Module/Templates/Toolkit/src/Controllers/EmailsController.php.tpl and remove
the BOM so the file starts exactly with '<?php' (save the file as UTF-8 without
BOM/UTF-8 (no BOM) in your editor) ensuring no invisible bytes precede the
'<?php' token.

In `@src/Module/Templates/Toolkit/src/Middlewares/BaseMiddleware.php.tpl`:
- Around line 40-44: The validateRequest method currently calls
$this->respondWithError(...) but does not return its Response, causing callers
like CreateTable::apply to receive null; update validateRequest in
BaseMiddleware (method validateRequest) to return the result of
$this->respondWithError(...) when validation fails (i.e., use return
$this->respondWithError(...)) so the Response is propagated to callers instead
of being dropped.

---

Outside diff comments:
In `@src/Module/Templates/DemoApi/src/Controllers/AccountController.php.tpl`:
- Around line 60-63: The exception handlers still call the removed local
$response->json(...) and will crash; replace those calls with the controller's
response accessor (e.g. $this->response->json([...]) or the project’s standard
response helper used elsewhere in AccountController) so the exception paths
return a valid JSON response; update both occurrences (the catch blocks at the
two exception paths) to use the controller-level response helper consistently.

In `@src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl`:
- Around line 79-83: The signout method references an undefined $response
variable in its error branch; update that return to use the controller's
available response object (e.g. $this->response->json([...],
StatusCode::UNAUTHORIZED)) or the class response helper used elsewhere in this
template so the code compiles; modify the return in signout to use
$this->response->json(...) (or the same response helper used by other methods)
instead of $response->json(...).
- Around line 151-154: The catch blocks in the verify and resend methods
reference an undefined $response variable; update those returns to use the
framework JSON helper (e.g., response()->json([...], StatusCode::UNAUTHORIZED))
or alternatively accept/use the existing $response parameter from the method
signature so the code returns a valid JsonResponse; modify the exception
handlers in verify and resend to replace $response->json(...) with a valid
response factory call or the method's $response variable.

In `@src/Module/Templates/DemoApi/src/Controllers/PostController.php.tpl`:
- Around line 99-102: The code calls $response->json(...) but $response is no
longer injected or defined; replace that call with a valid response creation
(e.g. use the framework helper or Symfony/Laravel response object) — for example
change the return to response()->json(['status' => 'success', 'data' =>
$postData]) or return new JsonResponse(['status' => 'success', 'data' =>
$postData]) in the controller method that currently uses $response->json so
$postData is returned correctly without relying on an undefined $response.

In `@src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl`:
- Around line 31-37: In the authorization conditional where
respondWithError(...) is called, return its Response immediately instead of
falling through; update the middleware (Auth.php.tpl) so that the branch uses
"return $this->respondWithError($request, t('validation.unauthorizedRequest'),
StatusCode::UNAUTHORIZED);" so unauthorized requests do not reach "return
$next($request)" and bypass authentication.

---

Nitpick comments:
In `@src/Module/Templates/DemoWeb/src/Middlewares/BaseMiddleware.php.tpl`:
- Around line 63-67: The current BaseMiddleware::respondWithError returns an
empty response which can cause callers like validateRequest to return a blank
response if a subclass forgets to override; change respondWithError in
BaseMiddleware (function respondWithError) to either be declared abstract so
subclasses must implement it, or implement a safe default that returns a minimal
error Response (e.g., JSON or text body with an error message and a 4xx status
code such as 400) so callers always receive a meaningful error; update method
signature and PHPDoc accordingly and ensure any subclasses implement the new
abstract method if you choose the abstract route.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bff22cdc-1744-44f0-a5f4-572c0eaff874

📥 Commits

Reviewing files that changed from the base of the PR and between e8bcbb4 and b6e8ba0.

📒 Files selected for processing (56)
  • src/Module/Templates/DefaultApi/src/Controllers/MainController.php.tpl
  • src/Module/Templates/DefaultApi/src/Controllers/OpenApi/OpenApiMainController.php.tpl
  • src/Module/Templates/DefaultWeb/src/Controllers/MainController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/AccountController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/BaseController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/CommentController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/OpenApi/OpenApiAuthController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/OpenApi/OpenApiPostController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/PostController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/PostManagementController.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Activate.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Comment.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/CommentOwner.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Editor.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Forget.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Password.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/PostOwner.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Resend.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Reset.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Signout.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Signup.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Update.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Verify.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/AccountController.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/AuthController.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/BaseController.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/CommentController.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/PageController.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/PostManagementController.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Activate.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Auth.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/BaseMiddleware.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Comment.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/CommentOwner.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Editor.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Forget.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Guest.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Password.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/PostOwner.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Resend.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Reset.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Signup.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Update.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Verify.php.tpl
  • src/Module/Templates/Toolkit/src/Controllers/BaseController.php.tpl
  • src/Module/Templates/Toolkit/src/Controllers/DashboardController.php.tpl
  • src/Module/Templates/Toolkit/src/Controllers/DatabaseController.php.tpl
  • src/Module/Templates/Toolkit/src/Controllers/EmailsController.php.tpl
  • src/Module/Templates/Toolkit/src/Controllers/LogsController.php.tpl
  • src/Module/Templates/Toolkit/src/Middlewares/BaseMiddleware.php.tpl
  • src/Module/Templates/Toolkit/src/Middlewares/BasicAuth.php.tpl
  • src/Module/Templates/Toolkit/src/Middlewares/CreateTable.php.tpl
💤 Files with no reviewable changes (2)
  • src/Module/Templates/DemoApi/src/Controllers/BaseController.php.tpl
  • src/Module/Templates/Toolkit/src/Controllers/BaseController.php.tpl

Comment thread src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl Outdated
Comment thread src/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl Outdated
Comment thread src/Module/Templates/DemoApi/src/Middlewares/Editor.php.tpl Outdated
Comment thread src/Module/Templates/DemoWeb/src/Middlewares/Auth.php.tpl Outdated
Comment thread src/Module/Templates/DemoWeb/src/Middlewares/BaseMiddleware.php.tpl Outdated
Comment thread src/Module/Templates/DemoWeb/src/Middlewares/Guest.php.tpl Outdated
Comment thread src/Module/Templates/Toolkit/src/Controllers/EmailsController.php.tpl Outdated
Comment thread src/Module/Templates/Toolkit/src/Middlewares/BaseMiddleware.php.tpl Outdated
Comment thread src/Module/Templates/Toolkit/src/Middlewares/BaseMiddleware.php.tpl Outdated
Comment thread src/Module/Templates/Toolkit/src/Middlewares/BasicAuth.php.tpl Outdated
@armanist armanist requested a review from andrey-smaelov May 4, 2026 08:12
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl (1)

31-35: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Return the unauthorized response to prevent auth bypass.

On Line 31, the middleware builds an error response but does not return it, so execution falls through to Line 37 and allows unauthorized access.

Suggested fix
         if (!auth()->check()) {
-            $this->respondWithError($request,
+            return $this->respondWithError($request,
                 t('validation.unauthorizedRequest'),
                 StatusCode::UNAUTHORIZED
             );
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl` around lines 31 -
35, The middleware calls $this->respondWithError(...) but does not return it,
allowing execution to continue and potentially bypass auth; modify the Auth
middleware to return the response from respondWithError (i.e., add a return
before $this->respondWithError(...)) so the request pipeline halts on
unauthorized, ensuring the method (in Auth.php.tpl) exits immediately when
StatusCode::UNAUTHORIZED is triggered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl`:
- Around line 31-35: The middleware calls $this->respondWithError(...) but does
not return it, allowing execution to continue and potentially bypass auth;
modify the Auth middleware to return the response from respondWithError (i.e.,
add a return before $this->respondWithError(...)) so the request pipeline halts
on unauthorized, ensuring the method (in Auth.php.tpl) exits immediately when
StatusCode::UNAUTHORIZED is triggered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: af9aca82-5d90-449c-b193-ea4ead1334ba

📥 Commits

Reviewing files that changed from the base of the PR and between b6e8ba0 and 2402dbb.

📒 Files selected for processing (39)
  • src/Module/Templates/DefaultWeb/src/Controllers/MainController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/AccountController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/CommentController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/OpenApi/OpenApiAuthController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/OpenApi/OpenApiPostController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/PostController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/PostManagementController.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Activate.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Auth.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Comment.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Editor.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Forget.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Password.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/PostOwner.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Resend.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Reset.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Signout.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Signup.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Update.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Verify.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/BaseController.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/CommentController.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/PostManagementController.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Auth.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/BaseMiddleware.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Editor.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Forget.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Guest.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Resend.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Reset.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Signup.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Update.php.tpl
  • src/Module/Templates/Toolkit/src/Controllers/EmailsController.php.tpl
  • src/Module/Templates/Toolkit/src/Middlewares/BaseMiddleware.php.tpl
  • src/Module/Templates/Toolkit/src/Middlewares/BasicAuth.php.tpl
  • src/Module/Templates/Toolkit/src/Middlewares/CreateTable.php.tpl
💤 Files with no reviewable changes (2)
  • src/Module/Templates/DemoWeb/src/Controllers/BaseController.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/CommentController.php.tpl
✅ Files skipped from review due to trivial changes (5)
  • src/Module/Templates/DemoWeb/src/Middlewares/Guest.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Signup.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Forget.php.tpl
  • src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl
🚧 Files skipped from review as they are similar to previous changes (16)
  • src/Module/Templates/DemoApi/src/Middlewares/Verify.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Update.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/BaseMiddleware.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/CommentController.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Auth.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Update.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Forget.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Resend.php.tpl
  • src/Module/Templates/DemoWeb/src/Middlewares/Editor.php.tpl
  • src/Module/Templates/Toolkit/src/Middlewares/CreateTable.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/AccountController.php.tpl
  • src/Module/Templates/Toolkit/src/Controllers/EmailsController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/PostManagementController.php.tpl
  • src/Module/Templates/DemoApi/src/Controllers/PostController.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/BaseMiddleware.php.tpl
  • src/Module/Templates/DemoApi/src/Middlewares/Activate.php.tpl

@armanist armanist merged commit 28a6bd9 into softberg:master May 4, 2026
7 checks passed
@armanist armanist deleted the 496-remove-response-param-in-templates branch May 4, 2026 09:19
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 module templates to remove Response action args and use response() helper

2 participants