whisper-money/app/Http/Controllers/Settings
Víctor Falcón 6803f2cf0e
refactor(accounts): split store/update in the account controller (#776)
## Why

`Settings\AccountController` held two of the remaining complexity
offenders — `store` at **16** and `update` at **11** — and the two
clones jscpd reports inside the file:

```
AccountController.php [75:9 - 83:47]  ↔  [201:9 - 209:47]   (the nine real-estate fields)
AccountController.php [115:9 - 125:35] ↔ [217:9 - 227:35]   (the three loan fields)
```

Both actions were doing four jobs at once: map the request onto columns,
create or update the type-specific detail row, backfill balance history,
and answer.

## What changed

**The shared mapping** — `accountAttributes()`, `realEstateAttributes()`
and `loanAttributes()`, used by both actions. That is both clones gone.

**`store`'s type-specific work** moves out:

| new method | job |
|---|---|
| `createRealEstateDetail()` | the detail row + its balance history |
| `createLoanDetail()` | the detail row + its balance history |
| `linkToRealEstateAccount()` | points the property back at its new
mortgage |
| `backfillHistoricalBalances()` | "last twelve months now, older on the
queue" — both paths ended in this same dance |

**`update`'s loan branch** (`syncLoanDetail()`) returns the missing
fields instead of `return to_route(...)->withErrors(...)` from inside a
nested `else`, so the redirect decision stays in the action.

## Metrics

| | before | after |
|---|---|---|
| methods over complexity 10 | 30 | 28 |
| `store` | 16 | 5 |
| `update` | 11 | 4 |
| clones in this file | 2 | 0 |

## Testing

`AccountControllerTest`, `LoanTest`, `RealEstateTest`,
`RealEstateAvailabilityTest`, `AccountBalanceControllerTest`,
`AccountUserCurrencyServiceTest` — 148 tests green. PHPStan clean.

Three of the branches I moved had no coverage, so this adds it:

- creating a loan that started four years ago **queues**
`GenerateHistoricalLoanBalancesJob` and still writes the recent balances
inline (so the chart is not empty while the queue catches up)
- one that started two months ago queues **nothing** — the `isBefore`
condition that is the whole point of `backfillHistoricalBalances`
- adding loan details with only one of the three required fields comes
back with errors on the other two and writes no row. Worth noting these
errors come from the controller, not the request: `loanDetailRules()`
marks all three `nullable`.

The mortgage back-link was already covered by `LoanTest`.
2026-08-11 13:58:47 +00:00
..
AccountController.php refactor(accounts): split store/update in the account controller (#776) 2026-08-11 13:58:47 +00:00
AutomationRuleApplicationController.php fix(security): scope job-status endpoints to owner + feature-area fixes (#627) 2026-07-03 14:49:32 +02:00
AutomationRuleController.php Apply automation rules to existing transactions (#413) 2026-05-22 08:36:18 +02:00
BankController.php refactor(banks): add Bank::availableForUser scope (#480) 2026-06-03 17:59:24 +02:00
CategoryController.php feat: enable category tree for all users, remove flag (#488) 2026-06-04 13:44:57 +02:00
ChartColorSchemeController.php Add chart color scheme setting (#101) 2026-02-28 12:58:21 +01:00
LabelController.php refactor(api): standardize serialization via model $hidden (#492) 2026-06-05 13:57:34 +02:00
McpTokenController.php feat(mcp): add OAuth 2.1 for Claude Desktop & ChatGPT connectors (Phase 3) (#691) 2026-07-17 19:10:48 +02:00
NetWorthChartLoanPreferenceController.php fix(dashboard): treat loans as debt in net worth (#238) 2026-03-20 09:55:53 +00:00
NetWorthChartRealEstatePreferenceController.php feat(accounts): add real estate asset tracking (#241) 2026-03-24 10:21:32 +00:00
NotificationPreferenceController.php fix(budgets): keep per-transaction email notifications opt-in (#735) 2026-07-25 12:36:13 +02:00
PasswordController.php Set up a fresh Laravel app 2025-11-07 12:01:36 +00:00
ProfileController.php feat(budgets): add per-budget email notifications (#731) 2026-07-24 12:52:03 +02:00
TimezoneController.php fix(user): persist detected timezones (#296) 2026-04-16 11:36:57 +01:00
TwoFactorAuthenticationController.php Set up a fresh Laravel app 2025-11-07 12:01:36 +00:00