Repository navigation
Constructor Optional Parameters and Indexed Adder Support
Pre-releaseSummary: Constructor Optional Parameters and Indexed Adder Support
Date: January 13, 2026
Branch: improv_break/code/DataObjectConstructArgs_Adder
Base: 2.0
Overview
This work session implemented two major features:
- Relaxed constraints on constructor parameters (optional parameters now allowed without
#[Param]) - Added
TYPE_INDEXED_ADDERsetter type for associative array handling with#[Param]support
Features Implemented
1. Optional Constructor Parameters
Modified Loader::instantiateWithParams() to allow optional constructor parameters without #[Param] attribute. These parameters use their default values.
Rule: Constructor parameters must either be optional OR have a #[Param] attribute.
2. Indexed Adder (TYPE_INDEXED_ADDER)
Added new setter type constant Setter::TYPE_INDEXED_ADDER that:
- Iterates over array items
- Passes both the key and value to the adder method
- Supports both associative and list arrays
3. Param Support in Adders
Extended #[Param] support to adder and indexed adder methods:
- For
TYPE_ADDER: First parameter (value) must NOT have#[Param], additional can - For
TYPE_INDEXED_ADDER: First two parameters (index, value) must NOT have#[Param], additional can
Code Changes
Source Files Modified
| File | Changes |
|---|---|
src/Attribute/Setter.php |
Added TYPE_INDEXED_ADDER = 'indexed_adder' constant |
src/Loader/Loader.php |
Modified instantiateWithParams(), setPropertyValue(), added callMethodWithParams() |
Test Files Created/Modified
| File | Description |
|---|---|
tests/Integration/AttributeSets/SetterAndGetter/SetterGetterIntegrationTest.php |
Added 3 tests for indexed adder |
tests/Integration/Attributes/Param/Fixtures/*.php |
Created 11 fixture files |
tests/Integration/Attributes/Param/ParamIntegrationTest.php |
Refactored, added 2 new tests |
tests/Integration/Rules/DataObjectInstantiation/*.php |
Created new test directory with 4 fixtures and 1 test class |
Documentation Updated
| File | Changes |
|---|---|
docs/attributes/Setter.md |
Complete rewrite: all setter types, adder, indexed adder with Param |
docs/attributes/Getter.md |
Complete rewrite: getter types, isser, haser |
docs/attributes/Param.md |
Updated rules for constructor (optional) and indexed adder |
README.md |
Updated Getter & Setter section with all types |
EXAMPLE.md |
Updated constructor example, added indexed adder example |
Test Results
Tests: 397, Assertions: 986, Skipped: 4
OK (with deprecation warnings)
Key Design Decisions
-
Optional parameters use default values: When a constructor parameter is optional and has no
#[Param], its default value is used directly. -
Indexed adder preserves keys: Unlike regular adder which only passes values, indexed adder passes both keys and values, enabling associative array support.
-
Param position rules by setter type:
TYPE_SETTER: 1st param = value (no Param), rest = Param optionalTYPE_ADDER: 1st param = item value (no Param), rest = Param optionalTYPE_INDEXED_ADDER: 1st = key (no Param), 2nd = value (no Param), rest = Param optional
Files Summary
Created (18 files)
- 11 fixture files in
tests/Integration/Attributes/Param/Fixtures/ - 5 files in
tests/Integration/Rules/DataObjectInstantiation/ - 2 documentation files in
docs/history/
Modified (8 files)
- 2 source files
- 1 test file
- 5 documentation files