Skip to content

refactor: extract HasResourceFields trait (closes #135 after merge)#175

Merged
ginkelsoft-development merged 1 commit into
developfrom
refactor/extract-resource-fields-trait
May 12, 2026
Merged

refactor: extract HasResourceFields trait (closes #135 after merge)#175
ginkelsoft-development merged 1 commit into
developfrom
refactor/extract-resource-fields-trait

Conversation

@ginkelsoft-development

Copy link
Copy Markdown
Owner

Vierde en laatste decomposition stap voor #135

Volgt op PR #172 (HasResourceActions), PR #173 (HasResourceNavigation), PR #174 (HasResourceQuery).

Na merge van alle vier de PRs: #135 is volledig opgelost. BuildoraResource is gestript van ~355 regels naar ~150, met elke concern in eigen trait + dedicated tests.

Wijziging

src/Resources/Concerns/HasResourceFields.php (nieuw) bevat 4 methodes voor field state management:

Method Doel
fill(Model) Populate field values/displayValues vanuit model
setFields(array) Replace field collection met type-validation
getFields() Read field collection met defensieve Field-check
resolveFields(\$model) Re-prepare via FieldManager voor een specifiek model

BuildoraResource gebruikt nu use HasResourceFields;. De abstract defineFields(): array blijft bewust op BuildoraResource — een abstract hook in een trait is moeilijker te ontdekken door IDEs (geen "implement me" suggestion bij class extension), en is conceptueel de definiërende eigenschap van de resource.

State access

De trait leest/schrijft \$this->fields en \$this->parentModel — beide protected properties op BuildoraResource. PHP staat dit toe zonder herdeclaratie.

Tests — 7 tests, 16 asserties

Behavioural (5)

  • getFields() returnt de declared fields
  • fill(\$model) zet field-value op de model-attribute (sqlite-backed)
  • setFields() gooit BuildoraException op non-Field entries
  • setFields() accepteert valid Field[] array
  • resolveFields(\$model) re-prepared fields voor een specifiek model

Structural (2)

  • BuildoraResource gebruikt de trait
  • ✓ Source-grep: 4 methodes absent uit BuildoraResource.php, present in trait

Eindstand #135

PR Concern Methods Open
#172 HasResourceActions 6
#173 HasResourceNavigation 4
#174 HasResourceQuery 2
deze HasResourceFields 4

Totaal: 16 methodes uit BuildoraResource gemoved, elk in een trait waar ze conceptueel thuishoren. Bij het lezen van BuildoraResource zelf zie je alleen nog: constructor, state declarations, model resolution glue (getModelInstance/getModelClass/relation panels), detail-view configuratie, en de abstract defineFields() hook.

Closes #135 (na merge van #172, #173, #174 én deze)

Fourth and final decomposition step for #135. After this, every
overridable resource hook lives in a dedicated trait under
Resources\Concerns and the BuildoraResource class itself shrinks from
~355 lines to ~150 — covering only constructor, state declarations,
model resolution, panel relations, detail-view configuration and the
abstract defineFields() contract.

This PR moves four methods covering field state management into
Resources\Concerns\HasResourceFields:

  - fill(Model)           — populate every field's value/displayValue
                            from a model
  - setFields(array)      — replace the field collection with
                            type validation
  - getFields()           — read the field collection with the same
                            defensive Field-type check
  - resolveFields($model) — re-prepare the fields for a specific model
                            via FieldManager::prepare

The abstract defineFields(): array contract stays on BuildoraResource.
Abstract hooks declared via a trait are harder to discover (PHPStorm
doesn't surface them as 'implement me' candidates when you extend the
class), and the subclass-implementation contract is the resource's
defining feature — it belongs on the resource itself.

State access: the trait reads/writes $this->fields and
$this->parentModel, both protected properties declared on
BuildoraResource. PHP allows that without re-declaration in the trait.

Tests (7):
  - getFields() returns the declared fields
  - fill() sets the value on the field from the model attribute
  - setFields() throws BuildoraException on non-Field entries
  - setFields() accepts a valid Field[] array
  - resolveFields($model) re-prepares fields for that model
  - BuildoraResource uses the trait (reflection)
  - Source-grep both files: methods present in the trait, absent from
    BuildoraResource.php. defineFields stays on the resource (abstract).

After #172, #173, #174 and this PR are merged, #135 is closed.

Refs #135
@ginkelsoft-development
ginkelsoft-development force-pushed the refactor/extract-resource-fields-trait branch from a4916f9 to a05a8bf Compare May 12, 2026 13:15
@ginkelsoft-development
ginkelsoft-development merged commit 8ab0bbe into develop May 12, 2026
11 of 12 checks passed
@ginkelsoft-development
ginkelsoft-development deleted the refactor/extract-resource-fields-trait branch May 12, 2026 13:15
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