Skip to content

refactor(php): migrate go_cli_helpers + 27 callers to core.E (Mantis …#6

Merged
Snider merged 2 commits intomainfrom
dev
May 1, 2026
Merged

refactor(php): migrate go_cli_helpers + 27 callers to core.E (Mantis …#6
Snider merged 2 commits intomainfrom
dev

Conversation

@Snider
Copy link
Copy Markdown
Contributor

@Snider Snider commented May 1, 2026

…#1283)

  • go_cli_helpers.go: drop backtick-quoted fmt/strings imports
  • phpFailure/phpWrapMessage/phpWrapAction now use core.E + core.Sprintf instead of fmt.Errorf
  • strings.HasPrefix/TrimPrefix → core.HasPrefix/TrimPrefix
  • strings.Cut(body, "=") → phpCutOnEquals helper using core.SplitN
  • strings.ToLower → core.Lower
  • 27 callers using phpFailure(cliWrapErrorFormat, msg, err) now use core.E("php", msg, err) directly (cleaner — no format-string indirection for the wrapped-error path)
  • 4 remaining direct phpFailure("...%w...", err) sites converted to core.E with explicit cause (core.Sprintf doesn't support %w)

Verification:

  • GOWORK=off go build ./... clean
  • GOWORK=off go test -count=1 -short ./pkg/php/ pass

Closes tasks.lthn.sh/view.php?id=1283

Pull Request

Description

Please provide a clear description of your changes and the motivation behind them.

Fixes # (issue)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • Test improvements

Testing

Please describe the tests you ran to verify your changes:

  • Test A
  • Test B

Test Configuration:

  • PHP Version:
  • Laravel Version:
  • Database:

Checklist

  • My code follows the project's coding standards (PSR-12)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published
  • I have updated the CHANGELOG.md file
  • I have checked my code for security vulnerabilities

Screenshots (if applicable)

Add screenshots to help explain your changes.

Breaking Changes

If this PR introduces breaking changes, please describe:

  1. What breaks:
  2. Why it's necessary:
  3. Migration path:

Additional Notes

Add any other context about the pull request here.


For Maintainers:

  • Code reviewed
  • Tests passing
  • Documentation updated
  • Changelog updated
  • Ready to merge

Summary by CodeRabbit

  • Refactor
    • Updated error handling across all PHP command handlers (deployment, development, build, packages, and CI operations) to use standardised error wrapping for more consistent error reporting.
    • Refactored internal helper functions to use core utilities for string operations and error construction, replacing previous custom implementations.

…#1283)

- go_cli_helpers.go: drop backtick-quoted `fmt`/`strings` imports
- phpFailure/phpWrapMessage/phpWrapAction now use core.E + core.Sprintf
  instead of fmt.Errorf
- strings.HasPrefix/TrimPrefix → core.HasPrefix/TrimPrefix
- strings.Cut(body, "=") → phpCutOnEquals helper using core.SplitN
- strings.ToLower → core.Lower
- 27 callers using `phpFailure(cliWrapErrorFormat, msg, err)` now use
  `core.E("php", msg, err)` directly (cleaner — no format-string indirection
  for the wrapped-error path)
- 4 remaining direct phpFailure("...%w...", err) sites converted to core.E
  with explicit cause (core.Sprintf doesn't support %w)

Verification:
- GOWORK=off go build ./...                       clean
- GOWORK=off go test -count=1 -short ./pkg/php/  pass

Closes tasks.lthn.sh/view.php?id=1283
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

Warning

Rate limit exceeded

@Snider has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 36 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 200c4b05-633b-49e8-81d9-91310f46a9c0

📥 Commits

Reviewing files that changed from the base of the PR and between 6e70b0d and f6c5172.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml
  • pint.json
📝 Walkthrough

Walkthrough

The PHP package's error handling is being standardised across all command handlers and utility functions. The old phpFailure helper pattern is systematically replaced with a unified core.E("php", ...) error wrapper, and string/error utilities are refactored to use core functions instead of fmt and strings packages.

Changes

Cohort / File(s) Summary
Helper Function Refactoring
go/pkg/php/go_cli_helpers.go, go/pkg/php/packages.go
Refactored phpFailure, phpWrapMessage, and phpWrapAction to construct errors using core.E("php", ...) and core.Sprintf instead of fmt.Errorf. Updated phpSplitFlag to use core.HasPrefix, core.TrimPrefix, and a new phpCutOnEquals helper via core.SplitN. Boolean flag parsing now uses core.Lower instead of strings.ToLower.
Command Error Handling Standardisation
go/pkg/php/cmd.go, go/pkg/php/cmd_build.go, go/pkg/php/cmd_ci.go, go/pkg/php/cmd_deploy.go, go/pkg/php/cmd_dev.go, go/pkg/php/cmd_packages.go
Replaced all instances of phpFailure(cliWrapErrorFormat, ...) error returns with core.E("php", ...) across all CLI command handlers (activation, build, CI, deployment, development, and package management operations). Localised message keys and error parameters remain unchanged.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.70% 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 pull request title accurately summarizes the main change: migrating PHP error handling from phpFailure/fmt-based approaches to core.E error wrapper.
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.


Review rate limit: 0/5 reviews remaining, refill in 36 seconds.

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

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 (2)
go/pkg/php/cmd_dev.go (1)

43-47: 💤 Low value

Consider using i18n key for consistency.

This error uses a hardcoded English string, whereas similar os.Getwd() failures in other files (e.g., cmd_ci.go line 90) use phpT(i18nFailGetKey, workingDirectorySubject).

♻️ Optional: Use i18n pattern
 cwd, err := os.Getwd()
 if err != nil {
-  return core.E("php", "failed to get working directory", err)
+  return core.E("php", phpT(i18nFailGetKey, workingDirectorySubject), err)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@go/pkg/php/cmd_dev.go` around lines 43 - 47, The error message in runPHPDev
uses a hardcoded English string; replace it to use the i18n helper so messages
are consistent by calling phpT(i18nFailGetKey, workingDirectorySubject) instead
of the literal "failed to get working directory" when returning core.E in
runPHPDev.
go/pkg/php/cmd.go (1)

118-120: 💤 Low value

Consider using i18n key for consistency.

The error message uses a hardcoded English string, whereas other files in this PR use the phpT(i18nFailGetKey, ...) pattern for similar directory-related errors. This is a minor inconsistency that could be aligned for localisation support.

♻️ Optional: Use i18n pattern
 if err := os.Chdir(targetDir); err != nil {
-  return core.E("php", "failed to change directory to active package", err)
+  return core.E("php", phpT(i18nFailGetKey, "active package directory"), err)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@go/pkg/php/cmd.go` around lines 118 - 120, Replace the hardcoded error string
in the os.Chdir error handling with the i18n helper used elsewhere: call
phpT(i18nFailGetKey, "failed to change directory to active package", targetDir)
(or the appropriate phpT invocation pattern used across the PR) and pass that
resulting message into core.E("php", ..., err) instead of the literal string;
update the os.Chdir error branch (the block that currently calls core.E("php",
"failed to change directory to active package", err)) to use phpT and include
targetDir for context.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@go/pkg/php/cmd_dev.go`:
- Around line 43-47: The error message in runPHPDev uses a hardcoded English
string; replace it to use the i18n helper so messages are consistent by calling
phpT(i18nFailGetKey, workingDirectorySubject) instead of the literal "failed to
get working directory" when returning core.E in runPHPDev.

In `@go/pkg/php/cmd.go`:
- Around line 118-120: Replace the hardcoded error string in the os.Chdir error
handling with the i18n helper used elsewhere: call phpT(i18nFailGetKey, "failed
to change directory to active package", targetDir) (or the appropriate phpT
invocation pattern used across the PR) and pass that resulting message into
core.E("php", ..., err) instead of the literal string; update the os.Chdir error
branch (the block that currently calls core.E("php", "failed to change directory
to active package", err)) to use phpT and include targetDir for context.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 43ffb6a2-af51-4ca4-879e-cbcdc113459e

📥 Commits

Reviewing files that changed from the base of the PR and between 4d44a4e and 6e70b0d.

📒 Files selected for processing (8)
  • go/pkg/php/cmd.go
  • go/pkg/php/cmd_build.go
  • go/pkg/php/cmd_ci.go
  • go/pkg/php/cmd_deploy.go
  • go/pkg/php/cmd_dev.go
  • go/pkg/php/cmd_packages.go
  • go/pkg/php/go_cli_helpers.go
  • go/pkg/php/packages.go

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

@Snider Snider merged commit bfa6fbf into main May 1, 2026
15 of 19 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.

1 participant