Skip to content

Layer the code as actions, services and support - #8

Merged
imanimanyara merged 14 commits into
mainfrom
refactor/actions-services-support
Nov 10, 2026
Merged

imanimanyara merged 14 commits into
mainfrom
refactor/actions-services-support

Conversation

@imanimanyara

Copy link
Copy Markdown
Member

Summary

This lays the code out as entry points → actions → services → support, following the plan written from an inventory of src/. Behaviour, messages and audit entries are unchanged, and nothing public is removed.

  • Support (one implementation of duplicated logic):

    • Json and Translations replace 5 copies of the title/JSON encoding.
    • DatabaseValues::boolean() replaces 5 copies of the [true, 1, '1'] check.
    • Scope::of(), Scope::fromString() and Scope::owner() replace 7 copies of scope parsing.
    • ConfigValues collects the provider's typed config readers and the strict list check.
    • AuditedTransaction is the single implementation of: transaction, allowed entry, rollback, failed entry, rethrow. Every write, category change and promotion uses it.
  • Services (database work moved out of actions):

    • Database\AuditRepository takes the audit sink, query and prune.
    • Database\DefinitionsRepository takes the definitions sync and reads.
    • Database\SchemaInspector takes doctor and install's foreign-table check.
    • Tenancy\TenantDiscriminators takes the stancl and spatie adapters, out of the service provider.
    • Store::requireDatabase() and CategoryRepository::of() replace three copies of the same lookup and error.
  • Actions: FindOrphans split from PruneOrphans.

  • Guards: architecture tests check that:

    • an action's only public method is handle();
    • actions never touch the connection or the schema builder;
    • only entry points depend on actions;
    • support classes are readonly.

    Every exemption states its reason and fails if it goes stale. Every scan checks it read at least a minimum number of files. All five failure modes were proven red.

Deprecated (both still work and forward)

  • PruneOrphans::find() → FindOrphans::handle() (removal: 1.0)
  • DatabaseDefinitions::localised() → Translations::nullableText() (removal: 1.0). It differs only for a malformed JSON map whose '' entry is not a string.

Kept on purpose

  • WriteGuard and CategoryGuard stay in Actions/ and delegate to AuditedTransaction. Each still holds its own logic (approval and lock override; repository and events), so moving them would only rename public classes.
  • QueryAudit stays an action. It is now authorize + AuditRepository, and splitting its three result shapes would change public signatures.
  • Large classes (SettingsManager, DatabaseDriver, the provider) are not split by size alone.

Testing

vendor/bin/pest: 465 passed. Coverage 97.5%. PHPStan at max level: no errors. Rector and Pint are clean. MySQL and PostgreSQL run in CI.

Support\Json (the package's JSON flags and its encode error) and Support\Translations (the
lang/json title format) replace the copies in CategoryRepository, SyncDefinitions,
DatabaseDefinitions, DatabaseAuditSink and the category factory. DatabaseDefinitions::localised()
stays and forwards, deprecated.
DatabaseValues::boolean() replaces five copies of the [true, 1, '1'] check. Scope gains of(),
fromString() and owner(), which replace the scope parsing copied in DatabaseDriver,
RecordSerializer and QueryAudit and the owner-to-scope helpers in SettingsManager and
SettingWriter. Behaviour is unchanged: a malformed stored scope still raises each caller's
DriverFailure, an invalid alias still raises InvalidIdentifier.
The provider's lenient string, integer, array and strings readers and StoreRegistry's strict
list-of-strings check now live in one class; their call sites and messages are unchanged.
DatabaseAuditSink, QueryAudit and PruneAudit no longer build queries on the audit table; the
row format, tenant filter, store fallback and prune live in Database\AuditRepository. Moved
verbatim; behaviour is unchanged.
SyncDefinitions keeps the authorization, the per-store loop and the audit entry; the upsert,
conflict check, removal and runtime-row query move verbatim to Database\DefinitionsRepository,
which DatabaseDefinitions reads through too.
doctor's column, id-type and cross-store category checks and install's foreign-table check
read the database through Database\SchemaInspector instead of the schema builder directly.
A failed introspection still reports nothing rather than a finding.
The stancl and spatie adapters and the auto/null/class choice move out of the service provider
verbatim; the provider only binds the result.
PromoteStore, CategoryGuard and CategoryManager each looked the layer up and built the same
StoreNotWritable message; they now share one method, and CategoryRepository::of() builds a
store's repository. Messages are unchanged.
WriteGuard, CategoryGuard and PromoteStore each wrapped their work in the same transaction,
allowed-entry, rollback, failed-entry, rethrow sequence. Support\AuditedTransaction is that
sequence once; the three keep their constructors, their public methods and their audit
entries (actions, outcomes, versions, meta and reasons are unchanged).
PruneOrphans had two public intents. FindOrphans::handle() finds (moved verbatim) and
PruneOrphans::handle() removes what it finds; PruneOrphans::find() stays, deprecated, and
forwards. The prune-orphans command lists through FindOrphans.
Arch tests: an action's only public method is handle(); actions do not touch the connection
or schema builder; only entry points import actions; support classes are readonly. Each
exemption names its reason and fails when stale; each scan asserts how many files it read.
RecordSerializer and ValueEncoder, which hold no state, are declared readonly.
Copilot AI balanced review requested due to automatic review settings November 10, 2026 01:32

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Under --parallel Pest honours only the first --exclude-group, and the comma-separated
--exclude-group=matrix,shared-app excluded nothing, so the tests that publish into the shared
testbench application raced the others on config/laranail/settings.php (reproduced locally in
2 runs of 3). Both groups now also carry group mutation-excluded, which the job excludes; the
run is 433 tests, stable over repeated parallel runs.
@imanimanyara
imanimanyara merged commit b870695 into main Nov 10, 2026
15 checks passed
@imanimanyara
imanimanyara deleted the refactor/actions-services-support branch November 11, 2026 17:52
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.

2 participants