Skip to content

Introduce DefaultValuesStrategy for constructor & property defaults#601

Merged
veewee merged 1 commit intophpro:v5.xfrom
veewee:consistent-default-values-code-generator
Feb 27, 2026
Merged

Introduce DefaultValuesStrategy for constructor & property defaults#601
veewee merged 1 commit intophpro:v5.xfrom
veewee:consistent-default-values-code-generator

Conversation

@veewee
Copy link
Contributor

@veewee veewee commented Feb 27, 2026

Summary

  • Add ScalarDefaultProvider that determines type-appropriate defaults for properties ('', 0, false, 0.0, [], null)
  • Add DefaultValuesStrategy enum (None, OptionalOnly, All) to control default value behavior
  • Add withDefaultValues() option to both ConstructorAssembler and PropertyAssembler, replacing the separate PropertyDefaultsAssembler
  • Add withOptionalValue() option to ConstructorAssembler, forcing all parameters to ?Type = null
  • Remove PropertyDefaultsAssembler (functionality folded into PropertyAssembler)
  • Automatic reordering of constructor parameters so those with defaults come last

Default behavior

The default strategy is OptionalOnly: only WSDL-optional/nullable properties receive = null. This prevents required properties from silently getting defaults like = '' or = 0, which would allow constructing objects without providing them.

Users can opt into the previous "all scalars get defaults" behavior with DefaultValuesStrategy::All, or disable defaults entirely with DefaultValuesStrategy::None.

@veewee veewee force-pushed the consistent-default-values-code-generator branch 2 times, most recently from 0e30e80 to d39f2a5 Compare February 27, 2026 12:04
@veewee veewee changed the title Introduce constructor & property default values with ScalarDefaultProvider Introduce DefaultValuesStrategy for properties and constructors Feb 27, 2026
…vider

  - Add ScalarDefaultProvider that determines type-appropriate defaults
    for properties (string='', int=0, bool=false, float=0.0, array=[],
    nullable=null)
  - Add withDefaultValues() option to PropertyAssembler (enabled by default),
    replacing the separate PropertyDefaultsAssembler
  - Add withDefaultValues() option to ConstructorAssembler (enabled by default),
    with automatic reordering of parameters so those with defaults come last
  - Add withOptionalValue() option to ConstructorAssembler, forcing all
    parameters to ?Type = null (matching PropertyAssembler behavior)
  - Remove PropertyDefaultsAssembler (functionality folded into PropertyAssembler)
@veewee veewee force-pushed the consistent-default-values-code-generator branch from d39f2a5 to 0a635f9 Compare February 27, 2026 12:06
@veewee veewee changed the title Introduce DefaultValuesStrategy for properties and constructors Introduce DefaultValuesStrategy for constructor & property defaults Feb 27, 2026
@veewee veewee merged commit 0c424f6 into phpro:v5.x Feb 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant