You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(transform): skip null by default with configurable parameter
BREAKING CHANGE: transform() now skips null values by default (was executing on null)
- Add $skipNull parameter (default: true) to transform() method
- Most type conversions don't need null handling, making this safer and more efficient
- Use transform($fn, skipNull: false) when null processing is needed
- Update tests to reflect new default behavior and add explicit null handling test
- Update documentation (llms.txt, guides) with examples and migration notes
- Update CHANGELOG.md with breaking change details
Refs: Real-world feedback on null handling efficiency
Copy file name to clipboardExpand all lines: CHANGELOG.md
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,16 +4,25 @@ All notable changes to this project will be documented in this file.
4
4
5
5
## [Unreleased]
6
6
7
+
### Changed
8
+
-**BREAKING**: `transform()` now skips `null` values by default (was executing on null)
9
+
-**Rationale**: Most type conversions don't need null handling, making this safer and more efficient by default
10
+
-**Migration**: Use `transform($fn, skipNull: false)` if you need to process null values (e.g., `transform(fn($v) => $v ?? 'fallback', skipNull: false)`)
11
+
-**Impact**: Existing code that relied on `transform()` executing on null will need to explicitly set `skipNull: false`
12
+
-**Real-World Benefit**: Prevents errors when null values reach type conversions like `DateTime::createFromFormat()`, `explode()`, `strlen()`, etc.
13
+
7
14
### Added
8
15
-`notEmpty()` convenience method for `StringValidator` and `ArrayValidator` to reject empty strings/arrays
9
16
-`between()` shorthand for string length and numeric range constraints with unified error messages
10
17
-`in()` alias for `oneOf()` on primitive validators for clearer allowed-value validation
18
+
-`transform()` method now accepts optional `$skipNull` parameter (default: `true`) to configure null handling
11
19
12
20
### Deprecated
13
21
-`oneOf()` in favor of `in()` (alias retained for backward compatibility)
14
22
15
23
### Documentation
16
24
- Clarified fail-fast behavior per field and schema-level error aggregation in guides and examples
25
+
- Updated transformation documentation to reflect new null handling behavior
-**Use `transform()`** for type changes (string → array, array → int)
308
-
-**Null handling** - `pipe()` skips null values to avoid type errors, `transform()`runs on null so you can map it to a new value
308
+
-**Null handling** - `pipe()` skips null values to avoid type errors, `transform()`skips null by default. Use `transform($fn, skipNull: false)`to process null values.
-**Changes type context** - Updates internal type tracking
142
142
-**No type coercion** - Returns exactly what the transformer produces
143
143
-**Enables type switching** - Subsequent `pipe()` operations work with the new type
144
-
-**Null handling** - `transform()` runs even when the current value is null so you can map null to a new value or type
144
+
-**Null handling** - `transform()` skips null by default (most type conversions don't need null). Use `transform($fn, skipNull: false)` to process null values.
145
+
146
+
**Null Handling Examples:**
147
+
148
+
```php
149
+
// Default behavior: skips null (most common case)
- `pipe(callable)`: Skips `null` values (type-preserving, expects specific type).
11
-
- `transform(callable)`: Executes on `null` (can handle null and change types).
11
+
- `transform(callable, bool $skipNull = true)`: Skips `null` by default (most type conversions don't need null). Set `$skipNull = false` to process null values.
12
12
- **Pipeline Order:** Pipeline steps execute in the exact order defined; `required()` is a flag enforced after the pipeline regardless of position.
13
13
- **Transformation Types:**
14
14
- `pipe(callable)`: Intended for sanitization. Preserves type context and applies type-coercion to result.
0 commit comments