Skip to content

Improve config merge behavior and add FieldKey constants#96

Merged
dereuromark merged 1 commit intomasterfrom
feature/improve-config-merge-and-field-constants
Mar 23, 2026
Merged

Improve config merge behavior and add FieldKey constants#96
dereuromark merged 1 commit intomasterfrom
feature/improve-config-merge-and-field-constants

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

Summary

  • Fixes configuration merge to properly merge fields at the field level instead of overwriting
  • Adds FieldKey constants class to reduce magic strings throughout the codebase
  • Sorts config files alphabetically in Finder for consistent merge order

Changes

Config Merge Fix

When the same DTO is defined in multiple configuration files, fields are now properly merged:

  • Fields from all files are combined
  • If the same field is defined in multiple files, later files' attributes override earlier ones
  • Field attributes not specified in later files are preserved from earlier files

This enables modular configuration where you can:

config/dto/01-base-user.php      # Define base User DTO with all fields
config/dto/02-user-validation.php # Add validation rules to specific fields

FieldKey Constants

Introduces FieldKey class with constants for all field metadata keys:

  • FieldKey::NAME, FieldKey::TYPE, FieldKey::REQUIRED, etc.
  • FieldKey::metadataKeys() method for runtime metadata key list
  • FieldKey::defaults() method for default field values

Updated Builder, DtoValidator, and FieldCompletor to use these constants.

Finder Sorting

Files in config/dto/ directory are now sorted alphabetically to ensure:

  • Consistent merge order across different filesystems
  • Ability to control merge order with numbered prefixes

Breaking Changes

None - this is a backwards-compatible enhancement.

This commit addresses two improvements:

1. **Fix configuration merge to properly merge fields**
   - When the same DTO is defined in multiple config files, fields are now
     properly merged instead of overwritten
   - Field attributes from later files override earlier ones while preserving
     attributes not specified in later files
   - Finder now sorts files alphabetically for consistent merge order,
     allowing numbered prefixes (01-base.php, 02-override.php) to control order

2. **Add FieldKey constants class**
   - Introduces `FieldKey` class with constants for all field metadata keys
   - Reduces magic strings throughout the codebase
   - Improves IDE autocompletion and static analysis
   - Updates Builder, DtoValidator, and FieldCompletor to use these constants

Tests added for:
- Config merge preserving fields from multiple files
- DTO-level attribute merging
- Field attribute override behavior
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 94.59459% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.08%. Comparing base (6393236) to head (3ea5b24).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
src/Generator/DtoValidator.php 81.25% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master      #96      +/-   ##
============================================
+ Coverage     82.63%   83.08%   +0.45%     
- Complexity     1409     1415       +6     
============================================
  Files            40       41       +1     
  Lines          3426     3476      +50     
============================================
+ Hits           2831     2888      +57     
+ Misses          595      588       -7     

☔ 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.

@dereuromark dereuromark merged commit 1f924fd into master Mar 23, 2026
12 checks passed
@dereuromark dereuromark deleted the feature/improve-config-merge-and-field-constants branch March 23, 2026 08:39
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